2
1

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 3 years have passed since last update.

matlabでBLEを使う⑦SwitchBot温湿度計

Posted at

 「SwitchBot 温湿度計 デジタル スマート家電 高精度 スイス製センサー スマホで温度湿度管理 アラーム付き グラフ記録 アレクサ、Google home、HomePod、IFTTT に対応(ハブ必要)」
が安価に入手できます。ここでは、BLEで温度と湿度を読み取ります。
IMGP0112.png

UUIDなどを知る手順

 手順は、matlabでBLEを使う④SHT31-SMART-GADGETと同じです。取得したアドレスはD6D36EEF4BA2でした。同様に、サービスUUIDとキャラUUIDも取得します。次のGitHubにもUUIDが書かれています。
  https://github.com/OpenWonderLabs/python-host/wiki/Meter-BLE-open-API#0x30_Setting_Temperature_Display_Mode
 この資料から、

  • 0x57 Magic Number
  • 0x0f 拡張コマンドを送るよ
  • 0x31 ペイロード;Read the Display Mode and Value of the Meter

の3バイトを送りnotifyにすると、温度と湿度を送り返してくれます。送られてくるのは、次の4バイトです。

  • ステータス 1 – OK
  • 温度の小数点部分 0~9の数値
  • 温度 MSBは符号、残りが0~127℃の数値
  • 湿度 整数0~99

プログラム

 温度は零下を無視しています。10秒ごとに10回測定します。

clear
scan = blelist("Timeout", 20);

SwitchBox_address = "D6D36EEF4BA2";
b = ble(SwitchBox_address);
%bb = b.Characteristics;

Bot_ServiceUUID            = "CBA20D00-224D-11E6-9FB8-0002A5D5C51B";
data_CharacteristicUUID    = "CBA20003-224D-11E6-9FB8-0002A5D5C51B";
command_CharacteristicUUID = "CBA20002-224D-11E6-9FB8-0002A5D5C51B";

c1 = characteristic(b, Bot_ServiceUUID, command_CharacteristicUUID);
c10 = characteristic(b, Bot_ServiceUUID, data_CharacteristicUUID);
subscribe(c10);

for i=1:10
    %% https://github.com/OpenWonderLabs/python-host/wiki/Meter-BLE-open-API
    write(c1, [0x57 0x0f 0x31], "withResponse");
    data = read(c10);
    humi = data(4)
    temp = str2double( bitand(data(3), 0b01111111) + "." + data(2) )
    pause(10);
end

 実行例です。計測途中で本体の上部を手のひらで囲っています。
switch101.png

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?