MQTT sync after reboot

Hi Guys,

I am busy withe a project using a NodeMcu and therefore I am using the MQTT. I would like to know if, and how there is a way to sync dashboard values when the device comes online after a reboot.
for example: if I have set pin D1 high with a button widget and there is a power failure, when the power comes back on D1 is still set high on the dashboard but the pin on the physical board is still off. I would like the board to fetch values from the dashboard upon connection as it is done here with the ethernet version:

Thanks in advance!

look at this ESP8266 : using syncAll() function

1 Like

Thanks, I did see that but restoring from dashboard would be optimal as if a scheduled event happens when the device is powered off and it reads from EEPROM, the scheduled event will not have any effect.

@devjardim can you elabrate a bit more about it.

I will indicate the problem of storing in the eeprom with an example:

12:01 State of pin 1 is set high
12:01 State of Pin 1 is set high in eeprom
12:03 Power failure
12:05 Scheduled time to switch Pin 1 to low
12:07 Power is restored
12:07 Device reads from eeprom storage and pin 1 is set high

This is a problem as any scheduled events that happen when the power is off are ignored. What would solve this issue is if every time the board connects to the cayenne dashboard all pin states are synced with the values on the dashboard.

@devjardim great point. i will transfer this with cayenne team and see if there is an solution.

Some test have made but fell a little to oblivion :wink:
@rsiegel: ESP8266 : using syncAll() function
And :

Thank you very much. It is essential to my project for this to work.

@SuperNinja this is a bit different. if there is a schedule at 2 pm and during this time the device is off so this will cause loss of data.

1 Like

I find it quite strange that there already is a Cayenne.syncAll() function that works with the ethernet shields but not with the wifi boards.
From what I have read, blynk has been able to do this with their equivalent Blynk.syncAll() function and it works with the wifi board.

I have thought we need a device reboot/reset library to update the device not just with the current values of on/off and sliders with the Cayenne->device data, but also to update the device on the current state of the device->Cayenne data that is normally delivered with mqtt. The current values of sensors are available to the device, but if the device is doing accumulations or has some “state”, but the device does not have a harddrive or permanent memory. For example, a rebooted device has no memory of the machine – that the device is keeping track off and reporting to Cayenne – is on or off, or starting, etc. So the device could query Cayenne to find the last state of things, and then update the device memory and programs to continue from that starting place.

The option of using the 8266 EPROM for this is not ideal in my opinion, as the 8266 would need to update the EPROM every 15 seconds or more, which would take time and battery power, and quickly run through the 100,000 update lifetime of the EPROM. Cayenne has the big expensive database with all that data available to query and reset the device to last known good status.

This is like a reverse mqtt, which does not exist, but the REST API could fetch the data and reset the device. So that is my next project.


While using the REST API, I have plans to update our MQTT API to allow that to stick to a single protocol library and limit the footprint.

1 Like