LoginSignup
5
0

More than 3 years have passed since last update.

ThingSpeakでInternet of Test

Last updated at Posted at 2020-12-08

ThingSpeakにアクセスしてモジュールの安定度のテストをしています。無料のアカウントでのアクセスは15秒以上の間隔が必要で30秒のインターバルでアクセスして試しています。

kani.png

thing.png

データを送信しているmrubyスクリプトは以下のようにしています。

MATLAB Visualizationで直近1000個のアクセス間隔を集計してます。

readChannelID = 0;

readAPIKey = 'abc';

t1 = thingSpeakRead(readChannelID, 'ReadKey', readAPIKey, 'NumPoints',1000, 'OutputFormat','table');

[m,n] = size(t1);
for c = 1:m - 1
    d = seconds(t1.Timestamps(c+1) - t1.Timestamps(c));
    s(c) = d(1); 
end

ma = max(s)
for c = 1:ma
    v(c) = 0;
end

for c = 1:m - 1
    v(s(c)) = v(s(c)) + 1;
end

plot(v, 'LineStyle','--','LineWidth',2,'Color','green','Marker','s');

matlab4.png

一行追加してX軸の範囲を指定してみます。

xlim([30 ma+1])

matlab5.png

棒グラフにしてみます。

bar(v);
xlim([30 ma+1])

matlab6.png

配列を行列に変換してaccumarray関数で集計しても同じグラフになりました。

readChannelID = 0;

readAPIKey = 'abc';

t1 = thingSpeakRead(readChannelID, 'ReadKey', readAPIKey, 'NumPoints',1000, 'OutputFormat','table');

[m,n] = size(t1);
for c = 1:m - 1
    d = seconds(t1.Timestamps(c+1) - t1.Timestamps(c));
    s(c) = d(1); 
end

B = reshape(s,[m-1,1])
A = accumarray(B,1);

bar(A);
xlim([30 ma+1])

無料アカウントでの使用はCPU利用時間に制限があり、データ量が多い場合は、できるだけ関数で処理するほうが有利なのかと思われます。

MATLABあまり良く分かってないので、よいこはまねしないでくださいね。

5
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
5
0