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 **.
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 Then, logging will be performed.
** ・ RaspberryPi ** (Pi3Model B is used this time) **-Python execution environment ** (This time, pyenv uses Python 3.7.6) ** ・ Inkbird IBS-TH1 mini **
** ① 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
** ・ 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.
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
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 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.
[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
[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
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