From eefb9fe3f66a6c4fe6d33092b29ecbb406389e14 Mon Sep 17 00:00:00 2001 From: Dan-in-CA Date: Mon, 14 Oct 2013 09:27:50 -0700 Subject: [PATCH 01/13] Renamed Main Loop > Timing loop --- ospi.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ospi.py b/ospi.py index f2bdd32..aa6ccfe 100644 --- a/ospi.py +++ b/ospi.py @@ -14,7 +14,7 @@ gv.ver = 183 gv.rev = 138 gv.rev_date = '11/October/2013' - #### urls is a feature of web.py. When a GET request is recieved , the corrisponding class is executed. + #### urls is a feature of web.py. When a GET request is received , the corresponding class is executed. urls = [ '/', 'home', '/cv', 'change_values', @@ -193,8 +193,8 @@ def stop_stations(): return def main_loop(): # Runs in a separate thread - """ ***** Main algorithm.***** """ - print 'Starting main loop \n' + """ ***** Main timing algorithm.***** """ + print 'Starting timing loop \n' last_min = 0 while True: # infinite loop gv.now = time.time()+((gv.sd['tz']/4)-12)*3600 # Current time based on UTC time from the Pi adjusted by the Time Zone setting from options. updated once per second. @@ -309,7 +309,7 @@ def main_loop(): # Runs in a separate thread gv.sd['rdst'] = 0 # Rain delay stop time jsave(gv.sd, 'sd') time.sleep(1) - #### End of main loop #### + #### End of timing loop #### def data(dataf): """Return contents of requested text file as string or create file if a missing config file.""" From 7311632ca8dba94e5270df3d50f112deb5ae988e Mon Sep 17 00:00:00 2001 From: Dan-in-CA Date: Fri, 11 Oct 2013 13:10:32 -0700 Subject: [PATCH 02/13] Minor bug fix, code cleanup --- .gitignore | 3 - README.md | 312 +++++++++++++++++++++++++++-------------------------- ospi.py | 3 +- 3 files changed, 161 insertions(+), 157 deletions(-) diff --git a/.gitignore b/.gitignore index b77f87e..b90266c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ web/ /data -/.settings *.pyc -.project -.pydevproject diff --git a/README.md b/README.md index cb331d4..bf2866f 100644 --- a/README.md +++ b/README.md @@ -1,152 +1,160 @@ -OSPi -==== - -A Python port of the Arduino based OpenSprinkler firmware V 1.8.3 ------------------------------------------------------------------ -OpenSprinkler Pi (OSPi) Interval Program Demo
-Creative Commons Attribution-ShareAlike 3.0 license
-June 2013, http://rayshobby.net - -*********** -UPDATES -=========== -*********** - -October 4 2013 --------------- -(jonathanmarsh)
-Additions, bug fixes:
-1. Improved options handling and passing logic
-2. Added a "System Name" option to help users distinguish between multiple systems
-3. Configurable station name length (increased default to 32)
-4. Added logging options to options page
- -(Dan)
-Additions, bug fixes:
-1. Moved RasPi specific code into try-except blocks allowing program to run on multiple platforms
-2. Added "write_options" function to create/update new style options.txt file in data directory.
-3. Fixed a bug in new options code that prevented master station from being selected.
-4. Fixed a bug that caused an exception when the number of expansion boards was reduced.
- -October 1 2013 --------------- -Changes:
-1. Changed the pin numbering option in the RPi.GPIO module from BCM to BOARD.
- -September 23 2013 --------------- -Additions, bug fixes:
-1. Added a new revisions page to the native web interface.
-2. Modified the home.js file to show time zone info in the last run log near the bottom of the page.
-3. Fixed a bug in concurrent mode that kept a station running after it's duration had expired.
-4. Fixed a bug that would cause an exception (freeze the program) after the number of expansion boards was changed in Options.
-5. Fixed a bug that would stop a running station and clear scheduled stations when the number of expansion boards was changed in Options.
- -September 10 2013 --------------- -Additions, bug fixes:
-1. Added a per-station "Ignore rain" option that allows a station to operate during rain delay or if a rain sensor detects rain.
-2. Modified the program to use the HTTP port setting from the Options page.
-3. Improved the way the program tracks current time. This simplified the code and should eliminate some timing bugs.
-4. Edited Denny's init.d startup script to remove IP address and port settings no longer needed.
- -August 30 2013 --------------- -Additions, bug fixes:
-1. Modified the program to use only the time zone setting from the Options page and not the tz setting from the py.
-2. Made the CPU temperature readout on the home page clickable to toggle between C and F.
-3. Added a copy of Denny Fox's init.d auto startup script
- -August 25 2013 --------------- -Additions, bug fixes:
-1. Implemented improved installation and update methods using GitHub.
-2. Modified the program to automatically create default config files on new installations. This also prevents existing settings from being overwritten.
-3. Added a "Run now" button to the programs page. Allows a schedule program to be started at any time. This overrides (stops) any running program.
-4. Added a readout of the Raspberry Pi's CPU temperature to the home page.
-5. Fixed a bug that would allow a station to be stopped / started without a password ueing the HTML API.
-6. Fixed a bug that would display an incorrect start day for a schedule program.
- -August 1 2013 Reved to firmware V 1.8.3 ---------------------------------------- -Now supports concurrent operation.
-Additions, bug fixes:
-1. Added Sequential/Concurrent option.
-2. Added a function to detect Pi board rev and auto-configure GPIO pins for rev 1 boards.
-3. Fixed a bug in manual mode that would cause any zone with a master association to stop the master when turned off, even if another station with a master association was still running.
-4. Changed how ospi.py handles master zone associations. The program should now work with more than 3 expansion boards (untested in hardware but at least 5 expansion boards, 64 stations work in software).
- -July 21 2013 ------------- -Bug fixes:
-1. Fixed a bug that kept an in progress program running after it was disabled.
-2. Added error checking to prevent an 'lg' KeyError
-3. When a new program was added, it became program 1 instead of being added at the end of the list. - fixed.
-4. When Rain Delay was set, running stations did not stop. - Fixed.
-5. Added a 1.5s delay in the screen refresh of manual Mode to allow active stations and last run log time to update.
- -July 19 2013 ------------- -Code re-factored:
-1. Eliminated over 100 lines of redundant code. The code is now much closer to the micro-controller version. Manual Mode and Run-once now rely on the main loop algorithm. This eliminates potential conflicts and makes the code easier to maintain. The program should now be more stable and have fewer bugs although the UI is a little slower.
-2. Changed bit-wise operations to make them more reliable.
-3. Station names now accept Unicode characters allowing names to be entered in any language.
-4. Faveicon now appears on all pages.
-5. A small bug in the display of Master valve off time in the program preview has been fixed. The off time was 1 minute short.
-6. A file named 'sd_reference.txt' has been added to the OSPi directory. It contains a list with descriptions of the values contained in the global settings dictionary variable (gv.sd) which holds most settings for the program. These values are kept in memory and also stored in the file OSPi/data/sd.json to persist across system restarts. This is for the benefit of anyone who wishes to tinker with the code.
- -It is recommended to re-install the entire OSPi directory from GitHub. You can keep your current settings by saving the contents of the OSPi/data directory to another location before installation, then replace the contents of the newly installed directory with your saved files. - -july 10 2013 ------------- -Bug fixes and additions:
-1. Fixed a bug that prevented zones 9+ from running.
-2. The Run once program was not observing the station delay setting - Fixed
-3. Made the sd variable an attribute of the gv module. All references to sd... are now gv.sd... This should potentially fix several bugs, Specifically the Rain delay seems to be working properly now.
-4. The Graph Programs time marker was not recognizing the time zone setting from the Options page - fixed.
-5. Time displayed on the last run line of the main page was not correct - fixed.
-6. Added a faveicon which will help distinguish the OpenSprinkler tabs on the browser.
-7. Added an import statement and file which provide a stub for adding user written custom functions to the interval program without modifying the program itself.
- -Jun 26 2013 ------------ -1. Last run logging is now working for manual mode when an optional time value is selected, even if more that one station is started.
-2. Fixed a bug that prevented the home page display from updating when running irrigation programs.
-3. Includes a fix from Samer that allows the program preview time marker to update properly.
- -Jun 20, 2013 ------------- -This update includes:
-1. Changed the way ospi.py handles time. It now uses the time zone setting from the OS options page. It also eliminates the auto daylight savings time adjustment that was causing problems for some users.
-2. Fixes a bug mentioned on the forum that caused Samer's app to not update in program mode.
-3. Fixes a bug that caused a program to re-start after the "Stop all stations" button was clicked.
-4. A partial fix for the "last run" problems. Still need to get manual mode with an optional time setting working.
-5. Added a docstring at the top of the ospi.py file with the date for version tracking. - -Jun 19, 2013 ------------- - Applied Samer Albahra's patch so that the program will work with Samer's mobile web app. - Per forum discussion: http://rayshobby.net/phpBB3/viewtopic.php?f=2&t=154&start=40#p781
- - -NOTE -==== -This folder contains the interval program demo for OpenSprinkler Pi written by Dan Kimberling. It is compatible with the microcontroller-based OpenSprinkler firmware 1.8, the instructions of which can be found at: - - http://rayshobby.net/?page_id=730 - -The program makes use of web.py (http://webpy.org/) for the web interface. - -****************************************************** -Full credit goes to Dan for his generous contributions -in porting the microcontroller firmware to Python. -****************************************************** - -================================================================ - -*********************** -Installation and set up -*********************** - -For complete and up-to-date installation and set up instructions, see the Rays Hobby wiki page at: -http://rayshobby.net/mediawiki/index.php?title=Python_Interval_Program_for_OSPi +OSPi +==== + +A Python port of the Arduino based OpenSprinkler firmware V 1.8.3 +----------------------------------------------------------------- +OpenSprinkler Pi (OSPi) Interval Program Demo
+Creative Commons Attribution-ShareAlike 3.0 license
+June 2013, http://rayshobby.net + +*********** +UPDATES +=========== +*********** + +October 11 2013 +-------------- +(Dan)
+Additions, bug fixes:
+1. Fixed a bug that would cause an error when a master was enabled and making changes to station settings.
+2. added approve_pwd function and removed redundant code.
+3. removed write_options function and added options.txt file to distribution.
+ +October 4 2013 +-------------- +(jonathanmarsh)
+Additions, bug fixes:
+1. Improved options handling and passing logic
+2. Added a "System Name" option to help users distinguish between multiple systems
+3. Configurable station name length (increased default to 32)
+4. Added logging options to options page
+ +(Dan)
+Additions, bug fixes:
+1. Moved RasPi specific code into try-except blocks allowing program to run on multiple platforms
+2. Added "write_options" function to create/update new style options.txt file in data directory.
+3. Fixed a bug in new options code that prevented master station from being selected.
+4. Fixed a bug that caused an exception when the number of expansion boards was reduced.
+ +October 1 2013 +-------------- +Changes:
+1. Changed the pin numbering option in the RPi.GPIO module from BCM to BOARD.
+ +September 23 2013 +-------------- +Additions, bug fixes:
+1. Added a new revisions page to the native web interface.
+2. Modified the home.js file to show time zone info in the last run log near the bottom of the page.
+3. Fixed a bug in concurrent mode that kept a station running after it's duration had expired.
+4. Fixed a bug that would cause an exception (freeze the program) after the number of expansion boards was changed in Options.
+5. Fixed a bug that would stop a running station and clear scheduled stations when the number of expansion boards was changed in Options.
+ +September 10 2013 +-------------- +Additions, bug fixes:
+1. Added a per-station "Ignore rain" option that allows a station to operate during rain delay or if a rain sensor detects rain.
+2. Modified the program to use the HTTP port setting from the Options page.
+3. Improved the way the program tracks current time. This simplified the code and should eliminate some timing bugs.
+4. Edited Denny's init.d startup script to remove IP address and port settings no longer needed.
+ +August 30 2013 +-------------- +Additions, bug fixes:
+1. Modified the program to use only the time zone setting from the Options page and not the tz setting from the py.
+2. Made the CPU temperature readout on the home page clickable to toggle between C and F.
+3. Added a copy of Denny Fox's init.d auto startup script
+ +August 25 2013 +-------------- +Additions, bug fixes:
+1. Implemented improved installation and update methods using GitHub.
+2. Modified the program to automatically create default config files on new installations. This also prevents existing settings from being overwritten.
+3. Added a "Run now" button to the programs page. Allows a schedule program to be started at any time. This overrides (stops) any running program.
+4. Added a readout of the Raspberry Pi's CPU temperature to the home page.
+5. Fixed a bug that would allow a station to be stopped / started without a password ueing the HTML API.
+6. Fixed a bug that would display an incorrect start day for a schedule program.
+ +August 1 2013 Reved to firmware V 1.8.3 +--------------------------------------- +Now supports concurrent operation.
+Additions, bug fixes:
+1. Added Sequential/Concurrent option.
+2. Added a function to detect Pi board rev and auto-configure GPIO pins for rev 1 boards.
+3. Fixed a bug in manual mode that would cause any zone with a master association to stop the master when turned off, even if another station with a master association was still running.
+4. Changed how ospi.py handles master zone associations. The program should now work with more than 3 expansion boards (untested in hardware but at least 5 expansion boards, 64 stations work in software).
+ +July 21 2013 +------------ +Bug fixes:
+1. Fixed a bug that kept an in progress program running after it was disabled.
+2. Added error checking to prevent an 'lg' KeyError
+3. When a new program was added, it became program 1 instead of being added at the end of the list. - fixed.
+4. When Rain Delay was set, running stations did not stop. - Fixed.
+5. Added a 1.5s delay in the screen refresh of manual Mode to allow active stations and last run log time to update.
+ +July 19 2013 +------------ +Code re-factored:
+1. Eliminated over 100 lines of redundant code. The code is now much closer to the micro-controller version. Manual Mode and Run-once now rely on the main loop algorithm. This eliminates potential conflicts and makes the code easier to maintain. The program should now be more stable and have fewer bugs although the UI is a little slower.
+2. Changed bit-wise operations to make them more reliable.
+3. Station names now accept Unicode characters allowing names to be entered in any language.
+4. Faveicon now appears on all pages.
+5. A small bug in the display of Master valve off time in the program preview has been fixed. The off time was 1 minute short.
+6. A file named 'sd_reference.txt' has been added to the OSPi directory. It contains a list with descriptions of the values contained in the global settings dictionary variable (gv.sd) which holds most settings for the program. These values are kept in memory and also stored in the file OSPi/data/sd.json to persist across system restarts. This is for the benefit of anyone who wishes to tinker with the code.
+ +It is recommended to re-install the entire OSPi directory from GitHub. You can keep your current settings by saving the contents of the OSPi/data directory to another location before installation, then replace the contents of the newly installed directory with your saved files. + +july 10 2013 +------------ +Bug fixes and additions:
+1. Fixed a bug that prevented zones 9+ from running.
+2. The Run once program was not observing the station delay setting - Fixed
+3. Made the sd variable an attribute of the gv module. All references to sd... are now gv.sd... This should potentially fix several bugs, Specifically the Rain delay seems to be working properly now.
+4. The Graph Programs time marker was not recognizing the time zone setting from the Options page - fixed.
+5. Time displayed on the last run line of the main page was not correct - fixed.
+6. Added a faveicon which will help distinguish the OpenSprinkler tabs on the browser.
+7. Added an import statement and file which provide a stub for adding user written custom functions to the interval program without modifying the program itself.
+ +Jun 26 2013 +----------- +1. Last run logging is now working for manual mode when an optional time value is selected, even if more that one station is started.
+2. Fixed a bug that prevented the home page display from updating when running irrigation programs.
+3. Includes a fix from Samer that allows the program preview time marker to update properly.
+ +Jun 20, 2013 +------------ +This update includes:
+1. Changed the way ospi.py handles time. It now uses the time zone setting from the OS options page. It also eliminates the auto daylight savings time adjustment that was causing problems for some users.
+2. Fixes a bug mentioned on the forum that caused Samer's app to not update in program mode.
+3. Fixes a bug that caused a program to re-start after the "Stop all stations" button was clicked.
+4. A partial fix for the "last run" problems. Still need to get manual mode with an optional time setting working.
+5. Added a docstring at the top of the ospi.py file with the date for version tracking. + +Jun 19, 2013 +------------ + Applied Samer Albahra's patch so that the program will work with Samer's mobile web app. + Per forum discussion: http://rayshobby.net/phpBB3/viewtopic.php?f=2&t=154&start=40#p781
+ + +NOTE +==== +This folder contains the interval program demo for OpenSprinkler Pi written by Dan Kimberling. It is compatible with the microcontroller-based OpenSprinkler firmware 1.8, the instructions of which can be found at: + + http://rayshobby.net/?page_id=730 + +The program makes use of web.py (http://webpy.org/) for the web interface. + +****************************************************** +Full credit goes to Dan for his generous contributions +in porting the microcontroller firmware to Python. +****************************************************** + +================================================================ + +*********************** +Installation and set up +*********************** + +For complete and up-to-date installation and set up instructions, see the Rays Hobby wiki page at: +http://rayshobby.net/mediawiki/index.php?title=Python_Interval_Program_for_OSPi diff --git a/ospi.py b/ospi.py index f2bdd32..2b88482 100644 --- a/ospi.py +++ b/ospi.py @@ -555,7 +555,7 @@ class change_values: elif qdict.has_key('en') and qdict['en'] == '0': gv.srvals = [0]*(gv.sd['nst']) # turn off all stations set_output() - if qdict.has_key('mm') and qdict['mm'] == '0': clear_mm() #self.clear_mm() + if qdict.has_key('mm') and qdict['mm'] == '0': clear_mm() if qdict.has_key('rd') and qdict['rd'] != '0': gv.sd['rdst'] = (gv.now+(int(qdict['rd'])*3600)) stop_onrain() @@ -726,7 +726,6 @@ class change_stations: save('snames', names.encode('ascii', 'backslashreplace')) jsave(gv.sd, 'sd') raise web.seeother('/') -# return class get_station: """Return a page containing a number representing the state of a station or all stations if 0 is entered as statin number.""" From 6481ed42e5cb8f828b92a8c6af278f9edc691a13 Mon Sep 17 00:00:00 2001 From: Dan-in-CA Date: Tue, 15 Oct 2013 17:11:42 -0700 Subject: [PATCH 03/13] Restoring .project files --- .gitignore | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitignore b/.gitignore index b77f87e..b90266c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ web/ /data -/.settings *.pyc -.project -.pydevproject From 3a3e0f9697099365bd76ce5917a2e180824d68ff Mon Sep 17 00:00:00 2001 From: Dan-in-CA Date: Tue, 15 Oct 2013 19:11:58 -0700 Subject: [PATCH 04/13] Regenerating .project files --- .project | 17 +++++++++++++++++ .pydevproject | 10 ++++++++++ 2 files changed, 27 insertions(+) create mode 100644 .project create mode 100644 .pydevproject diff --git a/.project b/.project new file mode 100644 index 0000000..a77e25c --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + OSPi + + + + + + org.python.pydev.PyDevBuilder + + + + + + org.python.pydev.pythonNature + + diff --git a/.pydevproject b/.pydevproject new file mode 100644 index 0000000..2783106 --- /dev/null +++ b/.pydevproject @@ -0,0 +1,10 @@ + + + + + +/${PROJECT_DIR_NAME} + +python 2.7 +Default + From b62f67de6d05390048a165a440930fd0e4c473bb Mon Sep 17 00:00:00 2001 From: Dan-in-CA Date: Tue, 15 Oct 2013 19:29:23 -0700 Subject: [PATCH 05/13] edited .git.ignore --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b90266c..7a0271f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ web/ -/data +/data/programs.json +/data/sd.json +/data/snames.txt *.pyc From 1313e633ca67c244a8a2d6ab335e9a02517b4224 Mon Sep 17 00:00:00 2001 From: Dan-in-CA Date: Tue, 15 Oct 2013 19:31:53 -0700 Subject: [PATCH 06/13] edited .git.ignore --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b90266c..7a0271f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ web/ -/data +/data/programs.json +/data/sd.json +/data/snames.txt *.pyc From 4c9c444533a61b7a70ce4c2d6ec20ff792f6f0a9 Mon Sep 17 00:00:00 2001 From: Dan-in-CA Date: Tue, 15 Oct 2013 20:23:04 -0700 Subject: [PATCH 07/13] Switching manual mode on or off does not cancel rain delay. Changing rain delay does not cancel manual mode. --- ospi.py | 2 +- static/scripts/java/svc1.8.3/home.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ospi.py b/ospi.py index f6d68aa..1b1ff69 100644 --- a/ospi.py +++ b/ospi.py @@ -556,7 +556,7 @@ class change_values: gv.srvals = [0]*(gv.sd['nst']) # turn off all stations set_output() if qdict.has_key('mm') and qdict['mm'] == '0': clear_mm() - if qdict.has_key('rd') and qdict['rd'] != '0': + if qdict.has_key('rd') and qdict['rd'] != '0' and qdict['rd'] != '': gv.sd['rdst'] = (gv.now+(int(qdict['rd'])*3600)) stop_onrain() elif qdict.has_key('rd') and qdict['rd'] == '0': gv.sd['rdst'] = 0 diff --git a/static/scripts/java/svc1.8.3/home.js b/static/scripts/java/svc1.8.3/home.js index c51a415..02dcb9f 100644 --- a/static/scripts/java/svc1.8.3/home.js +++ b/static/scripts/java/svc1.8.3/home.js @@ -51,7 +51,7 @@ else w("
Log: n/a"); w("
"); // print html form w("

