3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

MATLAB/SimulinkAdvent Calendar 2024

Day 3

ThingSpeakネタ

Last updated at Posted at 2024-12-03

mruby on YABMなモジュールからThingSpeakを叩いてInternet of Testしてます。以前書いた簡単なスクリプトをアップデートしてみました。

Internetなので失敗する事もあり、成功率を計算してみました。

エントリー数と、mruby側のカウントの比較になります。

mrubyのスクリプトはこれです。

Channel Settingsでfead dataをクリアして始めます。

MATLABはこんな感じです。

% Channel ID to read data from 
readChannelID = xxx; 

% Channel Read API Key 
% If your channel is private, then enter the read API Key between the '' below: 
readAPIKey = 'naisyo'; 

% Humidity Field ID 
valueFieldID = 1; 

now = datetime('now');
t1 = now;
t2 = t1 - days(1);
total = 0;

while 1
data = thingSpeakRead(readChannelID,'Fields',valueFieldID,'ReadKey',readAPIKey,'OutputFormat','table','DateRange',[t2,t1]); 
[m,n] = size(data);
total = total + m;
if t1 == now
last = data.Timestamps(m);
current = data.FieldLabel1(m);
end
if m == 0
break;
else
fast = data.Timestamps(n);
t1 = t2;
t2 = t1 - days(1);
end
end

uptime = last - fast;

display(total,'total');
display(total / current * 100,'rate');
display(fast,'fast'); 
display(last,'last'); 
display(days(uptime),'days'); 

出力はこんな感じです。

total =

       72007


rate =

   99.9958


fast = 

  datetime

   07-Nov-2024 08:59:56


last = 

  datetime

   03-Dec-2024 14:35:00


days =

   26.2327
3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?