Field Chart :problem with "sum" function
Afficher commentaires plus anciens
I want to sum up the inputs of a field varible (1 value /min) from 00:00a.m. until12:00p.m. (24 hours) and then store it as "previous day" value.
It works fine during the day, but the value at 12p.m. is not completly stored ( only 20 ...35% of the totalized value) as previous day value.
It works perfectly for hourly sums (60 data points).
Is there a limit of max. data points? one day = 1440 data points
I use the follwing parameters:
type: column
dynamic: true
days: 10
Sum: daily
Are these the right parameters?
Many thanks in advance for support
8 commentaires
Adam Danz
le 17 Fév 2020
Could you provide a minimal working example that recreates the problem?
The problem is not explained well but an example may be sufficient to understand the problem.
Adam Danz
le 17 Fév 2020
Otto Meier's answer moved here as a comment.
Adam,
many thanks for your fast response.
To make the issue more clear ,I will send 2 screen shoots of the chart one before midnight and one after midnight to hopefully show the problem in detail.
Best regards
Otto
Adam Danz
le 17 Fév 2020
Screenshots might be helpful but if the images are of code, it's much more useful to copy-paste the code directly.
Also, please use the comment section for comments and reserve the answer section for answers. You could attach the additional information to your original question, as well.
Christopher Stapels
le 18 Fév 2020
How frequently are you writing to your channel? There is a limit of 8000 data points in a single read that might casue the problem you are seeing.
Otto Meier
le 18 Fév 2020
Christopher Stapels
le 19 Fév 2020
You can only read 8000 values at once from any ThingSpeak Read API. When you try to sum over 10 days for 1440 values per day, you are exceeding the maximum read number. This is why you observe less than the appropriate sum.
We generally suggest using an additional derived channel that is a summation channel to overcome this issue. Each day, or on a regular interval, the target channel is read and summed or averaged and written to the derived channel. You can use timeControl and MATLAB analysis to acheive this operation.
Alternatively, you could use a MATLAB analysis to do multiple reads of the target channel and sum them in a single script. If you do this route, be sure to add a small delay between reads so as not to upset the server.
Otto Meier
le 19 Fév 2020
David Stacer
le 19 Fév 2020
I do this on several of my channels, where I log data to one channel every minute then once a day run a timecontrol job that reads from the detail channel, counts, compute or sum's up a field and writes one record to another channel.
It took a while to figure this out so some code snipps to get you started.
EndDate = datetime('today','TimeZone','America/New_York','Format','yyyy-MM-dd''T''HH:mmZZZ') % use your TimeZone What time is it "right now" (local) when running this
StartDate = EndDate - days(1)
% Count the number of sequence number that were sent yesterday. Logging every 1 minutes produces 1440 entries per day.
[Seq, time] = thingSpeakRead(readChannelID,'Fields',SeqID,'DateRange',[StartDate,EndDate], 'ReadKey', readAPIKey); % Count the number of entries for the day
SeqCount = length(Seq); % getting the length returns the number of records read from the channel.
[RT, time] = thingSpeakRead(readChannelID,'Fields',Runtime,'DateRange',[StartDate,EndDate], 'ReadKey', readAPIKey);
sumRT = sum(RT);
sumRT
Total_Gallons = round((sumRT * 1.226) / 128,2) %measured 1.226 oz per second
Total_Gallons
%Runtime is in seconds, make it easier to read, convert to minutes
sumRT_minutes = round(sumRT / 60)
dutyCycle = round(sumRT_minutes / 1440,4) * 100 %Calculate duty cycle or precentage of time on
dutyCycle
sumRT_hours = round(sumRT / 3600,2)
sumRT_hours
dataTable = timetable(StartDate, Total_Gallons, dutyCycle, sumRT_hours, sumRT_minutes, SeqCount)
display(dataTable)
response = thingSpeakWrite(writeChannelID, dataTable, 'WriteKey',writeAPIKey);
https://thingspeak.com/channels/112973 is a public channel of what my Little Sump Pump did yesterday. The data in this channel is from the code above. It runs at 2:00 am to summarize what happened yesterday.
Réponses (0)
Communautés
Plus de réponses dans ThingSpeak Community
Catégories
En savoir plus sur Line Plots dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!