Gearing up a Monitor One for field use and with battery life a somewhat unknown, I’d like to sleep before making a measurement of a modbus device. I’m using a custom user_modbus.cpp file that uses the Console Ledger in lieu of the configuration schema (3 calls just wasn’t enough). I’d like to poll this modbus device every hour, Publish those results, go to sleep, and wake again a minute or so before the next reading.
In the modbus loop:
<builds JSON file>
resultsToPublish.clear();
if (Particle.connected())
Particle.publish("topic",publish1);
EdgeSleep::instance().wakeAtSeconds(looptick+3540);
However, this doesn’t cause the Monitor One to wake up 59 minutes later.
Any pointers on how to get this working? And bonus points for a more robust (queued?) Publish method.
One way to solve this problem is to use the normal scheduled wake feature. In the location settings set the minimum location update frequency to 1 hour so the device will wake every hour.
Use the regLocGenCallback to register a function to be called when the device wakes. You can read the modbus sensor from this callback and write it to the ledger. You can also add it to the location publish, if desired.
If you want to continue to use the code you already have, what are you setting loopTick to?
I have used the location settings to set a wakeup time, but I wasn’t getting desired behavior. I am using nearly identical structure as user_modbus.cpp, aka creating a thread, and setting loopTick to System.uptime() at the beginning of the modbusThreadLoop. The only difference is that I’m using the Ledger to specify the MODBUS registers, data types, etc and publishing a JSON object at the end of these MODBUS calls. If sleep is not enabled, I get regular modbus polling and publishings.
So, I guess I need clarification. In the default Monitor Edge firmware, you can specify 3 modbus registers to be read. Each has a polling interval.
So how does this polling interval relate to the location publish interval and how does that relate to the sleep behavior if enabled? As I mentioned in the first post, the goal is regular modbus polling and publishing with sleep between those polls. I’m not sure how to get there.
The modbus settings don't interact with sleep mode or location publishing at all. The modbus thread only runs when awake (of course) and maintains its own timing, which is independent of the location publish timing, and it uses its own event, separate from loc events, so it will never wake the device.
The code you have should work, assuming looptick is set correctly. I'd run some more testing, like trying wakeAtMilliseconds relative to System.millis(). Also check the result code of wakeAtSeconds to make sure an error isn't returned.