Monday, March 5, 2018

System File 2:PHP script to write CSV header

File to write the CSV file header once each day or turn on cycle:

CODE
<?php
/*   epoutX-write-header.php   */

error_reporting(0);

exec ('sudo hwclock > /var/www/html/_hwc_out.txt');
exec ('date > /var/www/html/_date_out.txt');
exec ('sudo hwclock -w');

#$file= 'data_'.date('m-d-Y').'.txt'
$myfile = fopen('/var/www/html/data_'.date('m-d-Y').'.txt', "a") or die("Unable to open file!");
#shell_exec ( string 'sudo chown pi  $file'  )
fwrite($myfile,"time,time12,date,PV array voltage(V),PV array current(A),PVpower,Battery voltage(V),Battery charging current(A),Battery charging power(W),BattSOC,elevcalc,azicalc,Si,Sm\n");
fclose($myfile);

exec ('/bin/bash /var/www/html/epoutX-unlock_files.sh');



#$myfile = fopen('/var/www/html/data_XXX'.date('m-d-Y').'.txt', "a") or die("Unable to open file!");
#fwrite($myfile,"time,time12,date,PV array voltage(V),PV array current(A),PVpower,Battery voltage(V),Battery charging current(A),Battery charging power(W),BattSOC,azimuth,elevation\n");
#fclose($myfile);


?>
END CODE

System File 1:Data saver PHP script

 
   I'm publishing the files I've created to run and monitor, my system. There will be no explanations. I

The file to load and save data from the MPPT controller:

CODE
<?php
/*   epoutX-2.php   */
#date_default_timezone_set('EST');
#exec ('/bin/bash /var/www/html/epoutX-unlock_files.sh');

#$x=0;
require_once 'PhpEpsolarTracer.php';
$tracer = new PhpEpsolarTracer('/dev/ttyXRUSB0');
error_reporting(0);


$y = 1;
$x = 3;
#######################################
# exec ('/bin/bash /var/www/html/chd.sh');
#######################################

while($x = 3):
#######################################
exec ('/bin/bash /var/www/html/example_web.sh');
#######################################








#while($x=3):
$myfile = fopen('/var/www/html/data_'.date('m-d-Y').'.txt', "a") or die("Unable to open file!");
#If  ($y = 1){
# fwrite($myfile,"time,time12,date,PV array voltage(V),PV array current(A),PVpower,Battery voltage(V),Battery charging current(A),Battery charging power(W),BattSOC,azimuth,elevation,Si,Sm\n");
# $y = 0;
#  }


$nano = time_nanosleep(30, 0);
  if ($tracer->getRealtimeData()) {
    $i=0;
#--------------------------------------->
    $pythonnoaaephem = `/usr/bin/env python3.6 /var/www/html/resources/NOAA.py`;

#____________________________________


    $date=date("Y-m-d H:i:s");
    $seconds = strtotime($date);
    $seconds /= 30;
    $seconds = round($seconds);
    $seconds *= 30;
    $date2 = date("h:i:s", $seconds);
    $date = date("h:i:s A", $seconds);
    $today = date("Y-m-d"); # Y-m-d
    $now = $date;
#______________________________________
    fwrite($myfile, $date2);
    fwrite($myfile, ",");
    fwrite($myfile, $now);
    fwrite($myfile, ",");
    fwrite($myfile, $today.",");
#---------------------------------------->
    while ($i<=5):
      $dat[$i] = $tracer->realtimeData[$i].",";
       fwrite($myfile, $dat[$i]);
       $i++;
    endwhile;
  $i=12;
$dat[$i] = $tracer->realtimeData[$i].",";
    fwrite($myfile, $dat[$i]);

    }
#--------------------------------------------------------->
    fwrite($myfile,$pythonnoaaephem);
#--------------------------------------------------------->





endwhile;
    fclose($myfile);
?>
END CODE

Update and plans for CGI model of shadows



