├── .gitignore ├── AUTHORS ├── COPYING ├── IrrduinoController ├── IrrduinoController.pde ├── commandCentral.pde ├── htmlOutput.pde ├── serverReport.pde └── web-ctrl-api.txt ├── IrrduinoDroid └── IrrduinoRemote │ ├── .classpath │ ├── .project │ ├── .settings │ └── org.eclipse.jdt.core.prefs │ ├── AndroidManifest.xml │ ├── assets │ ├── grass-and-sky-background-portrait.svg │ ├── grass-and-sky.svg │ ├── grass-icon.png │ └── grass-icon.svg │ ├── proguard.cfg │ ├── project.properties │ ├── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-ldpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── drawable │ │ ├── grass_and_sky_background_portrait.png │ │ ├── ic_menu_report.png │ │ └── ic_menu_settings.png │ ├── layout │ │ ├── main.xml │ │ ├── main_table.xml │ │ └── report.xml │ ├── menu │ │ └── app_menu.xml │ ├── values │ │ └── strings.xml │ └── xml │ │ └── settings.xml │ └── src │ └── com │ └── joefernandez │ └── irrduino │ └── android │ └── remote │ ├── HttpCommandTask.java │ ├── IrrduinoRemoteActivity.java │ ├── Settings.java │ └── ViewReportActivity.java ├── IrrduinoServer ├── .project ├── .pydevproject ├── README ├── app.yaml ├── index.yaml ├── irrduinoserver │ ├── __init__.py │ ├── handlers │ │ ├── __init__.py │ │ ├── abouthandler.py │ │ ├── irrigatehandler.py │ │ ├── lawnvillehandler.py │ │ ├── loghandler.py │ │ └── reportshandler.py │ ├── initialization.py │ ├── main.py │ ├── model.py │ ├── routes.py │ ├── templates │ │ ├── about.html │ │ ├── irrigate.html │ │ ├── lawnville.html │ │ ├── layout.html │ │ ├── log.html │ │ └── reports.html │ └── utils │ │ ├── __init__.py │ │ ├── irrduino.py │ │ ├── ui.py │ │ └── web.py ├── static │ ├── css │ │ └── layout.css │ ├── dart │ │ ├── dart.js │ │ ├── lawnville.dart │ │ ├── lawnville.dart.js │ │ ├── lawnville.dart.js.deps │ │ └── lawnville.dart.js.map │ ├── favicon.ico │ └── images │ │ ├── droid-jetpack-on-front.png │ │ ├── droid-waiting-front.png │ │ ├── droid-waiting-lower-head.png │ │ ├── droid-watering-1.png │ │ ├── droid-watering-2.png │ │ ├── grass.png │ │ └── map.png └── third-party │ └── httplib2 │ ├── __init__.py │ ├── cacerts.txt │ ├── iri2uri.py │ ├── socks.py │ └── test │ ├── __init__.py │ ├── brokensocket │ └── socket.py │ ├── functional │ └── test_proxies.py │ ├── miniserver.py │ ├── other_cacerts.txt │ ├── smoke_test.py │ └── test_no_socket.py └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Eclipse 2 | .metadata 3 | 4 | # OS X 5 | .DS_Store 6 | 7 | # Python 8 | *.pyc 9 | 10 | # IntelliJ and PyCharm 11 | .idea 12 | 13 | # Python 14 | .*.swp 15 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Joe Fernandez 2 | Shannon -jj Behrens -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2012 Google Inc. 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. -------------------------------------------------------------------------------- /IrrduinoController/IrrduinoController.pde: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | Irrduino v0.8.2 by Joe Fernandez 17 | 18 | Issues: 19 | - need a nanny process to check a max run time for valves (regardless of commands or program) 20 | - not working on an Arduino Ethernet board 21 | 22 | Change Log: 23 | - 2012-01-09 - changed reporting to point to /log (instead of /reports) 24 | - 2012-01-07 - added run time in seconds (web command syntax option and 25 | update to CommandDispatch handling) 26 | - 2011-12-14 - added function to retrieve current settings 27 | - 2011-12-13 - added REST command for system settings /settings?rr 28 | - 2011-12-02 - added function to report zone runs checkAndPostReport() 29 | - 2011-12-02 - add per-zone status reporting, with zone IDs and remaining times 30 | - 2011-11-10 - add global status option 31 | - 2011-10-27 - added code to turn on and blink an LED on pin 13 while zone running 32 | - 2011-10-07 - fixed problem with home page not displaying after first request 33 | - fixed problem mismatch between zone/pin selection 34 | - 2011-10-05 - Version 0.6 completed 35 | - 3 file split, commandDispatch[] infrastructure implemented 36 | - fixed problem with zone command being run repeatedly 37 | - 2011-09-28 - Split pde into parts for easier code management 38 | - Introduced new commandDispatch[] object for storing command parameters 39 | - 2011-09-25 - Added web UI for more zones and "ALL OFF" function 40 | - 2011-09-xx - Entended parser to turn off zones indifvidually 41 | - updated to use timer for executing irrigation zone runs; now runs can be interrupted 42 | 43 | An irrigation control program with a REST-like http 44 | remote control protocol. 45 | 46 | Based on David A. Mellis's "Web Server" ethernet 47 | shield example sketch. 48 | 49 | REST implementation based on "RESTduino" sketch 50 | by Jason J. Gullickson 51 | */ 52 | 53 | #include 54 | #include 55 | #include 56 | 57 | 58 | byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xE2, 0xEB }; //physical mac address 59 | byte ip[] = { 192, 168, 1, 15 }; // ip in lan 60 | byte gateway[] = { 192, 168, 1, 1 }; // internet access via router 61 | byte dnsServerIp[] = { 192, 168, 1, 1}; // DNS server IP (typically your gateway) 62 | byte subnet[] = { 255, 255, 255, 0 }; //subnet mask 63 | 64 | Server server(80); //server port 65 | Client client = NULL; // client 66 | 67 | // zone to pin mapping 68 | int zone1 = 2; //pin 2 69 | int zone2 = 3; //pin 3 70 | int zone3 = 4; //pin 4 71 | int zone4 = 5; //pin 5 72 | int zone5 = 6; //pin 6 73 | int zone6 = 7; //pin 7 74 | int zone7 = 8; //pin 8 75 | int zone8 = 9; //pin 9 76 | 77 | int zone9 = A0; //pin A0 78 | int zone10 = A1; //pin A1 79 | int zone11 = A2; //pin A2 80 | int zone12 = A3; //pin A3 81 | 82 | // LED indicator pin variables 83 | int ledIndicator = 13; 84 | int ledState = LOW; 85 | unsigned long ledFlashTimer = 0; // timer for LED in milliseconds 86 | unsigned long ledFlashInterval = 1000; // flash interval in milliseconds 87 | 88 | // set the maximum run time for a zone (safeguard) 89 | unsigned long MAX_RUN_TIME_MINUTES = 30; // Default 30 minutes 90 | unsigned long MAX_RUN_TIME = MAX_RUN_TIME_MINUTES * 60000; 91 | 92 | int zones[] = {zone1, zone2, zone3, zone4, 93 | zone5, zone6, zone7, zone8, 94 | zone9, zone10, zone11, zone12}; 95 | 96 | int zoneCount = 12; 97 | 98 | // REST commands 99 | const String REST_CMD_OFF = "off"; 100 | const String REST_CMD_STATUS = "status"; 101 | const String REST_CMD_ZONE = "zone"; 102 | const String REST_CMD_ZONES = "zones"; 103 | const String REST_CMD_SETTINGS = "settings"; 104 | const String REST_CMD_TESTREPORT = "testreport"; 105 | 106 | // Command codes 107 | const int OBJ_CMD_ALL_OFF = 1; 108 | const int OBJ_CMD_STATUS = 2; 109 | const int OBJ_CMD_SETTINGS = 3; 110 | const int OBJ_CMD_ZONES = 10; 111 | const int OBJ_CMD_ZONE = 100; 112 | const int OBJ_CMD_PROGRAMS = 20; 113 | const int OBJ_CMD_PROGRAM = 200; 114 | 115 | // Reporting constants and variables 116 | int maxReportAttempts = 3; 117 | int reportAttempts = 0; 118 | 119 | boolean reportingEnabled = false; // reporting disabled by default 120 | char reportingHostName[512]; 121 | int reportingHostPort = 80; 122 | 123 | // Command Codes (CC) 124 | const int CC_OFF = 0; 125 | const int CC_ON = 1; 126 | const int CC_STATUS = 3; 127 | 128 | // Command Dispatch structure - for processing incoming commands 129 | int commandDispatchLength = 5; 130 | int commandDispatch[] = { 0, // command object type, 0 for none 131 | 0, // command object id, 0 for none 132 | 0, // command code, 0 for none 133 | 0, // value 1, 0 for none 134 | 0 // value 2, 0 for none 135 | }; 136 | const int CD_OBJ_TYPE = 0; 137 | const int CD_OBJ_ID = 1; 138 | const int CD_CMD_CODE = 2; 139 | const int CD_VALUE_1 = 3; 140 | const int CD_VALUE_2 = 4; 141 | 142 | // Command Running structure - for managing running commands 143 | int commandRunningLength = 4; 144 | unsigned long commandRunning[] = {0, // pin ID, 0 for none 145 | 0, // run end time in milliseconds, 0 for none 146 | 0, // zone ID, 0 for none 147 | 0 // run start time in milliseconds, 0 for none 148 | }; 149 | const int CR_PIN_ID = 0; 150 | const int CR_END_TIME = 1; 151 | const int CR_ZONE_ID = 2; 152 | const int CR_START_TIME = 3; 153 | 154 | // Command Report structure - for reporting completed runs (use CR_ constants for indexes) 155 | int commandReportLength = 4; 156 | unsigned long commandReport[] = {0, // pin ID, 0 for none 157 | 0, // run end time in miliseconds, 0 for none 158 | 0, // zone ID, 0 for none 159 | 0 // run start time in milliseconds, 0 for none 160 | }; 161 | 162 | String jsonReply; 163 | String reportData; 164 | 165 | void setup(){ 166 | // Turn on serial output for debugging 167 | Serial.begin(9600); 168 | 169 | Serial.println("Irrduino starting up..."); 170 | 171 | // Start Ethernet connection and server 172 | Ethernet.begin(mac, ip, gateway, subnet); 173 | server.begin(); 174 | 175 | // Set the DNS server (for resolving hosts) 176 | EthernetDNS.setDNSServer(dnsServerIp); 177 | 178 | //Set relay pins to output 179 | for (int i = 0; i < zoneCount; i++){ 180 | pinMode(zones[i], OUTPUT); 181 | } 182 | 183 | // set the LED indicator pin for output 184 | // pinMode(ledIndicator, OUTPUT); // (causes failure on Arduino Ethernet board) 185 | } 186 | 187 | // url buffer size 188 | #define BUFSIZE 255 189 | 190 | void loop(){ 191 | char clientLine[BUFSIZE]; 192 | int index = 0; 193 | 194 | // check on timed runs, shutdown expired runs 195 | checkTimedRun(); 196 | 197 | // check for pending reports to be sent 198 | checkAndPostReport(); 199 | 200 | // listen for incoming clients 201 | client = server.available(); 202 | if (client) { 203 | 204 | // reset input buffer 205 | index = 0; 206 | 207 | while (client.connected()) { 208 | if (client.available()) { 209 | char c = client.read(); 210 | 211 | // fill buffer with url 212 | if(c != '\n' && c != '\r'){ 213 | 214 | // if we run out of buffer, overwrite the end 215 | if(index >= BUFSIZE) { 216 | break; 217 | //index = BUFSIZE -1; 218 | } 219 | 220 | clientLine[index] = c; 221 | index++; 222 | 223 | // Serial.print("client-c: "); 224 | // Serial.println(c); 225 | continue; 226 | } 227 | Serial.print("http request: "); 228 | Serial.println(clientLine); 229 | 230 | // convert clientLine into a proper 231 | // string for further processing 232 | String urlString = String(clientLine); 233 | 234 | if (urlString.lastIndexOf("TTP/1.1") < 0 ){ 235 | Serial.println("no HTTP/1.1, ignoring request"); 236 | // not a url request, ignore this 237 | goto finish_http; 238 | } 239 | 240 | // extract the operation (GET or POST) 241 | String op = urlString.substring(0,urlString.indexOf(' ')); 242 | 243 | // we're only interested in the first part... 244 | urlString = urlString.substring( 245 | urlString.indexOf('/'), 246 | urlString.indexOf(' ', urlString.indexOf('/'))); 247 | 248 | // put what's left of the URL back in client line 249 | urlString.toCharArray(clientLine, BUFSIZE); 250 | 251 | // get the parameters 252 | char *arg1 = strtok(clientLine,"/"); 253 | Serial.print("arg1: "); 254 | Serial.println(arg1); 255 | char *arg2 = strtok(NULL,"/"); 256 | Serial.print("arg2: "); 257 | Serial.println(arg2); 258 | char *arg3 = strtok(NULL,"/"); 259 | Serial.print("arg3: "); 260 | Serial.println(arg3); 261 | char *arg4 = strtok(NULL,"/"); 262 | Serial.print("arg4: "); 263 | Serial.println(arg4); 264 | 265 | if (arg1 == NULL){ 266 | // we got no parameters. show default page 267 | httpHomePage(); 268 | 269 | } else { 270 | // start a json reply 271 | jsonReply = String(); 272 | // identify the command 273 | findCmdObject(arg1); 274 | 275 | switch (commandDispatch[CD_OBJ_TYPE]) { 276 | 277 | case OBJ_CMD_ALL_OFF: // all off command 278 | cmdZonesOff(); 279 | break; 280 | 281 | case OBJ_CMD_STATUS: // Global status ping 282 | cmdGlobalStatusRequest(); 283 | break; 284 | 285 | case OBJ_CMD_SETTINGS: // Controller settings 286 | findSettingsCommand(arg1); 287 | break; 288 | 289 | case OBJ_CMD_ZONE: // zone command 290 | 291 | findZoneCommand(arg2); 292 | 293 | switch (commandDispatch[CD_CMD_CODE]){ 294 | case CC_OFF: 295 | endTimedRun(); 296 | break; 297 | case CC_ON: 298 | findZoneTimeValue(arg3); 299 | cmdZoneTimedRun(); 300 | break; 301 | case CC_STATUS: 302 | cmdZoneStatus(); 303 | break; 304 | } 305 | 306 | break; 307 | case OBJ_CMD_ZONES: // all zones 308 | break; 309 | case OBJ_CMD_PROGRAM: // program command 310 | break; 311 | case OBJ_CMD_PROGRAMS: // all programs 312 | break; 313 | 314 | default: 315 | httpJsonReply("\"ERROR\":\"Command not recognized.\""); 316 | } 317 | } 318 | } 319 | } 320 | 321 | // finish http response 322 | finish_http: 323 | 324 | // clear Command Dispatch 325 | Serial.println("clearCommandDispatch()"); 326 | clearCommandDispatch(); 327 | 328 | // Clear the clientLine char array 329 | Serial.println("clear client line: clearCharArray()"); 330 | clearCharArray(clientLine, BUFSIZE); 331 | 332 | // give the web browser time to receive the data 333 | delay(20); 334 | 335 | // close the connection: 336 | client.stop(); 337 | 338 | } 339 | } /// ========= end loop() ========= 340 | 341 | void findCmdObject(char *cmdObj){ 342 | 343 | String commandObject = String(cmdObj); 344 | commandObject = commandObject.toLowerCase(); 345 | 346 | // check for "OFF" shortcut 347 | if (commandObject.compareTo("off") == 0) { 348 | commandDispatch[CD_OBJ_TYPE] = OBJ_CMD_ALL_OFF; 349 | jsonReply += "\"command\":\"zones off\""; 350 | return; 351 | } 352 | 353 | // check for global "status" request "/status" 354 | if (commandObject.compareTo(REST_CMD_STATUS) == 0) { 355 | commandDispatch[CD_OBJ_TYPE] = OBJ_CMD_STATUS; 356 | return; 357 | } 358 | 359 | // check for settings request "/settings" 360 | if (commandObject.startsWith(REST_CMD_SETTINGS)) { 361 | commandDispatch[CD_OBJ_TYPE] = OBJ_CMD_SETTINGS; 362 | return; 363 | } 364 | 365 | // must check for plural form first 366 | if (commandObject.compareTo(REST_CMD_ZONES) == 0) { 367 | commandDispatch[CD_OBJ_TYPE] = OBJ_CMD_ZONES; 368 | jsonReply += "\"zones\":"; 369 | return; 370 | } 371 | 372 | if (commandObject.startsWith(REST_CMD_ZONE)) { 373 | commandDispatch[CD_OBJ_TYPE] = OBJ_CMD_ZONE; // command object type, 0 for none 374 | jsonReply += "\"zone"; 375 | 376 | // get zone number 377 | String zoneNumber = commandObject.substring( 378 | commandObject.lastIndexOf('e') + 1, 379 | commandObject.length() ); 380 | 381 | commandDispatch[CD_OBJ_ID] = stringToInt(zoneNumber); // command object id, 0 for none 382 | jsonReply += zoneNumber; 383 | jsonReply += "\":"; 384 | return; 385 | } 386 | 387 | // must check for plural form first 388 | if (commandObject.compareTo("programs") == 0) { 389 | commandDispatch[CD_OBJ_TYPE] = OBJ_CMD_PROGRAMS; 390 | jsonReply += "\"programs\":"; 391 | return; 392 | } 393 | if (commandObject.startsWith("program")) { 394 | commandDispatch[CD_OBJ_TYPE] = OBJ_CMD_PROGRAM; 395 | jsonReply += "\"program"; 396 | 397 | // get program number 398 | String progNumber = commandObject.substring( 399 | commandObject.lastIndexOf('m') + 1, 400 | commandObject.length() ); 401 | 402 | commandDispatch[CD_OBJ_ID] = stringToInt(progNumber); // command object id, 0 for none 403 | jsonReply += progNumber; 404 | jsonReply += "\":"; 405 | return; 406 | } 407 | 408 | } 409 | 410 | // interprets the command following the /zoneX/ command prefix 411 | void findZoneCommand(char *zoneCmd){ 412 | 413 | String zoneCommand = String(zoneCmd); 414 | 415 | // if zone command is empty, treat as a status request 416 | if (zoneCommand.length() < 1){ 417 | commandDispatch[CD_CMD_CODE] = CC_STATUS; 418 | // clear the json reply 419 | jsonReply = ""; 420 | return; 421 | } 422 | 423 | zoneCommand = zoneCommand.toLowerCase(); 424 | 425 | // check for "ON" 426 | if (zoneCommand.compareTo("on") == 0) { 427 | commandDispatch[CD_CMD_CODE] = CC_ON; 428 | jsonReply += "\"on\""; 429 | return; 430 | } 431 | 432 | // check for "OFF" 433 | if (zoneCommand.compareTo("off") == 0) { 434 | commandDispatch[CD_CMD_CODE] = CC_OFF; 435 | jsonReply += "\"off\""; 436 | return; 437 | } 438 | 439 | // check for "status" 440 | if (zoneCommand.compareTo(REST_CMD_STATUS) == 0) { 441 | commandDispatch[CD_CMD_CODE] = CC_STATUS; 442 | // clear the json reply 443 | jsonReply = ""; 444 | return; 445 | } 446 | 447 | } 448 | 449 | // Finds and sets the zone run time in seconds 450 | void findZoneTimeValue(char *zoneTimeValue){ 451 | 452 | String zoneTime = String(zoneTimeValue); 453 | 454 | if (zoneTime.lastIndexOf("s") >= 0 ){ 455 | // zone run request is in seconds (e.g., 30s) 456 | zoneTime = zoneTime.substring(0, zoneTime.lastIndexOf("s")); 457 | commandDispatch[CD_VALUE_1] = stringToInt(zoneTime); 458 | 459 | } else { 460 | int time = atoi(zoneTimeValue); 461 | commandDispatch[CD_VALUE_1] = time * 60; 462 | } 463 | 464 | } 465 | 466 | // interpret and execute settings commands 467 | void findSettingsCommand(char *settings){ 468 | 469 | char *arg, *i; 470 | int count=0; 471 | // get the parameters 472 | arg = strtok_r(settings,"?",&i); 473 | Serial.print("arg "); 474 | Serial.print(count); 475 | Serial.print(": "); 476 | Serial.println(arg); 477 | 478 | while (arg != NULL && count < 16){ 479 | arg = strtok_r(NULL,"&",&i); 480 | if (arg != NULL) { 481 | count++; 482 | Serial.print("arg "); 483 | Serial.print(count); 484 | Serial.print(": "); 485 | Serial.println(arg); 486 | setSettings(arg); 487 | } 488 | } 489 | 490 | // /settings with no parameters: return setting values 491 | if ( count == 0 ){ 492 | jsonReply += "\"reportingEnabled\":"; 493 | if (reportingEnabled){ 494 | jsonReply += "\"true\""; 495 | } else { 496 | jsonReply += "\"false\""; 497 | } 498 | jsonReply += ",\"reportingHostName\":\""; 499 | jsonReply += reportingHostName; 500 | jsonReply += "\""; 501 | jsonReply += ",\"reportingHostPort\":\""; 502 | jsonReply += reportingHostPort; 503 | jsonReply += "\""; 504 | } 505 | 506 | // send reply, send error message if message empty 507 | if (jsonReply == NULL || jsonReply.length() == 0){ 508 | jsonReply = "\"settings\":\"parameters not recognized\""; 509 | } 510 | httpJsonReply(jsonReply); 511 | 512 | // clear the command, so we don't re-execute 513 | clearCommandDispatch(); 514 | } 515 | 516 | void setSettings(char *valuePair){ 517 | char *aLabel = strtok(valuePair, "="); 518 | char *aValue = strtok(NULL, "="); 519 | 520 | String label = String(aLabel); 521 | String value = String(aValue); 522 | 523 | // check for "reportingEnabled" setting 524 | if (label.compareTo("reportingEnabled") == 0 || 525 | label.compareTo("re") == 0) { // label shortcut 526 | if(jsonReply != NULL && jsonReply.length() > 0){ 527 | jsonReply += ","; 528 | } 529 | if (value.compareTo("true") == 0) { 530 | reportingEnabled = true; 531 | jsonReply += "\"reportingEnabled\":\"true\""; 532 | } 533 | if (value.compareTo("false") == 0) { 534 | reportingEnabled = false; 535 | jsonReply += "\"reportingEnabled\":\"false\""; 536 | } 537 | return; 538 | } 539 | 540 | if (label.compareTo("reportingHostName") == 0 || 541 | label.compareTo("rhn") == 0){ // label shortcut 542 | if(jsonReply != NULL && jsonReply.length() > 0){ 543 | jsonReply += ","; 544 | } 545 | if (value.length() >= 4) { 546 | value.toCharArray(reportingHostName, 512); 547 | jsonReply += "\"reportingHostName\":\""; 548 | jsonReply += value; 549 | jsonReply += "\""; 550 | } 551 | return; 552 | } 553 | 554 | if (label.compareTo("reportingHostPort") == 0 || 555 | label.compareTo("rhp") == 0){ // label shortcut 556 | if(jsonReply != NULL && jsonReply.length() > 0){ 557 | jsonReply += ","; 558 | } 559 | if (value.length() >= 1) { 560 | reportingHostPort = stringToInt(value); 561 | jsonReply += "\"reportingHostPort\":\""; 562 | jsonReply += value; 563 | jsonReply += "\""; 564 | } 565 | return; 566 | } 567 | } 568 | 569 | // Utility functions 570 | 571 | void clearCharArray(char array[], int length){ 572 | for (int i=0; i < length; i++) { 573 | //if (array[i] == 0) {break; }; 574 | array[i] = 0; 575 | } 576 | } 577 | 578 | void clearCommandDispatch(){ 579 | for (int i = 0; i < commandDispatchLength; i++){ 580 | commandDispatch[i] = 0; 581 | } 582 | } 583 | 584 | void clearCommandRunning(){ 585 | for (int i = 0; i < commandRunningLength; i++){ 586 | commandRunning[i] = 0; 587 | } 588 | } 589 | 590 | void clearCommandReport(){ 591 | for (int i = 0; i < commandReportLength; i++){ 592 | commandReport[i] = 0; 593 | } 594 | } 595 | 596 | // standard function for debug/logging 597 | void writeLog(String logMsg){ 598 | 599 | Serial.println(logMsg); 600 | 601 | //TODO: buffer log message for web delivery 602 | //TODO: write log message to SDCard (if available) 603 | 604 | } 605 | 606 | int stringToInt(String value){ 607 | // remember to add 1 to the length for the terminating null 608 | char buffer[value.length() +1]; 609 | value.toCharArray(buffer, value.length() +1 ); 610 | return atoi(buffer); 611 | } 612 | -------------------------------------------------------------------------------- /IrrduinoController/commandCentral.pde: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // functions for controlling Arduino pin outputs 16 | 17 | void cmdZonesOff(){ 18 | httpJsonReply("\"zones\":\"ALL OFF\""); 19 | shutDownAll(); 20 | } 21 | 22 | void cmdZoneTimedRun(){ 23 | 24 | if ( commandDispatch[CD_OBJ_ID] == 0 || commandDispatch[CD_VALUE_1] == 0 ){ 25 | 26 | String error = "ERROR: cmdZoneTimedRun(), commandDispatch not properly initialized."; 27 | Serial.println(error); 28 | httpJsonReply(error); 29 | return; 30 | } 31 | 32 | // check value is reasonable 33 | if (commandDispatch[CD_VALUE_1] > MAX_RUN_TIME_MINUTES * 60){ 34 | Serial.print("Requested time exceeds max runtime, reseting runtime to: "); 35 | Serial.print(MAX_RUN_TIME_MINUTES); 36 | Serial.println(" minutes"); 37 | commandDispatch[CD_VALUE_1] = MAX_RUN_TIME_MINUTES * 60; 38 | } 39 | 40 | jsonReply += ",\"time\":\""; 41 | jsonReply += commandDispatch[CD_VALUE_1]; 42 | jsonReply += "\""; 43 | 44 | httpJsonReply(jsonReply); 45 | 46 | startTimedRun(commandDispatch[CD_OBJ_ID], commandDispatch[CD_VALUE_1]); 47 | 48 | // clear the command, so we don't re-execute 49 | clearCommandDispatch(); 50 | } 51 | 52 | void cmdGlobalStatusRequest(){ 53 | 54 | // check for running command 55 | if (commandRunning[CR_PIN_ID] > 0){ 56 | jsonStatusRunningZone(); 57 | } else { 58 | jsonReply += "\"system status\":\"ready\""; 59 | } 60 | 61 | httpJsonReply(jsonReply); 62 | 63 | // clear the command, so we don't re-execute 64 | clearCommandDispatch(); 65 | } 66 | 67 | // zone status request, should return: 68 | // zoneX:OFF 69 | // - or - 70 | // zoneX:ON, elapsed:nnnn, remaining:nnn 71 | void cmdZoneStatus(){ 72 | 73 | if (commandDispatch[CD_OBJ_ID] == commandRunning[CR_ZONE_ID]){ 74 | jsonStatusRunningZone(); 75 | } else { 76 | // zone is not active 77 | jsonReply += "\"zone"; 78 | jsonReply += commandDispatch[CD_OBJ_ID]; 79 | jsonReply += "\":\"OFF\""; 80 | 81 | } 82 | // send the response 83 | httpJsonReply(jsonReply); 84 | 85 | // clear the command, so we don't re-execute 86 | clearCommandDispatch(); 87 | } 88 | 89 | void startTimedRun(int zone, unsigned long seconds){ 90 | // deactivate last zone before starting another 91 | endTimedRun(); 92 | 93 | // select pin (shift object id to base zero): 94 | int pin = zones[zone - 1]; 95 | Serial.print("requesting run for zone#: "); 96 | Serial.println(zone); 97 | Serial.print("starting run on pin:"); 98 | Serial.println(pin); 99 | 100 | // turn on selected zone 101 | digitalWrite(pin, HIGH); 102 | 103 | // turn on the LED indicator light 104 | digitalWrite(ledIndicator, HIGH); // set the LED on 105 | ledFlashTimer = millis() + 3000; // set the timer 106 | ledState = HIGH; // set the state 107 | 108 | // set commandRunning parameters 109 | commandRunning[CR_ZONE_ID] = zone; 110 | commandRunning[CR_PIN_ID] = pin; //BUG?: int to unsigned long? 111 | commandRunning[CR_START_TIME] = millis(); 112 | commandRunning[CR_END_TIME] = commandRunning[CR_START_TIME] + (seconds * 1000); 113 | } 114 | /* 115 | Check on timedRuns, stop runs on expiration time 116 | */ 117 | void checkTimedRun(){ 118 | // check for running command 119 | if (commandRunning[CR_END_TIME] > 0){ 120 | // a command is running, check for time end 121 | if (millis() >= commandRunning[CR_END_TIME]){ 122 | // close valve: stop zone X 123 | endTimedRun(); 124 | } else { 125 | // Flash the LED 126 | if (millis() >= ledFlashTimer){ 127 | if (ledState == LOW){ 128 | ledState = HIGH; 129 | } else { 130 | ledState = LOW; 131 | } 132 | // Change the LED state 133 | digitalWrite(ledIndicator, ledState); 134 | 135 | // reset the timer for the next state change 136 | ledFlashTimer = millis() + ledFlashInterval; 137 | } 138 | } 139 | } 140 | } 141 | 142 | void endTimedRun(){ 143 | Serial.print("deactivating zone: "); 144 | Serial.println(commandRunning[CR_PIN_ID]); 145 | 146 | // turn off the pin for the active zone 147 | digitalWrite(commandRunning[CR_PIN_ID], LOW); 148 | 149 | // record the actual end time for reporting 150 | commandRunning[CR_END_TIME] = millis(); 151 | 152 | // turn off the LED indicator 153 | digitalWrite(ledIndicator, LOW); // set the LED off 154 | ledState = LOW; // reset the state 155 | ledFlashTimer = 0; // reset the timer 156 | 157 | if (reportingEnabled){ 158 | // Capture command run data for a report 159 | // all report data is in the commandRunning array. 160 | clearCommandReport(); 161 | 162 | // transfer the commandRunning data into commandReport 163 | for (int i = 0; i < commandReportLength; i++){ 164 | commandReport[i] = commandRunning[i]; 165 | } 166 | // that's all: report will be sent on next loop run 167 | } 168 | 169 | // clear the commandRunning array 170 | clearCommandRunning(); 171 | 172 | } 173 | 174 | boolean exceedsMaxRunTime(){ 175 | if (commandRunning[CD_OBJ_ID] < (millis() + MAX_RUN_TIME)){ 176 | return false; 177 | } 178 | return true; 179 | } 180 | 181 | // shutdown all zones 182 | void shutDownAll(){ 183 | 184 | // check if run is in progress first 185 | if (commandRunning[CR_PIN_ID] != 0){ 186 | // shut down the currently running zone 187 | endTimedRun(); 188 | } 189 | 190 | // cycle through all pins/zones 191 | // for good measure 192 | for (int i = 0; i < zoneCount; i++){ 193 | Serial.print("Writing pin "); 194 | Serial.print(zones[i]); 195 | Serial.println(" LOW"); 196 | 197 | digitalWrite(zones[i], LOW); 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /IrrduinoController/htmlOutput.pde: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // html output functions 16 | 17 | void httpHeader(){ 18 | client.println("HTTP/1.1 200 OK "); 19 | client.println("Content-Type: text/html "); 20 | client.println(); // REQUIRED: must send blank line first 21 | } 22 | 23 | void httpJsonReply(String msg){ 24 | Serial.println("sending httpJsonReply()..."); 25 | httpHeader(); 26 | client.print("{"); 27 | client.print(msg); 28 | client.println("}"); 29 | client.stop(); 30 | } 31 | 32 | void jsonStatusRunningZone(){ 33 | jsonReply += "\"zone"; 34 | jsonReply += commandRunning[CR_ZONE_ID]; 35 | jsonReply += "\":\"ON\""; 36 | jsonReply += ",\"elapsed\":\""; 37 | jsonReply += (millis() - commandRunning[CR_START_TIME]) / 1000; 38 | jsonReply += "\""; 39 | jsonReply += ",\"remaining\":\""; 40 | jsonReply += (commandRunning[CR_END_TIME] - millis()) / 1000; 41 | jsonReply += "\""; 42 | } 43 | 44 | void httpHomePage(){ 45 | Serial.println("sending httpHomePage()..."); 46 | httpHeader(); 47 | 48 | client.println(" "); 49 | client.println(" "); 50 | client.println(" "); 78 | client.println("
"); 79 | client.println("