Password:

"); -w("
"); +w(""); w(""); w(""); w(""); From 9ecc28dc914217a6c0e492ba6f8f252b56303f5d Mon Sep 17 00:00:00 2001 From: Dan-in-CA Date: Tue, 15 Oct 2013 20:48:40 -0700 Subject: [PATCH 08/13] Program preview was broken. --- static/scripts/java/svc1.8.3/plotprog.js | 328 +++++++++++------------ 1 file changed, 164 insertions(+), 164 deletions(-) diff --git a/static/scripts/java/svc1.8.3/plotprog.js b/static/scripts/java/svc1.8.3/plotprog.js index 4faac8e..6d52287 100644 --- a/static/scripts/java/svc1.8.3/plotprog.js +++ b/static/scripts/java/svc1.8.3/plotprog.js @@ -1,164 +1,164 @@ -// Javascript for printing OpenSprinkler schedule page -// Firmware v1.8 -// All content is published under: -// Creative Commons Attribution ShareAlike 3.0 License -// Sep 2012, Rayshobby.net - -// colors to draw different programs -var prog_color=["rgba(0,0,200,0.5)","rgba(0,200,0,0.5)","rgba(200,0,0,0.5)","rgba(0,200,200,0.5)"]; -var days_str=["Sun","Mon","Tue","Wed","Thur","Fri","Sat"]; -var xstart=80,ystart=80,stwidth=40,stheight=180; -var winwidth=stwidth*sd['nbrd']*8+xstart, winheight=26*stheight+ystart; -var sid,sn,t; -var simt=Date.UTC(yy,mm-1,dd,0,0,0,0); -var simdate=new Date(simt); -var simday = (simt/1000/3600/24)>>0; -function w(s) {document.writeln(s);} -function check_match(prog,simminutes,simdate,simday) { - // simdate is Java date object, simday is the #days since 1970 01-01 - var wd,dn,drem; - if(prog[0]==0) return 0; - if ((prog[1]&0x80)&&(prog[2]>1)) { // inverval checking - dn=prog[2];drem=prog[1]&0x7f; - if((simday%dn)!=((devday+drem)%dn)) return 0; // remainder checking - } else { - wd=(simdate.getUTCDay()+6)%7; // getDay assumes sunday is 0, converts to Monday 0 - if((prog[1]&(1<prog[4]) return 0; // start and end time checking - if(prog[5]==0) return 0; - if(((simminutes-prog[3])/prog[5]>>0)*prog[5] == (simminutes-prog[3])) { // interval checking - return 1; - } - return 0; // no match found -} -function getx(sid) {return xstart+sid*stwidth-stwidth/2;} // x coordinate given a station -function gety(t) {return ystart+t*stheight/60;} // y coordinate given a time -function getrunstr(start,end){ // run time string - var h,m,s,str; - h=start/3600>>0;m=(start/60>>0)%60;s=start%60; - str=""+(h/10>>0)+(h%10)+":"+(m/10>>0)+(m%10)+":"+(s/10>>0)+(s%10); - h=end/3600>>0;m=(end/60>>0)%60;s=end%60; - str+="->"+(h/10>>0)+(h%10)+":"+(m/10>>0)+(m%10)+":"+(s/10>>0)+(s%10); - return str; -} -function plot_bar(sid,start,pid,end) { // plot program bar - w("
P"+pid+"
"); -} -function plot_master(start,end) { // plot master station - w("
"); - //if(mas==0||start==end) return; - //ctx.fillStyle="rgba(64,64,64,0.5)"; - //ctx.fillRect(getx(mas-1),gety(start/60),stwidth,(end-start)/60*stheight/60); -} -function plot_currtime() { - w("
"); -} -function run_sched(simseconds,st_array,pid_array,et_array) { // run and plot schedule stored in array data - var sid,endtime=simseconds; - for(sid=0;sid0)&&(sd['mas']!=sid+1)&&(sd['mo'][sid>>3]&(1<<(sid%8)))) - plot_master(st_array[sid]+sd['mton'], et_array[sid]+sd['mtoff']); - endtime=et_array[sid]; - } else { // concurrent - plot_bar(sid,simseconds,pid_array[sid],et_array[sid]); - // check if this station activates master - if((sd['mas']>0)&&(sd['mas']!=sid+1)&&(sd['mo'][sid>>3]&(1<<(sid%8)))) - endtime=(endtime>et_array[sid])?endtime:et_array[sid]; - } - } - } - if(sd['seq']==0&&sd['mas']>0) plot_master(simseconds,endtime); - return endtime; -} -function draw_title() { - w("
Program Preview of "); - w(days_str[simdate.getUTCDay()]+" "+(simdate.getUTCMonth()+1)+"/"+(simdate.getUTCDate())+" "+(simdate.getUTCFullYear())); - w("
(Hover over each colored bar to see tooltip)"); - w("
"); -} - -function draw_grid() { - // draw table and grid - for(sid=0;sid<=sd['nbrd']*8;sid++) { - sn=sid+1; - if(sidS"+(sn/10>>0)+(sn%10)+""); - w("
"); - } - // horizontal grid, time - for(t=0;t<=24;t++) { - w("
"); - w("
"); - w("
"+(t/10>>0)+(t%10)+":00
"); - } - plot_currtime(); -} -function draw_program() { - // plot program data by a full simulation - var simminutes=0,busy=0,match_found=0,bid,s,sid,pid,match=[0,0]; - var st_array=new Array(sd['nbrd']*8),pid_array=new Array(sd['nbrd']*8); - var et_array=new Array(sd['nbrd']*8); - for(sid=0;sid>3;s=sid%8; - if(sd['mas']==(sid+1)) continue; // skip master station - if(prog[7+bid]&(1<>0;pid_array[sid]=pid+1; - match_found=1; - }//if - }//for_sid - }//if_match - }//for_pid - if(match_found) { - var acctime=simminutes*60; - if(sd['seq']) { // sequential - for(sid=0;sid>0; - if(sd['seq']&&simminutes!=endminutes) simminutes=endminutes; - else simminutes++; - for(sid=0;sid>0)*60)); // scroll to the hour line cloest to the current time -} - -draw_title(); -draw_grid(); -draw_program(); +// Javascript for printing OpenSprinkler schedule page +// Firmware v1.8 +// All content is published under: +// Creative Commons Attribution ShareAlike 3.0 License +// Sep 2012, Rayshobby.net + +// colors to draw different programs +var prog_color=["rgba(0,0,200,0.5)","rgba(0,200,0,0.5)","rgba(200,0,0,0.5)","rgba(0,200,200,0.5)"]; +var days_str=["Sun","Mon","Tue","Wed","Thur","Fri","Sat"]; +var xstart=80,ystart=80,stwidth=40,stheight=180; +var winwidth=stwidth*sd['nbrd']*8+xstart, winheight=26*stheight+ystart; +var sid,sn,t; +var simt=Date.UTC(yy,mm-1,dd,0,0,0,0); +var simdate=new Date(simt); +var simday = (simt/1000/3600/24)>>0; +function w(s) {document.writeln(s);} +function check_match(prog,simminutes,simdate,simday) { + // simdate is Java date object, simday is the #days since 1970 01-01 + var wd,dn,drem; + if(prog[0]==0) return 0; + if ((prog[1]&0x80)&&(prog[2]>1)) { // inverval checking + dn=prog[2];drem=prog[1]&0x7f; + if((simday%dn)!=((devday+drem)%dn)) return 0; // remainder checking + } else { + wd=(simdate.getUTCDay()+6)%7; // getDay assumes sunday is 0, converts to Monday 0 + if((prog[1]&(1<prog[4]) return 0; // start and end time checking + if(prog[5]==0) return 0; + if(((simminutes-prog[3])/prog[5]>>0)*prog[5] == (simminutes-prog[3])) { // interval checking + return 1; + } + return 0; // no match found +} +function getx(sid) {return xstart+sid*stwidth-stwidth/2;} // x coordinate given a station +function gety(t) {return ystart+t*stheight/60;} // y coordinate given a time +function getrunstr(start,end){ // run time string + var h,m,s,str; + h=start/3600>>0;m=(start/60>>0)%60;s=start%60; + str=""+(h/10>>0)+(h%10)+":"+(m/10>>0)+(m%10)+":"+(s/10>>0)+(s%10); + h=end/3600>>0;m=(end/60>>0)%60;s=end%60; + str+="->"+(h/10>>0)+(h%10)+":"+(m/10>>0)+(m%10)+":"+(s/10>>0)+(s%10); + return str; +} +function plot_bar(sid,start,pid,end) { // plot program bar + w("
P"+pid+"
"); +} +function plot_master(start,end) { // plot master station + w("
"); + //if(sd['mas']==0||start==end) return; + //ctx.fillStyle="rgba(64,64,64,0.5)"; + //ctx.fillRect(getx(mas-1),gety(start/60),stwidth,(end-start)/60*stheight/60); +} +function plot_currtime() { + w("
"); +} +function run_sched(simseconds,st_array,pid_array,et_array) { // run and plot schedule stored in array data + var sid,endtime=simseconds; + for(sid=0;sid0)&&(sd['mas']!=sid+1)&&(sd['mo'][sid>>3]&(1<<(sid%8)))) + plot_master(st_array[sid]+sd['mton'], et_array[sid]+sd['mtoff']); + endtime=et_array[sid]; + } else { // concurrent + plot_bar(sid,simseconds,pid_array[sid],et_array[sid]); + // check if this station activates master + if((sd['mas']>0)&&(sd['mas']!=sid+1)&&(sd['mo'][sid>>3]&(1<<(sid%8)))) + endtime=(endtime>et_array[sid])?endtime:et_array[sid]; + } + } + } + if(sd['seq']==0&&sd['mas']>0) plot_master(simseconds,endtime); + return endtime; +} +function draw_title() { + w("
Program Preview of "); + w(days_str[simdate.getUTCDay()]+" "+(simdate.getUTCMonth()+1)+"/"+(simdate.getUTCDate())+" "+(simdate.getUTCFullYear())); + w("
(Hover over each colored bar to see tooltip)"); + w("
"); +} + +function draw_grid() { + // draw table and grid + for(sid=0;sid<=sd['nbrd']*8;sid++) { + sn=sid+1; + if(sidS"+(sn/10>>0)+(sn%10)+""); + w("
"); + } + // horizontal grid, time + for(t=0;t<=24;t++) { + w("
"); + w("
"); + w("
"+(t/10>>0)+(t%10)+":00
"); + } + plot_currtime(); +} +function draw_program() { + // plot program data by a full simulation + var simminutes=0,busy=0,match_found=0,bid,s,sid,pid,match=[0,0]; + var st_array=new Array(sd['nbrd']*8),pid_array=new Array(sd['nbrd']*8); + var et_array=new Array(sd['nbrd']*8); + for(sid=0;sid>3;s=sid%8; + if(sd['mas']==(sid+1)) continue; // skip master station + if(prog[7+bid]&(1<>0;pid_array[sid]=pid+1; + match_found=1; + }//if + }//for_sid + }//if_match + }//for_pid + if(match_found) { + var acctime=simminutes*60; + if(sd['seq']) { // sequential + for(sid=0;sid>0; + if(sd['seq']&&simminutes!=endminutes) simminutes=endminutes; + else simminutes++; + for(sid=0;sid>0)*60)); // scroll to the hour line cloest to the current time +} + +draw_title(); +draw_grid(); +draw_program(); From 41b5b83ee9b709b111866cff77a9ac5bd40380cd Mon Sep 17 00:00:00 2001 From: Dan-in-CA Date: Wed, 16 Oct 2013 12:08:12 -0700 Subject: [PATCH 09/13] Small change to rain delay code. --- ospi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ospi.py b/ospi.py index 1b1ff69..ab2c6b6 100644 --- a/ospi.py +++ b/ospi.py @@ -556,7 +556,7 @@ class change_values: gv.srvals = [0]*(gv.sd['nst']) # turn off all stations set_output() if qdict.has_key('mm') and qdict['mm'] == '0': clear_mm() - if qdict.has_key('rd') and qdict['rd'] != '0' and qdict['rd'] != '': + if qdict.has_key('rd') and qdict['rd'] > '0': gv.sd['rdst'] = (gv.now+(int(qdict['rd'])*3600)) stop_onrain() elif qdict.has_key('rd') and qdict['rd'] == '0': gv.sd['rdst'] = 0 From 2919b847f0a7a8228a585c307f0b074f36ea5a15 Mon Sep 17 00:00:00 2001 From: Dan-in-CA Date: Wed, 16 Oct 2013 12:10:40 -0700 Subject: [PATCH 10/13] added water_log.csv to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7a0271f..50a366f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ web/ /data/sd.json /data/snames.txt *.pyc +/static/log/water_log.csv From c3eeda7e90b6378977a32819641d0e4cbacd3001 Mon Sep 17 00:00:00 2001 From: Dan-in-CA Date: Wed, 16 Oct 2013 12:32:50 -0700 Subject: [PATCH 11/13] Edited .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 50a366f..885f96e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ web/ /data/sd.json /data/snames.txt *.pyc -/static/log/water_log.csv +/static/log/ From 9790d961b1babedc2e50139bb77844633d40ba09 Mon Sep 17 00:00:00 2001 From: Dan-in-CA Date: Wed, 16 Oct 2013 12:42:57 -0700 Subject: [PATCH 12/13] Fixed rain delay and program preview bugs. --- README.md | 7 +++++++ ospi.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bf2866f..2d314ab 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,13 @@ UPDATES =========== *********** +October 16 2013 +-------------- +(Dan)
+Additions, bug fixes:
+1. Fixed a bug that would cause an error in program preview when a master was enabled.
+2. Changing to manual mode would clear rain delay setting, Setting rain delay in manual mode would switch to program mode - fixed. + October 11 2013 -------------- (Dan)
diff --git a/ospi.py b/ospi.py index ab2c6b6..1b1ff69 100644 --- a/ospi.py +++ b/ospi.py @@ -556,7 +556,7 @@ class change_values: gv.srvals = [0]*(gv.sd['nst']) # turn off all stations set_output() if qdict.has_key('mm') and qdict['mm'] == '0': clear_mm() - if qdict.has_key('rd') and qdict['rd'] > '0': + if qdict.has_key('rd') and qdict['rd'] != '0' and qdict['rd'] != '': gv.sd['rdst'] = (gv.now+(int(qdict['rd'])*3600)) stop_onrain() elif qdict.has_key('rd') and qdict['rd'] == '0': gv.sd['rdst'] = 0 From f47e1a191d62dbd0410547f18853af86d6e56202 Mon Sep 17 00:00:00 2001 From: Dan-in-CA Date: Wed, 16 Oct 2013 12:45:59 -0700 Subject: [PATCH 13/13] Updated rev info --- ospi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ospi.py b/ospi.py index 1b1ff69..ea398c1 100644 --- a/ospi.py +++ b/ospi.py @@ -11,8 +11,8 @@ except ImportError: #### Revision information #### gv.ver = 183 -gv.rev = 138 -gv.rev_date = '11/October/2013' +gv.rev = 139 +gv.rev_date = '16/October/2013' #### urls is a feature of web.py. When a GET request is received , the corresponding class is executed. urls = [