1
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?

More than 5 years have passed since last update.

ThingSpeakでエラー値

Last updated at Posted at 2019-10-10

気圧計モジュールのBMP180のデータを13万件ほど送ったところで二件エラーがあり、最高最低気温のフラフがおかしくなりました。

2019-10-07 10:57:20 JST,129382,-196.9,476.54,,,,
2019-10-07 13:13:05 JST,129848,-83.5,722.24,,,,

気温が-196.9と-83.5になってしまってます。

スクリーンショット 2019-10-10 9.01.27.png

ThingSpeakは部分的にデータを削除することはできないのでMATLABで対処する方法を調べてみました。

とりあえず気温のデータがマイナスの場合NaNにしてデータを無効化してみました。

% Last week max and min temputure

readChannelID = ;
readAPIKey = "";

day = datetime('now') - 14;
disp(day);

% startdaystr = "Sep 22, 2019 00:00:00";
% enddaystr = "Sep 23, 2019 00:00:00";

for c = 1:14
    
    startdaystr = datestr(day,'mmm dd, yyyy 00:00:00');
    enddaystr = datestr(day + 1,'mmm dd, yyyy 00:00:00');
    [a,b] = thingSpeakRead(readChannelID, 'ReadKey', readAPIKey, 'Fields',1,'DateRange', [datetime(startdaystr),datetime(enddaystr)]);

    a(a < 0) = NaN;
    [m, n] = max(a);
    [x, y] = min(a);

    %disp(m);

    t(c) = day;
    vmax(c) = m - x
    vmin(c) = x
    day = day + 1
end

C = vertcat(vmin, vmax);

H = bar(t, C, 'stacked');

set(H(1),{'FaceColor'},{[1 1 1]});
set(H(1),{'EdgeColor'},{[1 1 1]});
set(H(1),{'LineWidth'},{1});

こうなりました。

スクリーンショット 2019-10-10 9.02.17.png

このスクリプトにはマイナスになった時に正しく動かないバグもあるようです。

1
0
1

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
1
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?