This post, I'm laying out plans to construct an animation of my property and the shadows cast throughout the year. I also recap progress on the installation.
   This will allow me to determine the best location for my array, or whether I will need to move the array, at least once per  year.

   The software I'll be using is Pov-Ray (Point of View Raytracer). If possible and necesasary, I'll use the architectural raytracer, Radiance.

   I have the formulae I need to do the calculations for solar positioning throughout the year. I'll get terrain data from D.E.M. data provided by the government for free. I also have twenty years of CDs containing GIS data and software to fall back on.
  The D.E.M. (Digital Elevation Map) is a file containing elevation data for points on an area of terrain. Generally, a seven degree quadrangle is the unit of measure. One 'quad' will contain data points similar to the pixels in an image file. The difference is the image data represents color or grayscale values. In fact, I have converted DEM files into grayscale high dynamic range images for use in rendering engines (raytracers). I constructed an animated gif of a local quad from topographic map graphic layers and a DEM layer. The gif shows the flat topo map flat, then the DEM data 'pushing' through from under to create a 3D map with a topo map overlay.

   I may use the Moray 3D object editing software to construct geometric tree and house objects to cast shadows. Some have created tree files for use in populating a landscape in Pov-Ray. I may use one of those.

   I've determined I need to double the number of watts for a comfortable minimum power for the system. A factor of two compensates for days that are overcast. There have to be more watts (panels) or more batteries. The panels last longer than batteries and are less expensive in terms of usage. Batteries last about five years. Panels have an industry wide warranty of twenty years for 80% rating.
   There is a balance between the number of batteries and panels.  Extra batteries are needed to draw only 50% of available power. The general rule for lead acid deep cycle batteries is: use no more than 50% to preserve longevity.

   There is one alternative to moving the array around. Find a way to get the owner of the adjoining property to remove or lower the top level of the evergreen trees blocking the sunlight from my array in the winter months.

   I may take that option. Roof mount would be an option if the roof were slanted more South. The roof points 20 degrees East of South. I would need to build a stage to position the aray pointing South. That is too difficult and costly. I don't like the idea of modifying my roof, either.

   That is the end of this post.

Tuesday, December 19, 2017

Python version problems.



Python version problems

Different versions of Python have enough differences to be troublesome.

Version 2.7.4 calculations use implicit integer types where version 3.6.0 uses implicit float types.
The following examples illustrate the problem:
V2: 7/5=1; -7/5= -2
V3: 7/5=1.4;-7/5= -1.4
Adding a decimal to numbers in V2 converts them to floats:
V2: 7.0/5=1.4
A manual conversion also works:
V2 float(7)/5=1.4

The problem, for me, is version 2.7.4 has the ephemeris module installed. In the computer’s Raspbian operating system, version 2.4 is installed and installing version 3.6 has to be without modules. Hence, the ephemeris module will be absent with 3.6.0. Again, the problem? Different scripts are written with different versions of Python. One or two large sophisticated programs require simultaneous versions of Python.
I decided to use my translation of an Excel spreadsheet instead of the ephemeris. Only version 3.6.0 is required and is summoned with:
“python3.6 NOAA.py”
My calculations of solar incident and solar module irradiation are compatible with version 3.6.0.



Wednesday, December 13, 2017

An instance of translation from Excel to Python.

This is an instance of the translation of an Excel spreadsheet formula into the Python equivalent.


EXCEL:
#AH2=Sun Azimuth degrees clockwise from North
=IF(AC2>0,MOD(DEGREES(ACOS(((SIN(RADIANS(Lat))*COS(RADIANS(AD2)))-SIN(RADIANS(T2)))/(COS(RADIANS(Lat))*SIN(RADIANS(AD2)))))+180,360),MOD(540-DEGREES(ACOS(((SIN(RADIANS(Lat))*COS(RADIANS(AD2)))-SIN(RADIANS(T2)))/(COS(RADIANS(Lat))*SIN(RADIANS(AD2))))),360))



PYTHON:
#AH2=Sun Azimuth degrees clockwise from North
AH2a1=math.acos(((math.sin((B3/r)) * math.cos((AD2/r))) - math.sin((T2/r))) / ((math.cos((B3/r)) * math.sin(AD2/r))))*r + 180
AH2b1=360
AH2a2=540-math.acos(((math.sin(B3/r)*math.cos(AD2/r))-math.sin(T2/r))/((math.cos(B3/r)*math.sin(AD2/r))))*r
AH2b2=AH2b1
if AC2 > 0 : AH2=AH2a1-int(AH2a1/AH2b1)*AH2b1
else : AH2=AH2a2-int(AH2a2/AH2b2)*AH2b2

Tuesday, December 12, 2017

