I have been using IoT Cloud for a few days now, and the simplicity and ease-of-use for the basics has been great. The ability to share dashboards (and only dashboards so that my family don't mess up my stuff) is great. I moved over from Blynk.
However, I want to see if I can push the limit a bit now, and would like some advice/guidance/idea-bouncing. I've done quite a bit of reading etc. and it's not 100% clear to me if/what the best approach is.
Consider the intro Temp/Humidity Sketch. This results in showing the real-time values on Gauge widgets, and the usual historic data (1h, 1d etc.) on the Chart widget.
But, I would like to display on the same Dashboard (using a Value widget?), the average values of some of those entities e.g. Avg Temp today, Avg Temp Yesterday, perhaps Max Temp so far this month?
I don't want to have to download the historic data for variables, and then process it in another application to display elsewhere. e.g. the dreaded excel way
My thoughts are leaning towards using the Application API calling once every few minutes to grab the data, within the sketch somehow, and then process that into a dummy variable that I can link to the relevant Value widget.
Don't need any code solutions etc. just want to know if I am barking up the wrong tree in terms of approach/functionality or if what I would like to do is even possible.
You have the data to start with, so no need to call the API to extract some historical information you were the one to provide in the first place...
for example if you want a daily average for yesterday, may be hour by hour to be on the display, maintain that on the clients side throughout the day (keep the sum of the samples and number of samples) and make it a shared variable with the dashboard then you can show Yesterday's average at the same time (hour interval) and today's value next to each other
I was wondering about that, I'm running an ESP32 with the DHT11 sensor on it (Testing for bigger future things). So I gave some thought about creating container variables that I can then use to do math on, to get what I need but I was concerned as to just how much data I can 'keep' or how much it might affect processing over time.
OK, think I have a handle on this - going use LittleFS to write to a file on the ESP to collect the data, and then do the math from that. Didn't know about LittleFS, always good to learn something new
you can indeed use the flash memory to store data, it's larger than the RAM you have available. It all depends on how much samples you want to collect and what you want to do with them. as I said to keep an hourly average for the day you can create a small structure
struct HourlyAverage {
long samplesSum; // adjust the type for your data
unsigned long samplesCount; // number of Samples making up that count
};
HourlyAverage yesterday[24], today[24];
and every time you acquire a new sample add the value to samplesSum and increment samplesCount by 1 in the right bucket based on the current hour of the day
when you want the average for a given hour h, you just divide
long average = yesterday[h].samplesSum / yesterday[h].samplesCount;
and at the end of the day you copy over the data from today into yesterday to start afresh
for (size_t h=0; h<23; h++) yesterday[h] = today[h]; // or just use memcpy()
the struct uses 8 bytes, so yesterday and today total size is 24 x 8 x 2 = 384 bytes. That's not a lot for an ESP32