[PYTHON] Inkbird IBS-TH1 value logged with Raspberry Pi

Introduction

This article has the same content as ** Omron Environment Sensor (BAG type) article **. This article was carried out with the low-priced ** Inkbird IBS-TH1 **. The mini I used last time had a bad battery life, so I aimed to improve the durability with this product with AAA batteries.

What is Inkbird?

A manufacturer in Shenzhen, China, which makes various home IoT sensors. It is attractive that it has all the functions such as data acquisition with smartphone application and API at a low price (about 3000 yen).

This time, it is equipped with a temperature + humidity sensor Inkbird IBS-TH1 Inkbird_IBS-TH1.jpg

Then, logging will be performed.

Things necessary

** ・ RaspberryPi ** (Pi3Model B is used this time) **-Python execution environment ** (This time, pyenv uses Python 3.7.6) ** ・ Inkbird IBS-TH1 ** (used with the probe removed)

procedure

** ① Check the Bluetooth connection between the Raspberry Pi and the sensor ** ** ② Get sensor measurements in Python ** ** ③ Hit the GAS API from Python to write data to the spreadsheet ** ** ④ Script execution regularly **

I referred to this. https://qiita.com/bon_dentetsu/items/87ed6c65640b5ba11e5c https://github.com/viyh/inkbird https://github.com/sputnikdev/eclipse-smarthome-bluetooth-binding/issues/60

① Check the Bluetooth connection between the Raspberry pi and the sensor

Sensor recognition confirmation

** ・ Sensor setup ** Insert AAA batteries into the sensor (please note that the lid is difficult to remove)

**-Scan for Bluetooth devices ** Execute the following command on Raspberry Pi

sudo hcitool lescan
LE Scan ...
AA:CC:EE:DD:55:77 sps

If you see the name "sps", this is the MAC address of the sensor. If it does not come out, check the battery contact and the Bluetooth enable of Raspberry Pi. Depending on the model and settings, the name may not be "sps", so In that case, you can check the MAC address at Inkbird Official App.

** ② Get sensor measurements in Python **

Recognition confirmation with bluepy

bluepy is a library for accessing Bluetooth Low Energy (BLE) in Python (class definition)

** ・ Installation of required packages ** Install the following

sudo install libglib2.0-dev

** ・ Install bluepy **

Install with pip with the following command

pip install bluepy

** ・ Grant permissions to bluepy ** You need to give bluepy Sudo privileges for scanning.

Go to the folder where bluepy is installed and

cd ~.pyenv/versions/3.7.6/lib/python3.7/site-packages/bluepy

Grant Sudo privileges to bluepy-helper with the following command

sudo setcap 'cap_net_raw,cap_net_admin+eip' bluepy-helper

Creating a sensor value acquisition script

Create the following script to get the sensor value

inkbird_ibsth1_connect.py


from bluepy import btle
import struct

def get_ibsth1_data(macaddr):
    peripheral = btle.Peripheral(macaddr)
    characteristic = peripheral.readCharacteristic(0x28)
    (temp, humid, unknown1, unknown2, unknown3) = struct.unpack('<hhBBB', characteristic)
    sensorValue = {
            'Temperature': temp / 100,
            'Humidity': humid / 100,
            'unknown1': unknown1,
            'unknown2': unknown2,
            'unknown3': unknown3,
        }
    return sensorValue

In Inkbird IBS-TH1 mini, the handle was "0x002d", but this time it is "0x28", so please be careful. Data is acquired by communication with bluepy's Peripheral class.

The acquired characteristic data is ** ・ 1st and 2nd bytes: Temperature (0.01 ℃ unit) ** ** ・ 3rd-4th bytes: Humidity (0.01% unit) ** However, I couldn't find out even if I checked the contents of the 5th to 7th bytes, so I will log it as unknown1 ~ 3 to find out what it is. (We are aiming to get the remaining battery power)

Create main script

Create a main script to call the sensor value acquisition script

inkbird_toSpreadSheet.py


from bluepy import btle
import inkbird_ibsth1_connect

######Acquisition of value of OMRON environment sensor (BAG type)######
PERIPHERAL_MAC_ADDRESS = 'MAC address obtained in ①'
sensorValue = inkbird_ibsth1_connect.get_ibsth1_data(PERIPHERAL_MAC_ADDRESS)

#Display the temperature as a trial
print(sensorValue['Temperature'])

Try running from the console

python inkbird_toSpreadSheet.py
25.49

You have now obtained the sensor readings in Python.

