Inconsistent ThingSpeak Data Logging – Missing Entries & Timing Issues
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
randomnick
le 14 Mar 2025
Modifié(e) : Christopher Stapels
le 18 Mar 2025
Hi, I am reading data from one ThingSpeak channel with three fields: Voltage, Frequency, and Wi-Fi Signal Strength, which update every minute. My setup reads these values, processes the data, and writes the results to another channel. However, I am facing several issues with inconsistent updates and missing entries. I read 30 data points every 30 minutes and write the processed results to my channel.
Two of the analyses are slightly more complex than the other six fields:
- One analysis takes 30 input values and outputs a single result to Field 5 in the last minute.
- Another analysis takes the last 31 inputs and processes them into 30 outputs for Field 8 using the diff() function.
- The update works correctly for 29 entries across 7 fields, but in the last minute, only Field 5 gets updated while the other fields do not.
- Sometimes, when I try to save and run the code, I encounter errors, but other times it runs fine, eventhough the code is the same.
- The time control is set to update every 30 minutes, but I notice that it sometimes updates only once an hour or stops for several hours before resuming.
Why does the last-minute update affect only Field 5 while the other fields are not updated? What could be causing some errors when saving and running the code? Why does the scheduled update sometimes not execute properly because of my analysis code and instead update and stopped at irregular intervals?
My suspect is my code is not well formed, and sometimes the code executed too fast, thingspeak is unable to handle too much writing. FYI, I am using free license, my daily usage rate is less than 2000 messages. Any insights or suggestions would be greatly appreciated. Thank you!
I am attaching some parts of my code, and the data exported from my channel. As of now I am writing this question, the entries seems to work properly for now since the last save and running the code, updating 31 entries, 30 entries for the other fields, 1 entry for field 5. My channel id is 2862014 if you need it.
readChId = XXX;
writeChId = XXX; % Replace with your channel number
writeKey = 'XXX'; % Replace with your channel write key
% Read data from ThingSpeak (last 30 data points)
[frequency,time] = thingSpeakRead(readChId,'Fields',1,'NumPoints',30);
voltage = thingSpeakRead(readChId,'Fields',2,'NumPoints',30);
wifiStrength = thingSpeakRead(readChId,'Fields',3,'NumPoints',30);
freq_drift = thingSpeakRead(readChId,'Fields',1,'NumPoints',31);
% Calculate voltage fluctuation index (percentage variation from mean)
% Field 5
voltage_fluctuation_index = (max(voltage) - min(voltage)) / mean(voltage) * 100;
% Field 8
freq_diff = diff(freq_drift);
thingSpeakWrite(writeChId,[voltage,frequency,wifiStrength,voltage_fluctuation,frequencyStability,wifiSNR,freq_diff],'Fields',[1,2,3,4,6,7,8],'TimeStamps',time,'WriteKey',writeKey);
thingSpeakWrite(writeChId,'Values',[voltage_fluctuation_index],'Fields',[5],'writekey',writeKey);




0 commentaires
Réponse acceptée
Christopher Stapels
le 14 Mar 2025
Modifié(e) : Christopher Stapels
le 18 Mar 2025
You need a delay between the two writes. Even with a paid license, you can update a channel no faster than once per second. This includes updating any fields in the channel. I suggest trying the pause(1) command, or a while loop counting to a high number. The fact that has worked several times is just luck. It might be possible to combine both write commands into a single command as well.
0 commentaires
Plus de réponses (0)
Communautés
Plus de réponses dans ThingSpeak Community
Voir également
Catégories
En savoir plus sur Prepare and Analyze Data dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!