tuanpmt / esp_mqtt

MQTT client library for ESP8266
http://tuanpm.net/post/esp_mqtt/
MIT License
1.14k stars 400 forks source link

Queue on Flash memory #123

Closed asadislam94 closed 7 years ago

asadislam94 commented 7 years ago

Is it possible to create the queue on flash memory to make sure we still have data during power failure?

tuanpmt commented 7 years ago

Maybe we can use a large portion of flash to do this by writing circle small data.

someburner commented 7 years ago

IMO this wouldn't really help anything. The only reason your buffer should be full is if WiFi is disconnected, not a power failure. Since I assume you can't predict when the failure occurs, it could happen at any random point, like during the middle of a flash read/write operation and then you would potentially be sending corrupt data. Unless you mean a power failure that affects your AP but not your ESP?

asadislam94 commented 7 years ago

There can be a situation where a power failure occurs to ESP during a network outage. If this instance occurs then you may want to keep the important publish data saved for when the device turns back on.

However I just realized that this doesn't need to be implemented on the queue. We can just keep the "important data" in flash and send it using QoS=2. If the data is sent correctly it can be deleted otherwise on boot-up we can have a check to see any data on flash and send it.