hack のためのネタ帳, etc,,,

×

Tips

20260403: 温度・湿度の取得

AdvertisementData を拾う方法と GATT の vendor specific characteristic から "Real time data" を拾う方法が取れる。

GATT から拾う場合の handle は、 辺りを見ると、同社製の他機種、IBS-TH2 は 0x24、IBS-TH1 は 0x28 みたいな情報が見られて、
どうも機種毎に異なっている様子である。
ひょっとすると、FW version によっても変わるのかもしれない。
とりあえず、本機 IBS-TH2 Plus の場合は UUID : 0x2901 (Standard Descriptors : Characteristic User Description) に "Real time data" が設定されている handle = 0x0017 の Characteristic が目的のデータで、データ構造は、上記ページの情報の通り、
{
  int16le temperature_x100. // 100 倍した温度
  int16le humidity_x100,    // 100 倍した湿度
  int8    unknown[3],       // 不明
}
だった。

Ubuntu に bluez 入れてると以下のコマンドで取得できる。
gatttool -b "$MAC" --char-read -a 0x0017
$ # temperature = 27.0℃
$ # humidity    = 40.5% 
$ # battery     = 70%
$ read v < <(gatttool -b "$MAC" --char-read -a 0x0017); printf "%s\n" "$v"; \
readarray -t v < <(sed -E 's/.*: *//g;s/ +/\n/g' <<<"$v"); declare -p v; \
printf "%d\n" "0x${v[1]}${v[0]}" "0x${v[3]}${v[2]}" "0x${v[4]}" "0x${v[5]}" "0x${v[6]}"
Characteristic value/descriptor: 8f 0a f6 0f 00 97 c5
declare -a v=([0]="8f" [1]="0a" [2]="f6" [3]="0f" [4]="00" [5]="97" [6]="c5")
2703
4086
0
151
197
みたいな感じなので、末尾 3 バイトの素性は不明で、少なくともバッテリーの残量とは関係のない値のような気がする。

AdvertisementData を拾う場合は によると、
{
  ManufacturerData Key : {
    int16le temperature_x100, // 100 倍した温度 [℃/100]
  },
  ManufacturerData Value : {
    int16le hupedity_x100.    // 100 倍した湿度 [%/100]
    int8    unknown[5],       // 不明
  }
}
みたいなデータ構造になってるっぽいんだが、
  • temperature = 27.08℃ : 2708 = 0x0a94
  • humidity = 40.36% : 4036 = 0x0fc4
  • battery = 69% : 69 = 0x45
のタイミングで bluez 同梱の bluetoothctl コマンドを使うと
$ bluetoothctl scan on
Discovery started
...
[NEW] Device **:**:**:**:**:** sps
...
[CHG] Device **:**:**:**:**:** ManufacturerData Key: 0x0a94
[CHG] Device **:**:**:**:**:** ManufacturerData Value:
  c4 0f 00 52 08 45 08                             ...R.E.
...
みたいな結果が得られるので、
{
  ManufacturerData Key : {
    int16le temperature_x100, // 100 倍した温度 [℃/100]

  },
  ManufacturerData Value : {
    int16le hupedity_x100.    // 100 倍した湿度 [%/100]
    int8    unknown1[3],      // 不明
    int8    battery,          // 電池残量[%]
    int8    unknown2,         // 不明
  }
}
じゃないかと思われる。

コメントをかく


「http://」を含む投稿は禁止されています。

利用規約をご確認のうえご記入下さい

Wiki内検索

フリーエリア

管理人/副管理人のみ編集できます

広告募集中