Run Sprinklers

"); 80 | client.println("
"); 81 | client.println("

Minutes: "); 82 | client.println("

"); 83 | client.println("
"); 84 | client.println("
"); 85 | client.println("
"); 86 | client.println("
"); 87 | client.println("
"); 88 | client.println("
"); 89 | client.println("
"); 90 | client.println("
"); 91 | client.println("
"); 92 | client.println("
"); 93 | client.println("
"); 94 | client.println(" "); 95 | client.stop(); 96 | } 97 | 98 | -------------------------------------------------------------------------------- /IrrduinoController/serverReport.pde: -------------------------------------------------------------------------------- 1 | // This code is adapted by Joe Fernandez from PollingDNS.pde which is: 2 | // 3 | // Copyright (C) 2010 Georg Kaindl 4 | // http://gkaindl.com 5 | // 6 | // This file is part of Arduino EthernetDNS. 7 | // 8 | // EthernetDNS is free software: you can redistribute it and/or modify 9 | // it under the terms of the GNU Lesser General Public License as 10 | // published by the Free Software Foundation, either version 3 of 11 | // the License, or (at your option) any later version. 12 | // 13 | // EthernetDNS is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU Lesser General Public License for more details. 17 | // 18 | // You should have received a copy of the GNU Lesser General Public 19 | // License along with EthernetDNS. If not, see 20 | // . 21 | // 22 | // The code written by Joe Fernandez is: 23 | // 24 | // Copyright 2012 Google Inc. 25 | // 26 | // Licensed under the Apache License, Version 2.0 (the "License"); 27 | // you may not use this file except in compliance with the License. 28 | // You may obtain a copy of the License at 29 | // 30 | // http://www.apache.org/licenses/LICENSE-2.0 31 | // 32 | // Unless required by applicable law or agreed to in writing, software 33 | // distributed under the License is distributed on an "AS IS" BASIS, 34 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 35 | // See the License for the specific language governing permissions and 36 | // limitations under the License. 37 | 38 | const char* ip_to_str(const uint8_t*); 39 | 40 | // TODO: Populate reportData for reporting to IrrduinoServer 41 | // /reports?zone=1&runtime=120"; 42 | void checkAndPostReport(){ 43 | 44 | if (commandReport[CR_ZONE_ID] > 0){ 45 | reportData = "/log?zone="; 46 | reportData += commandReport[CR_ZONE_ID]; 47 | reportData += "&runtime="; 48 | 49 | // calculate runtime in seconds 50 | reportData += (commandReport[CR_END_TIME] - commandReport[CR_START_TIME]) / 1000; 51 | 52 | Serial.println("Run Report parameters set:"); 53 | Serial.println(reportData); 54 | } 55 | 56 | if (reportData != ""){ 57 | // there is report data waiting to be sent 58 | 59 | // make sure we are not sending reports endlessly 60 | if (reportAttempts >= maxReportAttempts) { 61 | reportData = ""; 62 | clearCommandReport(); 63 | reportAttempts = 0; 64 | } else { 65 | reportAttempts++; 66 | } 67 | 68 | 69 | byte ipAddr[4]; 70 | 71 | DNSError err = EthernetDNS.resolveHostName(reportingHostName, ipAddr); 72 | 73 | if (DNSSuccess == err) { 74 | Serial.print("The IP address is: "); 75 | Serial.println(ip_to_str(ipAddr)); 76 | } else if (DNSTimedOut == err) { 77 | Serial.println("Timed out."); 78 | } else if (DNSNotFound == err) { 79 | Serial.println("Does not exist."); 80 | } else { 81 | Serial.print("Failed with error code "); 82 | Serial.print((int)err, DEC); 83 | Serial.println("."); 84 | } 85 | 86 | Client client(ipAddr, reportingHostPort); 87 | 88 | if (client.connect()) { 89 | Serial.print("Sending report data: "); 90 | Serial.println(reportData); 91 | 92 | 93 | client.print("POST "); 94 | client.print(reportData); 95 | client.println(" HTTP/1.1"); 96 | client.print("Host: "); 97 | client.println(reportingHostName); 98 | client.println("Content-length: 0"); 99 | client.println(""); // required to complete the request 100 | 101 | // TODO: check the return message for result 102 | 103 | // empty the reportData and clear the commandReport object 104 | reportData = ""; 105 | clearCommandReport(); 106 | } 107 | else { 108 | Serial.println("connection failed"); 109 | } 110 | 111 | // give the server time to receive the data 112 | delay(20); 113 | client.stop(); 114 | } 115 | } 116 | 117 | // Just a utility function to nicely format an IP address. 118 | const char* ip_to_str(const uint8_t* ipAddr) { 119 | static char buf[16]; 120 | sprintf(buf, "%d.%d.%d.%d\0", ipAddr[0], ipAddr[1], ipAddr[2], ipAddr[3]); 121 | return buf; 122 | } 123 | 124 | 125 | -------------------------------------------------------------------------------- /IrrduinoController/web-ctrl-api.txt: -------------------------------------------------------------------------------- 1 | Here's a quick run-down on the Irrduino controller web API: 2 | 3 | = Get Control main page: 4 | http://irrduinoctrl.org/ 5 | 6 | = Turn off everything (all zones): 7 | http://irrduinoctrl.org/off 8 | returns: {"zones":"ALL OFF"} 9 | 10 | = Get Global system status (whole system) 11 | http://irrduinoctrl.org/status 12 | returns: {"system status":"ready"} 13 | - or: if a zone is running: 14 | returns: 15 | {"zone1":"ON", // zone is on 16 | "elapsed":"4", // seconds elapsed in run 17 | "remaining":"235"} // seconds remaining for run 18 | 19 | = Get per-zone status 20 | http://irrduinoctrl.org/zone1 21 | http://irrduinoctrl.org/zone1/status 22 | returns: 23 | {"zone1":"OFF"} 24 | - or - 25 | {"zone1":"ON", // zone is on 26 | "elapsed":"4", // seconds elapsed in run 27 | "remaining":"235"} // seconds remaining for run 28 | 29 | = Activate Zones: (syntax: zone[1-9]/on/[1-10][s]) zone X, ON for N minutes, 30 | or N seconds (with "s" suffix) 31 | http://irrduinoctrl.org/zone1/on/1 32 | http://irrduinoctrl.org/zone1/on/60s 33 | returns: 34 | {"zone1":"ON", // value status 35 | "time":"60"} // run time in seconds 36 | 37 | = Set Controller Settings (syntax: /settings?label1=value1&label2=value2&label3=value3 ) 38 | http://irrduinoctrl.org/settings?re=true&rhn=my.server.com 39 | parameters 40 | reportingHostName=my.server.com (short form: rhn=my.server.com ) default value = NULL 41 | reportingHostPort=80 (short form: rhp=80 ) default value = 80 42 | reportingEnabled=true|false (short form: re=true|false ) default value = false 43 | 44 | = Get Controller Settings (syntax: /settings (no parameters)) 45 | http://irrduinoctrl.org/settings 46 | returns: 47 | {"reportingEnabled":"true", 48 | "reportingHostName":"my.server.com", 49 | "reportingHostPort":"80"} 50 | 51 | = Provoke a report call (for testing only) 52 | http://irrduinoctrl.org/testreport/irrduinoserver.org:8080/datadrop?what=1&ever=2&you=3&want=4 53 | makes the following http request: 54 | http://irrduinoserver.org:8080/datadrop?what=1&ever=2&you=3&want=4 -------------------------------------------------------------------------------- /IrrduinoDroid/IrrduinoRemote/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /IrrduinoDroid/IrrduinoRemote/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | IrrduinoDroid 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /IrrduinoDroid/IrrduinoRemote/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Wed Nov 02 17:08:12 PDT 2011 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 4 | org.eclipse.jdt.core.compiler.compliance=1.5 5 | org.eclipse.jdt.core.compiler.source=1.5 6 | -------------------------------------------------------------------------------- /IrrduinoDroid/IrrduinoRemote/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 16 | 17 | 20 | 21 | 22 | 23 | 24 | 25 | 28 | 29 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /IrrduinoDroid/IrrduinoRemote/assets/grass-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/irrduino/cd6ab315a8a08efa69eb13829d58ea0a116069dd/IrrduinoDroid/IrrduinoRemote/assets/grass-icon.png -------------------------------------------------------------------------------- /IrrduinoDroid/IrrduinoRemote/proguard.cfg: -------------------------------------------------------------------------------- 1 | -optimizationpasses 5 2 | -dontusemixedcaseclassnames 3 | -dontskipnonpubliclibraryclasses 4 | -dontpreverify 5 | -verbose 6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 7 | 8 | -keep public class * extends android.app.Activity 9 | -keep public class * extends android.app.Application 10 | -keep public class * extends android.app.Service 11 | -keep public class * extends android.content.BroadcastReceiver 12 | -keep public class * extends android.content.ContentProvider 13 | -keep public class * extends android.app.backup.BackupAgentHelper 14 | -keep public class * extends android.preference.Preference 15 | -keep public class com.android.vending.licensing.ILicensingService 16 | 17 | -keepclasseswithmembernames class * { 18 | native ; 19 | } 20 | 21 | -keepclasseswithmembers class * { 22 | public (android.content.Context, android.util.AttributeSet); 23 | } 24 | 25 | -keepclasseswithmembers class * { 26 | public (android.content.Context, android.util.AttributeSet, int); 27 | } 28 | 29 | -keepclassmembers class * extends android.app.Activity { 30 | public void *(android.view.View); 31 | } 32 | 33 | -keepclassmembers enum * { 34 | public static **[] values(); 35 | public static ** valueOf(java.lang.String); 36 | } 37 | 38 | -keep class * implements android.os.Parcelable { 39 | public static final android.os.Parcelable$Creator *; 40 | } 41 | -------------------------------------------------------------------------------- /IrrduinoDroid/IrrduinoRemote/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system use, 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | 10 | # Project target. 11 | target=Google Inc.:Google APIs:14 12 | -------------------------------------------------------------------------------- /IrrduinoDroid/IrrduinoRemote/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/irrduino/cd6ab315a8a08efa69eb13829d58ea0a116069dd/IrrduinoDroid/IrrduinoRemote/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /IrrduinoDroid/IrrduinoRemote/res/drawable-ldpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/irrduino/cd6ab315a8a08efa69eb13829d58ea0a116069dd/IrrduinoDroid/IrrduinoRemote/res/drawable-ldpi/ic_launcher.png -------------------------------------------------------------------------------- /IrrduinoDroid/IrrduinoRemote/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/irrduino/cd6ab315a8a08efa69eb13829d58ea0a116069dd/IrrduinoDroid/IrrduinoRemote/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /IrrduinoDroid/IrrduinoRemote/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/irrduino/cd6ab315a8a08efa69eb13829d58ea0a116069dd/IrrduinoDroid/IrrduinoRemote/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /IrrduinoDroid/IrrduinoRemote/res/drawable/grass_and_sky_background_portrait.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/irrduino/cd6ab315a8a08efa69eb13829d58ea0a116069dd/IrrduinoDroid/IrrduinoRemote/res/drawable/grass_and_sky_background_portrait.png -------------------------------------------------------------------------------- /IrrduinoDroid/IrrduinoRemote/res/drawable/ic_menu_report.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/irrduino/cd6ab315a8a08efa69eb13829d58ea0a116069dd/IrrduinoDroid/IrrduinoRemote/res/drawable/ic_menu_report.png -------------------------------------------------------------------------------- /IrrduinoDroid/IrrduinoRemote/res/drawable/ic_menu_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/irrduino/cd6ab315a8a08efa69eb13829d58ea0a116069dd/IrrduinoDroid/IrrduinoRemote/res/drawable/ic_menu_settings.png -------------------------------------------------------------------------------- /IrrduinoDroid/IrrduinoRemote/res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 15 | 16 | 23 | 24 | 33 | 34 |