③ Hit the GAS API from Python to write data to the spreadsheet

[Omron Environment Sensor Article](https://qiita.com/c60evaporator/items/ed2ffde4c87001111c12#python%E3%81%8B%E3%82%89gas%E3%81%AEapi%E3%82%92%E5% 8F% A9% E3% 81% 84% E3% 81% A6% E3% 82% B9% E3% 83% 97% E3% 83% AC% E3% 83% 83% E3% 83% 89% E3% 82% B7% E3% 83% BC% E3% 83% 88% E3% 81% AB% E3% 83% 87% E3% 83% BC% E3% 82% BF% E6% 9B% B8% E3% 81% 8D% E8% BE% BC% E3% 81% BF) Please refer

④ Periodic execution of script

[Omron Environment Sensor Article](https://qiita.com/c60evaporator/items/ed2ffde4c87001111c12#%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%97%E3%83 % 88% E3% 81% AE% E5% AE% 9A% E6% 9C% 9F% E5% AE% 9F% E8% A1% 8C) Please refer

Recommended Posts

Inkbird IBS-TH1 value logged with Raspberry Pi
Logging Inkbird IBS-TH1 mini values with Raspberry Pi
GPGPU with Raspberry Pi
DigitalSignage with Raspberry Pi
Mutter plants with Raspberry Pi
Take the value of SwitchBot thermo-hygrometer with Raspberry Pi
Log the value of SwitchBot thermo-hygrometer with Raspberry Pi
[Raspberry Pi] Stepping motor control with Raspberry Pi
Use vl53l0x with Raspberry Pi (python)
Servo motor control with Raspberry Pi
Serial communication with Raspberry Pi + PySerial
OS setup with Raspberry Pi Imager
Try L Chika with raspberry pi
VPN server construction with Raspberry Pi
Try moving 3 servos with Raspberry Pi
Using a webcam with Raspberry Pi
Periodically log the value of Omron environment sensor with Raspberry Pi
Pet monitoring with Rekognition and Raspberry pi
Build a Tensorflow environment with Raspberry Pi [2020]
Get BITCOIN LTP information with Raspberry PI
Try fishing for smelt with Raspberry Pi
Programming normally with Node-RED programming on Raspberry Pi 3
Try Object detection with Raspberry Pi 4 + Coral
Power SG-90 servo motor with raspberry pi
Working with sensors on Mathematica on Raspberry Pi
Use PIR motion sensor with raspberry Pi
Make a wash-drying timer with a Raspberry Pi
Infer Custom Vision model with Raspberry Pi
Operate an oscilloscope with a Raspberry Pi
Create a car meter with raspberry pi
Working with GPS on Raspberry Pi 3 Python
Get GrovePi + sensor value with Raspberry Pi and store it in kintone
Logging the value of Omron environment sensor with Raspberry Pi (USB type)
Discord bot with python raspberry pi zero with [Notes]
Media programming with Raspberry Pi (preparation for audio)
I tried L-Chika with Raspberry Pi 4 (Python edition)
Raspberry Pi backup
Enjoy electronic work with GPIO on Raspberry Pi
MQTT RC car with Arduino and Raspberry Pi
Power on / off your PC with raspberry pi
Use Majoca Iris elongated LCD with Raspberry Pi
CSV output of pulse data with Raspberry Pi (CSV output)
Observe the Geminids meteor shower with Raspberry Pi 4
Get CPU information of Raspberry Pi with Python
Play with your Ubuntu desktop on your Raspberry Pi 4
Get temperature and humidity with DHT11 and Raspberry Pi
Stock investment analysis app made with Raspberry Pi
Connect to MySQL with Python on Raspberry Pi
GPS tracking with Raspberry Pi 4B + BU-353S4 (Python)
Measure CPU temperature of Raspberry Pi with Python
Record temperature and humidity with systemd on Raspberry Pi
Machine learning with Raspberry Pi 4 and Coral USB Accelerator
Using the digital illuminance sensor TSL2561 with Raspberry Pi
Easy IoT to start with Raspberry Pi and MESH
Display images taken with the Raspberry Pi camera module
Using Akizuki Denshi's 4WD car FT-MC-004 with Raspberry Pi
Try to visualize the room with Raspberry Pi, part 1
Try debugging Python on Raspberry Pi with Visual Studio.
Detect mask wearing status with OpenCV and Raspberry Pi
Control brushless motors with GPIOs on Raspberry Pi Zero
Measure temperature and humidity with Raspberry Pi3 and visualize with Ambient