NOAA equations for solar data (sunrise, sunset, elevation, azimuth, Julian Day, Equation of Time, etc..



   In a recent post I presented the equation for energy incident on a solar panel (Sm).
Here I present the set of equations used to calculate sunrise, sunset, and solar elevation and azimuth.

=============================================================

#This particular set was extracted from an Excel spreadsheet made available by NOAA.

#360 deg/2*pi=57.29578
#if in radians, do sin(x/r) to get degrees
#sin(45d)=.7071
#sin(45r)=0.8509

LT: Local Tiime
UT:Universal Time
TZ:Time Zone
LT=UT+TZ

JDg1=367*Y-int(7*(Y+int((M+9)/12))/4)-int(3*(int((Y+(M-9)/7)/100)+1)/4)+int(275*M/9)+D+1721028.5+UT/24
JDg2=367*Y-int(7*(Y+int((M+9)/12))/4)+int(275*M/9)+D+1721013.5+UT/24

#For the Day:
#B3=Latitude, + to N
#B4=Longitude + to E
#B5=Time Zone + to E    ( calculations use TZ)
#B7=Date
#H=Blank
#--------------------------

#D2=date
=date, mm/dd/yyyy , Calculations use JD

#E2=T past local midnight (used in TST and Elev refraction calc)
#sum of 0.1/24 from midnight to current with .1/24 increments (fraction of the day in tenths of an hour ; 6 min = 0.0041666 day)
=LT/24
# In the JD, the previous day +.5 is midnight since the calendar sarts at noon.
#F2=Julian Day
=D2+2415018.5+E2-TimeZone(TZ)/24
JDg2=D2+2415018.5+E2-TimeZone(TZ)/24


#G=Julian , used in other functions, translated into radians. Functions that make up S and T use G (P,R,Q).
=(F2-2451545)/36525

#H=Blank

#I=Geom Mean Long Sun
=MOD(280.46646+G2*(36000.76983+G2*0.0003032),360)
#mod()=a-int(a/b)*b

#J=Geometric Mean Anomaly of the Sun
=357.52911+G2*(35999.05029-0.0001537*G2)

#K=Eccentricity of Earth orbit
=0.016708634-G2*(0.000042037+0.0000001267*G2)

#L=Sun Eq of Ctr
=SIN(RADIANS(J2))*(1.914602-G2*(0.004817+0.000014*G2))+SIN(RADIANS(2*J2))*(0.019993-0.000101*G2)+SIN(RADIANS(3*J2))*0.000289

#M=Sun True Long degrees
=I2+L2

#N=Sun True Anomaly degrees
=J2+L2

#O=Sun Radius Vector, A.U.
=(1.000001018*(1-K2*K2))/(1+K2*COS(RADIANS(N2)))

#P=Sun Apparent Long
=M2-0.00569-0.00478*SIN(RADIANS(125.04-1934.136*G2))

#Q=Mean Oblique Ecliptic degrees
=23+(26+((21.448-G2*(46.815+G2*(0.00059-G2*0.001813))))/60)/60

#R=Oblique Correction factor
=Q2+0.00256*COS(RADIANS(125.04-1934.136*G2))

#S=Right Ascension degrees
=DEGREES(ATAN2(COS(RADIANS(P2)),COS(RADIANS(R2))*SIN(RADIANS(P2))))

#T=Declination in degrees
=DEGREES(ASIN(SIN(RADIANS(R2))*SIN(RADIANS(P2))))

#U=var y
=TAN(RADIANS(R2/2))*TAN(RADIANS(R2/2))

#V=EoT minutes
=4*DEGREES(U2*SIN(2*RADIANS(I2))-2*K2*SIN(RADIANS(J2))+4*K2*U2*SIN(RADIANS(J2))*COS(2*RADIANS(I2))-0.5*U2*U2*SIN(4*RADIANS(I2))-1.25*K2*K2*SIN(2*RADIANS(J2)))

#W=HA Sunrise degrees
=DEGREES(ACOS(COS(RADIANS(90.833))/(COS(RADIANS(Lat))*COS(RADIANS(T2)))-TAN(RADIANS(Lat))*TAN(RADIANS(T2))))

#X=Sun noon LST
=(720-4*Lon-V2+TZ*60)/1440

#Y=Sunrise time
#Y=Sunrise time
Y2=X-W*4/1440
#Z=Sunset time
Z2=X+W*4/1440

#AA2=Sunlight duration
=8*W2

#AB2=TST
=MOD(E2*1440+V2+4*Lon-60*TZ,1440)

#AC2=Hour Angle
=IF(AB2/4<0,AB2/4+180,AB2/4-180)

#AD2=Zenith
=DEGREES(ACOS(SIN(RADIANS(Lat))*SIN(RADIANS(T2))+COS(RADIANS(Lat))*COS(RADIANS(T2))*COS(RADIANS(AC2))))

#AE2= Sun elevation in degrees
90-AD2

#AF2=Atmospheric refraction un degrees
=IF(AE2>85,0,IF(AE2>5,58.1/TAN(RADIANS(AE2))-0.07/POWER(TAN(RADIANS(AE2)),3)+0.000086/POWER(TAN(RADIANS(AE2)),5),IF(AE2>-0.575,1735+AE2*(-518.2+AE2*(103.4+AE2*(-12.79+AE2*0.711))),-20.772/TAN(RADIANS(AE2)))))/3600

#AG2=Sun Elevation corrected for refraction
=AE2+AF2

#AH2=Sun Azimuth degrees clockwise from North
=IF(AC2>0,MOD(DEGREES(ACOS(((SIN(RADIANS(Lat))*COS(RADIANS(AD2)))-SIN(RADIANS(T2)))/(COS(RADIANS(Lat))*SIN(RADIANS(AD2)))))+180,360),MOD(540-DEGREES(ACOS(((SIN(RADIANS(Lat))*COS(RADIANS(AD2)))-SIN(RADIANS(T2)))/(COS(RADIANS(Lat))*SIN(RADIANS(AD2))))),360))









=====================================================================





Friday, December 1, 2017

Linear actuator installed. Possible changes.



   I've been building my power station with n eye to minimizing the cost without sacrificing quality.
I've mounted the array on a one inch steel pipe leaning against an  aluminum ladder. The ladder was damaged beyond intended use, so I've re-purposed the ladder, for the time being, as a support frame for the array. I drilled holes to mount a piece of wood to strengthen the weak area. I also drilled holes to attach the linear actuator. I've mounted the linear actuator in the first trial position. The actuator is a heavy duty, hazardous environment, model suitable for outdoors, all season use. The unit can push or pull 10 kN, or 10000 N. That is equivalent to 2,200 pounds, or, a little over one ton (2000 lbs). The unit is working with a small load which will drain little power from the battery bank, even on a cloudy day.
   I will be able to program the tracking to follow the sun using calculations, mm/rpm specs from the manufacturer, and a solar detector composed of four small solar cells attached to the array. If the day is cloudy, the sensor will respond with characteristic data that can be responded to in program.
   The motor power wiring has to be run from the indoor station to the unit unless the control computer is mounted near the array in a weather proof box.
   The idea of moving the entire station out to the array is appealing. The problem I have is the battery bank. What is the effect of low temperatures on flooded lead-acid batteries? My first thought is to build an enclosure big enough to insulate. The minicomputer I'm using was not necessarily designed for harsh environments, though electronic circuitry tends to be very hardy. There is a more utilitarian version of the computer that may be a better choice. I may place the mini computer and charge controller at the array and keep the battery bank and inverter indoors. That makes powering the mini computer an issue. The unit is currently powered by the battery bank. Running DC power lines to the array for the unit seems impractical. A smaller battery dedicated to the mini computer would be a better choice. In fact, I have a left over charge controller and inverter that could supply the unit. A small solar panel could be added to the array specifically for the computer. The mini computer, RPi, typically uses onlly 5 watts of power and that makes powering the unit inexpensive and simple.
   The charge controller is a Zantrex 60A PWM model. The inverter is a 300 watt pure sine wave type. Add a small battery and a solar panel and the parts list is complete.
   The second power supply will, like the RPi, need to be enclosed in a weatherproof container.
   The mini computer is a Raspberry Pi 3B with USB ports, WiFi, and GPIO ports. Software installed includes the Apache web server, PHP, Python, an RTL hardware clock driver, a USB driver for the charge controller, WiFi access point software, and a small 16Gb SD card and reader.



Battery bank wiring modification

  The battery bank has been wired in parallel with system connections at the closest battery. This creates an unbalanced load on the bank.  ...