Notes on Gateway Main Loop:
Driven by two Alarms on the Real-Time Clock. Each alarm emits an electrical interrupt that wakes up the microcontroller. The main loop then evaluates what to do depending on which alarm went off and at what time.
Alarm 1 controls communication with the nodes. Alarm 2 controls cellular communications.
Both alarms initiate a check on the battery voltage. If the voltage is below 3.4 V, the gateway will go back to sleep to preserve power.
The gateway attempts to synchronize with the nodes before entering the main loop (in the setup section of the code which executes only once on startup). If the battery voltage is low it will skip trying to synchronize with the nodes but will save a flag to indicate that it did so. The main loop checks that flag to initiate a synchronization if it hasn’t been done yet.
Notes on Gateway fieldSync Function:
The node also has a fieldSync function that is the compliment to the gateway’s function, but does not have the same flow.
The gateway synchronizes with nodes by sending them with a timestamp which the node will update its clock to when received.
Notes on Node Main Loop:
Driven by two Alarms on the Real-Time Clock. Each alarm emits an electrical interrupt that wakes up the microcontroller. The main loop then evaluates what to do depending on which alarm went off, at what time, and under which conditions (scenarios listed below).
Alarm 1 controls data collection and transfer (if using a gateway). Alarm 2 only executes if a gateway is in use and performs a daily sync check with the gateway.
The node attempts to synchronize with the gateway before entering the main loop (in the setup section of the code which executes only once on startup). If the battery voltage is low it will skip trying to synchronize with the gateway but will save a flag to indicate that it did so. The main loop checks that flag to initiate a synchronization if it hasn’t been done yet.
The node main loop evaluates what to do based on four scenarios:
Scenario #1: No RH sensor, no gateway
Scenario #2: RH sensor, no gateway
Scenario #3: RH sensor, gateway
Scenario #4: No RH sensor, gateway
PSA nodes currently only use scenarios 1 or 4. The presence of an RH sensor is a legacy variable for PSA but was kept in the code in case they are ever used again in the future. The RH sensor had a heater that needed to be turned on for three minutes to burn off condensation from the sensor and then left off for three minutes before taking a measurement to avoid biasing the temperature reading.
0 Comments