Hello Particle friends.
I am building a device with a Photon as the MCP and moisture sensors. Very simple. I want to put it in a location where it is likely it will go for multiple days without internet connectivity. I have code in place that logs to the cloud and it works fine, but as soon as it disconnects, it will stop logging (as it stands).
Based on what it is for (gardening - soil moisture to be exact) and the data it collects (a timestamp and a voltage reading from up to 6 sensors), I believe my simplest answer is to store the data in array if Particle.connected() returns false. I have looked all over the internet and the forum for answers but most people appear to want to store LOTS of data points. I will check the readings at most 2x per day (could even go to 1 TBH, but 2 is better) so if I am offline for even 72 hours, I would have 6 timestamps and worst case 36 4-digit voltage readings (it ignores disconnected sensors) - even with formatting it would be under 512kb at worst (ish). Oh and I very much want to avoid SD cards and all that as I already have PCBs and want this prototype to be simpler than all that would entail.
So all that said, the root of the question is: I believe that I shouldnât overrun the memory on the photon with that little amount of data, but I cannot for the life of me figure out the way to store the data itself in C code. I have spent HOURS searching Stack, Google, here, and other sites for a simple âdynamic arraysâ type tutorial, but none of them are quite what I am looking for (I know very little C/C++ - I am a Python primary) so I figured I would ask here as there is no way I am the only one whoâs done this?
Example of one of the reading blocks from my code:
// Check the value of the probe - if > 4000 probe not connected so skip reading it
if (SMVolts1 < 4000) {
String voltage = "Voltage " + String(SMVolts1);
String publishdata = timestamp + " " + voltage;
if (Particle.connected()) {
Particle.publish("S1_Reading_Data", publishdata, PRIVATE);
}
else {
INSERT CODE HERE THAT STORES THIS READING INTO AN ARRAY THAT IS DYNAMIC
}
}
delay(1000);
In the final production version I will most likely reverse the loops you see here so that it checks connectivity first, THEN takes the reading or not. That way i can store a ânot connectedâ or something like it for missing probes. Does not change the âI need to store it in an arrayâ part of the equation though.
Thanks in advance.