High Level Summary of Firmware
The precipiSTATION firmware uses:
The firmware is not "architected-in-advance". It has grown organically over the last couple years using time as it was available. It is broken down into many small and hopefully understandable functions, and each function has potentially too verbose commented documentation in the firmware. It uses many global variables (generally a bad idea but they work here because the program is small enough, and I was too lazy to get rid of them), and has not been segmented into separately tabbed libraries, just one small loop() program calling many functions, all in one file. The code and documentation probably do not exactly match standard coding/documentation syntax as I am not a professional programmer. There are probably C or C++ libraries that I am not aware of that will do some of the functions I did by hand.
Execution-wise, in loop(), it repeatedly calls functions to check the status and manage execution of stored sprinkler programs, manage running a specific station once, manage running a sprinkler test, and random housekeeping.
The Android app or web page app communicates with the precipiSTATION using Particle Functions and Particle Variables. Custom message formats were created to send/receive data to/from the precipiSTATION (detailed descriptions of these formats are embedded in the firmware, using prose summaries above each function and line by line comments in the functions. Details can be seen here).
The main Particle Variables include:
A remote app does Particle POSTs to manage the precipiSTATION, and Particle GETs to verify operation and status, to get already stored data like station names, programs names, and program run time data. The Android or web app is one part a display formatting application that enables easy viewing of sprinkler status and parameters, one part a data entry console for inputting program and sprinkler operation parameters, and one quarter a communication handler to send to and get replies from the precipiSTATION. It relies on the precipiSTATION to store state, synchronizing with the Sprinkler at app startup, and after every communication (does not use cloud for storage).
While it is noted in the firmware comments, an important point about the firmware versus PCB layout is that the solenoids are turned on/off using a 16 bit variable "stationBitPosition" which is shifted out to the two 74HC595 shift registers. The mapping of the bits of this variable are as follows:
The precipiSTATION firmware uses:
- 4 main run time functions called from loop()
- 4 Particle Functions to receive Strings of data and commands from an Android app or web page app (iOS under development)
- 5 Particle Variables to reflect information back to the Android app
- Several Publish blocks to allow access of status via Publish/Subscribe
- Twitter functions to tweet sprinkler status
The firmware is not "architected-in-advance". It has grown organically over the last couple years using time as it was available. It is broken down into many small and hopefully understandable functions, and each function has potentially too verbose commented documentation in the firmware. It uses many global variables (generally a bad idea but they work here because the program is small enough, and I was too lazy to get rid of them), and has not been segmented into separately tabbed libraries, just one small loop() program calling many functions, all in one file. The code and documentation probably do not exactly match standard coding/documentation syntax as I am not a professional programmer. There are probably C or C++ libraries that I am not aware of that will do some of the functions I did by hand.
Execution-wise, in loop(), it repeatedly calls functions to check the status and manage execution of stored sprinkler programs, manage running a specific station once, manage running a sprinkler test, and random housekeeping.
The Android app or web page app communicates with the precipiSTATION using Particle Functions and Particle Variables. Custom message formats were created to send/receive data to/from the precipiSTATION (detailed descriptions of these formats are embedded in the firmware, using prose summaries above each function and line by line comments in the functions. Details can be seen here).
- The saveData(String x) Particle function receives strings from the Android app and stores the data in EEPROM, and sets control flags for sprinkler operation.
- The fetchData(String x) Particle function extracts data from EEPROM and firmware flags, assembling that data into Particle variables that the remote app can then query. It also handles the System On and Off commands.
- The runOnce(String x) Particle function stores station and program run time data to flash EEPROM and sets flags to run a station, program or sprinkler test.
- The setTwitter(String x) simply sets a Twitter enable/disable setting.
The main Particle Variables include:
- pgmList[], a CSV String of all program names
- stnList[], a CSV string of all station names
- pgmData[], a CSV string of data for a specific program
- statusData[], a CSV string holding a variety of status data
- TwitOnOff, an integer showing current Twitter enable/disable status, and sprinkler On/Off status
A remote app does Particle POSTs to manage the precipiSTATION, and Particle GETs to verify operation and status, to get already stored data like station names, programs names, and program run time data. The Android or web app is one part a display formatting application that enables easy viewing of sprinkler status and parameters, one part a data entry console for inputting program and sprinkler operation parameters, and one quarter a communication handler to send to and get replies from the precipiSTATION. It relies on the precipiSTATION to store state, synchronizing with the Sprinkler at app startup, and after every communication (does not use cloud for storage).
While it is noted in the firmware comments, an important point about the firmware versus PCB layout is that the solenoids are turned on/off using a 16 bit variable "stationBitPosition" which is shifted out to the two 74HC595 shift registers. The mapping of the bits of this variable are as follows:
Bit Position
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Sprinkler Channel
9 10 11 12 13 14 15 16 1 2 3 4 5 6 7 8 |
A downloadable file is at the bottom - it is a .ino Arduino. It has no twitter token in line 147 but has links on how to get one. It is hard-coded for Pacific DST in line 217. It does DST using an array of US dates through 2025 (a better solution than this is needed, both on calculating DST anywhere in the world, and making it easier to change time zones from mobile or web apps).
Open this file in the editor of your choice and copy it to the Particle online IDE, or use the Particle Dev IDE and flash it to your Photon.
You can use the web site www.atomiot.com as a console to play with it though you will be putting your API Token and Core ID onto that site. Or you can follow the steps in the Android app section to create an Android app to play with it.
Open this file in the editor of your choice and copy it to the Particle online IDE, or use the Particle Dev IDE and flash it to your Photon.
You can use the web site www.atomiot.com as a console to play with it though you will be putting your API Token and Core ID onto that site. Or you can follow the steps in the Android app section to create an Android app to play with it.
![](http://www.weebly.com/weebly/images/file_icons/file.png)
pstnpublic_14aug2016.ino | |
File Size: | 126 kb |
File Type: | ino |