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

Inkbird IBS-TH1 MINI 温湿度計をラズパイから読む

Posted at

 前回、Inkbird IBS-TH1 MINI 温湿度計をmatlabから読みました。ここではラズパイ4で読みます。

ラズパイの準備

セントラルのプログラムを書くために、bluepyライブラリをインストールします。このBLEライブラリは、pythonでセントラルのプログラムだけが書けます。

 ラズパイ4は最新の状態にしておきます。次の2点をインストールします。

$ sudo apt-get install python3-pip libglib2.0-dev $ sudo pip3 install bluepy

 GitHubにあるサンプルblescan.pyをエディタに読み込み、scan.pyの名前で保存します。

$ sudo python3 scan.py

で、アドバタイジングしているBLEペリフェラルを探します。見つけてきました。Device Addrをメモしておきます。
sps201.png

プログラム

from bluepy import btle
import time

data_CharacteristicUUID    = "FFF2"
deviceAddr = "10:08:2c:1e:2e:ab"

print('connect to Inkbird\n')
peri = btle.Peripheral()

while 1:
    peri.connect(deviceAddr, btle.ADDR_TYPE_PUBLIC)
    # print('connect')
    dataInformation = peri.getCharacteristics(uuid=data_CharacteristicUUID)[0]
    readdata = dataInformation.read()

    # print(readdata[0],readdata[1],readdata[2],readdata[3])
    temp = (readdata[1] * 256 + readdata[0] ) / 100.0
    humi = (readdata[3] * 256 + readdata[2] ) / 100.0
    print("temperature={:.2f}`C humidity={:.1f}%".format(temp, humi))

    peri.disconnect()
    time.sleep(7)

実行します。
sps202.png

 残念ながら、十数回から30回ほどで止まってしまいます。

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