[PYTHON] Logging Inkbird IBS-TH1 mini values with Raspberry Pi

Introduction

This article has the same content as ** Omron Environment Sensor (BAG type) article **. This article was carried out on the low-priced ** Inkbird IBS-TH1 mini **.

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 mini Inkbird_mini.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 mini **

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://qiita.com/junara/items/f396c1c4c15c78cde89f

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

Sensor recognition confirmation

** ・ Sensor setup ** Insert the button battery that comes with the sensor.

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

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

If you see the name "sps", this is the MAC address of the environmental sensor. If it does not come out, check the USB contact and the Bluetooth enable of the 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 the measured value of the environmental sensor with 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_mini_data(macaddr):
    peripheral = btle.Peripheral(macaddr)
    characteristic = peripheral.readCharacteristic(0x002d)
    (temp, humid, unknown1, unknown2, unknown3) = struct.unpack('<hhBBB', characteristic)
    sensorValue = {
            'Temperature': temp / 100,
            'Humidity': humid / 100,
            'unknown1': unknown1,
            'unknown2': unknown2,
            'unknown3': unknown3,
        }
    return sensorValue

This sensor is connected in connect mode like the USB version of OMRON Environmental Sensor. 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_mini_data(PERIPHERAL_MAC_ADDRESS1)

#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

Postscript

In addition, this product ** [Battery drains quickly](https://billiesmarket.net/2019/11/25/%EF%BC%91%E3%83%B6%E6%9C%88%E3% 81% A7% E9% 9B% BB% E6% B1% A0% E3% 81% 8C% E5% 88% 87% E3% 82% 8C% E3% 81% 9Finkbird-% E3% 83% 9F% E3% 83 % 8Bibs-th1-mini% E3% 80% 82% E8% B2% B7% E3% 81% 86% E3% 81% AA% E3% 82% 89% E3% 82% AA% E3% 82% B9 /) **, it seems that it will expire in about a month, so [IBS-TH1](https://www.amazon.co.jp/Inkbird-Bluetooth-%E3%82%B9%E3%83%9E%E3%83%BC] with a little size up but good battery life % E3% 83% 88% E3% 82% BB% E3% 83% B3% E3% 82% B5% E3% 83% BC-% E6% B8% A9% E6% B9% BF% E5% BA% A6% E3% 83% AC% E3% 82% B3% E3% 83% BC% E3% 83% 80% E3% 83% BC-IBS-TH1 / dp / B07T1W9WGN? Th = 1) think.

(I've become a Bluetooth sensorman, but I'll keep going without getting bored! Lol)

Recommended Posts

Logging Inkbird IBS-TH1 mini values with Raspberry Pi
Inkbird IBS-TH1 value logged with Raspberry Pi
GPGPU with Raspberry Pi
DigitalSignage 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
Measure SIM signal strength with Raspberry Pi
Pet monitoring with Rekognition and Raspberry pi
Hello World with Raspberry Pi + Minecraft Pi Edition
Build a Tensorflow environment with Raspberry Pi [2020]
Programming normally with Node-RED programming on Raspberry Pi 3
Improved motion sensor made with Raspberry Pi
Try Object detection with Raspberry Pi 4 + Coral
Power SG-90 servo motor with raspberry pi
Use PIR motion sensor with raspberry Pi
Make a wash-drying timer with a Raspberry Pi
Operate an oscilloscope with a Raspberry Pi
Create a car meter with raspberry pi
Working with GPS on Raspberry Pi 3 Python
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)
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
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
Raspberry Pi backup
Record temperature and humidity with systemd on Raspberry Pi
Machine learning with Raspberry Pi 4 and Coral USB Accelerator
Run LEDmatrix interactively with Raspberry Pi 3B + on Slackbot
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 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
Take the value of SwitchBot thermo-hygrometer with Raspberry Pi
Measure temperature and humidity with Raspberry Pi3 and visualize with Ambient
Log the value of SwitchBot thermo-hygrometer with Raspberry Pi
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
Make an umbrella reminder with Raspberry Pi Zero W
Face detection from images taken with Raspberry Pi camera
Troubleshoot with installing OpenCV on Raspberry Pi and capturing
Display USB camera video with Python OpenCV with Raspberry Pi
Let's operate GPIO of Raspberry Pi with Python CGI
Raspberry Pi with Elixir, which is cooler than Python