Quantcast
Channel: ThingSpeak IoT Community - Forum: ThingSpeak Apps
Viewing all articles
Browse latest Browse all 223

rberkelm on Daily max and min

$
0
0

Dear all

I looked long and hard for code that would calculate daily maxima and minima for temperature and humidity (i.e since midnight) but I couldn't find any.

I eventually managed to work it out, so I'm posting it here in case it helps others. The max & min graphs by themselves are not very interesting, but I use these data in Google Gauge to display the last value. I also found that creating a React app for running the code on each new temperature insertion is better than using the Time Control app. In the Time control app (which only runs every 5min), the current temperature can often be higher than the max temperature in the morning - this doesn't look cool!

----------------

% My implementation of daily max and min temperature and humidity, written to another channel (fields 2 to 5) for later display in Google Gauge using the standard plug-in. This code assumes a public channel to read the original data from.

readChannelID= 'xxxxxxxxxxxx';

writeNewChannelID='xxxxxxxxxxx'

writeAPIKey=xxxxxxxxx

% Define date range (i.e. since midnight)
end = datetime('now')
start=datetime('today')

% Read the Temp data from Field1 since midnight
[Temp, time] = thingSpeakRead(readChannelID,'DateRange', [start,end], 'Fields', [1]);
Tmax = max(Temp); % Get daily Max
Tmin = min(Temp); % Get daily Min
% Read the Humidity data from Field2 since midnight
[Humidity, time] = thingSpeakRead(readChannelID, 'DateRange', [start, end], 'Fields', [2]);
Hmax = max(Humidity); % Get daily Max
Hmin = min(Humidity); % Get daily Min

% display results to test
display(Tmax, 'T_max'), display(Tmin, 'T_min')
display(Hmax, 'H_max'), display(Hmin, 'H_max')

% Write data to a new channel
thingSpeakWrite(writeNewChannelID,'Fields',[2,3,4,5],'Values',{Tmax,Tmin,Hmax,Hmin}, 'Writekey', writeAPIKey);


Viewing all articles
Browse latest Browse all 223

Trending Articles