Best way to format data for sending through cloud

I need to send different sensor reading values to web app and smart phone app. There could be multiple temperature, humidity,and light sensors. I plan to save 5 minute intervals. I hope the Photon can store at least 7-days worth of data. The phone app will need to read day of data to plot in chart. Web app will have Photon sending data every 15 minutes or read days at a time.
One way is send data comma delimiter:
SensorName,Start Date and Time, Data1,Data2,Data3…
SensorName,Date and Time, Data1
SensorName,Date and Time, Data2
SensorName,Date and Time, Data3

Also how should the data be represented in Photons memory?

Thanks for all help

I’d create a struct that contains all the fields making up one data point and have an array of these struct entities.
The strings should be fixed length char[], DateTime should be uint32_t as you’d get from Time.local() and Data is up to you :wink:

The “sending through cloud” bit greatly depends on your intended way to send. There are multiple ways and even more to receive them on the other end that will dictate how you format the data.

If you want to store 2016 x number of sensor reading locally, I’d recommend adding an SD card or other non-volatile storage.

1 Like

A customer just turned me on to today. Perhaps that’ll work for you application?


My plan is not to create a separate data storage for each sensor. Instead, I will have data storage pools by interval readings:
1 minute, 15 minutes, and 60 minutes.

For example for the 1-minute pool. I will create a FIFO of a certain size like 1K. I will push all 1-minute interval sensor data into this one pool. Each data point will contain sensor ID, sensor type, and the data. The sensor pool will start with interval point followed with sensor data. Something like this:

What do you all think?

That should work however you are essentially “re-inventing” a serialization format (like JSON or the msgpack thing I posted). Not a terrible idea but you just end up spending a lot of time on something that may or may not be worth your time. It really depends on what you want to spend your time doing: do you want to move on to the next part of your project quicker or do you want to squeeze out every bit of missed-effeciency writing (and debugging!) a serialization process? As someone who has done the later I recommend the former.

Can the Photon take a data structure and convert it to JSON for transmission over Cloud? Or do I need to build the JSON string manually from data structure?
Thanks again

You’ll need to build it yourself. I believe there’s a JSON library in the WebIDE. Let me know if you can’t find it.