Why does thingSpeakRead() using numPoints > 100 not always select the latest data?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
When I use a value of n greater than 100, my data is read in a fuzzy way, so the most recent data point is not always selcted.
I'm using Apps-React to trigger an Apps MatLab Analysis custom code block.
The architecture is my 'Thing' posts to Channel 1 every 30 seconds. React is triggered by Channel 1 posting. Matlab writes an instruction to 'Control' channel 2. 'Thing' responds to channel 2. Repeat...
I use MATLAB to read Channel 1 and also Channel 2 in order to know its most recent instructions.
The long standing issue I have is with MatLab command thingSpeakRead()
The problem is ctrlTimestamps(last row) is not consistent, in fact the returned dataset depends upon the number of NumPoints.
Here is my test program to prove what happens when I use 101 data points. Yes it returns 101 points BUT the timestamps (posted to status column) are only sometimes in sequence!
% Test to see what value of n causes incorrect read of data
n=101;
%
% Read Input from sensors
%
readAPIKey = '***';
readChannelID = 1229509;
% Read raw data channel and map meaningful fields to the raw.
[data,timestamps] = thingSpeakRead(readChannelID,'Fields',[1,2,3,4,5,6], ...
'numPoints',(n),'ReadKey',readAPIKey);
% display(data,'Sensor data')
% display(timestamps,'Timestamps')
rowCountIn = size(data,1);
display(rowCountIn,'Row count for Input ch ')
%
% Read CONTROL channel for previous settings
%
readAPIKey = '***';
readChannelID = 1355058;
% Read raw data channel and map meaningful fields to the raw.
[ctrlData,ctrlTimestamps] = thingSpeakRead(readChannelID,'Fields',[1,2,3,4,5,6,7,8], ...
'NumPoints',(n),'ReadKey',readAPIKey);
% display(ctrlData,'Control data')
% display(ctrlTimestamps,'Control timestamps')
%
rowCount = size(ctrlData,1);
display(rowCount,'Row count of CONTROL ch ')
statusUpdate = strcat(' Ctrl time: ',datestr(ctrlTimestamps(rowCount),' HH:MM:SS'));
%
% Output to CONTROL channel
%
display (statusUpdate);
writeAPIKey = '***';
webwrite('http://api.thingspeak.com/update','api_key',writeAPIKey,'field1',0,'field2',0,'field3',0,'field4',0,'field5',0,'status',statusUpdate);
%
%
% ----------------END OF PROGRAM ------------
%
Ver -support is: ------ MATLAB Version: 9.13.0.2085925 (R2022b) Update 1 MATLAB License Number: 0 Operating System: Linux 5.4.209-0504209-generic #202208031145 SMP Wed Aug 3 12:39:06 UTC 2022 x86_64 Java Version: Java 1.8.0_292-b10 with AdoptOpenJDK OpenJDK 64-Bit Server VM mixed mode ---------------------------------------------------------------------------------------------------- MATLAB Version 9.13 (R2022b) License 0
----
3 Commenti
Christopher Stapels
il 29 Nov 2022
Modificato: Christopher Stapels
il 5 Dic 2022
Thanks for the evidence. I can't think of any reason why numbers greater than 100 would change the time recorded by the system when you ingest data. It is possible that the statistical fluctuations in your device posting time get significant when n=100 but I dont think it would be deterministic.
If you want to determine the timestamps exactly, you can use the 'created-at' parameter from your device and write its internal time (assuming the device has a clock).
Consider the following test: you can use ThingSpeakWrite to write 101 points exactly every 30 seconds. Then you would be guaranteed to not have the time lag problem since your points are exactly 30 seconds apart. This seems to prove that is does not have anything to do witht the read command, and it is due to fluctuations in your device writing time. Or I admit I do not understand the issue too well.
There are some pretty weird rules about how reacts are scheduled to be taken care of by the job scheduler - that may also be a part of the issue. I hope you get your process worked out!
Risposte (0)
Community
Più risposte nel ThingSpeak Community
Vedere anche
Categorie
Scopri di più su Visualize Data in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!