Daily average of a temperature

5 ビュー (過去 30 日間)
Matthias Borremans
Matthias Borremans 2021 年 8 月 3 日
コメント済み: colm carmody 2022 年 2 月 9 日
Hi all,
I have a ds18b20 and esp8266 with espeasy which posts a temperature reading to thingspeak every 5 minutes, works without any issue.
I want to have multiple fields to be able to show a daily average. I think this is not possible with espeasy directly so i have to get some workaround with the visualizations. I have the code below to show an average, it outputs a number, but nothing is plotted.
% Read temperature over the past hour from a ThingSpeak channel
readChannelID = 1462749;
TemperatureFieldID = 1;
readAPIKey = '__REDACTED__';
% Get temperature data for the last 60 minutes
[data, timeStamps ] = thingSpeakRead(readChannelID,'Fields',[TemperatureFieldID], 'NumPoints',30,'ReadKey',readAPIKey);
% Calculate the average temperature
avgTemperature = mean(data);
display(avgTemperature,'Average Temperature');
% Plot temperature and timestamp
plot(timeStamps,avgTemperature)
ylabel('temperature (°C)');
  1 件のコメント
colm carmody
colm carmody 2022 年 2 月 9 日
Did you solve this issue I have the same problem, I can compute the average but not plot it.

サインインしてコメントする。

回答 (2 件)

Yongjian Feng
Yongjian Feng 2021 年 8 月 3 日
Your avgTemperature is just a scalar, a single point. Maybe you want to plot the data instead?
plot(timeStamps, data)
  10 件のコメント
Matthias Borremans
Matthias Borremans 2021 年 8 月 3 日
Could you maybe guide me through the process?
Yongjian Feng
Yongjian Feng 2021 年 8 月 3 日
How about this:
  1. Use a for loop to loop through all the days you want to plot.
  2. Inside the loop, get the temperatures of that particular day, and do an average
  3. append this average to an array, inside the for loop
  4. once the for loop is done, you have an array of averageTemperatures
  5. Plot that array.

サインインしてコメントする。


Christopher Stapels
Christopher Stapels 2021 年 8 月 9 日
You can use the pencil icon on the top of the ThingSpeak plot to make the timeScale Daily.
Also, you can write the output from the code above to another ThingSpeak channel. We call that a derived channel.
Instead of 'NumPoints',30,
use 'NumDays', 1.
Use thingSpeakWrite() to write the data to you new channel.
And then use a timecontrol to call that code daily. Then you will have a plot of daily average.
See the getting started tutorial for an example of that workflow.
Also you could create a matlab visualisation that reads many days of data and then use retime() function to calculate the daily avarage and plot it.
I reccomend using 'outputformat','timetable' when you read the data becasue retime works nicely on timetables.

コミュニティ

その他の回答  ThingSpeak コミュニティ

カテゴリ

Help Center および File ExchangeRead Data from Channel についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by