ThingSpeak

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Aggregate Data in ThingSpeak Channel

This example shows how to aggregate data to a lower time resolution in a ThingSpeak™ channel to remove irregularity. Irregularity in a data can be caused due to several factors such as event driven sensing, malfunctioning of sensors, or network latencies.

Read Data

ThingSpeak channel 22641 contains tide and weather data measured once a minute at Ockway Bay, Cape Cod. Field 2 of the channel contains air temperature data. Read the air temperature data for the past 3 hours from channel 22641 using the thingSpeakRead function.

datetimeStop = dateshift(datetime('now'),'start','hour');
datetimeStart = dateshift(datetime('now'),'start','hour') - hours(3);

data = thingSpeakRead(22641,'DateRange',[datetimeStart,datetimeStop],...
    'Fields',2,'outputFormat','timetable'); 

Aggregate the Data

Data is measured once every minute. However, due to network latency associated with the measurement system, the actual timestamps might be greater than or less than a minute apart. Further, for the application of interest, the frequency of data measured every minute is high. Data at an hourly time resolution is sufficient. You can use the retime function to aggregate the data for each hour to a single value. You can use the maximum value for each hour to aggregate the data.

dataHourly = retime(data,'hourly','max');

Send Data to ThingSpeak

Send the aggregated data to a ThingSpeak channel using the thingSpeakWrite function.

% Change the Channel ID and the '<write API key>' to send data to your channel
thingSpeakWrite(<channelID>,chirpData,'WriteKey','<write API key>');

See Also

Functions

Was this topic helpful?