Best Practice for Offline Data Logging + Sync

Hello, need help with best practice for data logging (or persistence in database terms) if device goes or is used offline (no Internet connection.) I am thinking of using something like a serial logging SD card and storing in CSV, but the issue of timestamps, lots of special logging code, and then syncing with existing data stored comes up. I was wondering if anyone has worked out a kind of transparent persistence model for Blynk that uses Blynk.virtualWrite and sync with RTC so that data values, along with their timestamps, are stored locally. Then, when connection is restored, a sync will upload locally stored data and sync with the server. Sort of a reverse Blynk sync function, from device to server. Appreciate any thoughts to help me get started.

The API is currently the only way to upload data that has been collected whilst offline…

https://docs.blynk.io/en/blynk.cloud/upload-set-of-data-with-timestamps-api

Pete.

Pete, thanks much. This will help once the device is back online, but still not clear on how to efficiently persist data when offline. I suppose I could store data in a form that could be simply passed to the API when connection is resumed. This occurs more often than you might think…many such IOT devices are used on and off line, for example when WiFi or GSM is not available, but sensor data is still being collected. The real challenge is how to ensure the offline and online timestamps are congruent when “synced up” since my final datastore is Thingspeak where the data is timestamped as it is loaded there, not in the device code.

A lot depends on your hardware, how frequently you are taking readings (there’s no point in storing more then one reading per minute in most scenarios) and how long you expect the offline periods to last.

I’d probably use an ESP8266 or ESP32 and store the data in NVRAM using SPIFFS or LittleFS.

I see in the documentation that there is a new function called Blynk.beginGroup() which accepts a timestamp, so may be an alternative to the API…

https://docs.blynk.io/en/blynk.edgent-firmware-api/virtual-pins#blynk.begingroup-blynk.endgroup

Pete.

1 Like

Pete, thanks. Pursuing the logging to SDcard with RTC, then reading back to buffer and sending to cloud using the Blynk.beginGroup() as you have suggested. Still unsolved is how to then sync this “offline” data with the data that has been previously uploaded while Blynk is online…this is a problem as the timestamped data will be a bit out of sync when this new data is added.

I don’t understand.

Pete.

hello drew, i am facing the same problem of you. did find a way to synchronize the offline data with their time