- JAPANESE document is available: See README_ja.md
Module and sample code for obtaining data with OMRON 2JCIE-BU01 Environment Sensor by Python. The codes work with Python 3.6 and above. This module supports USB serial communication and BLE. This module depends on pySerial(serial communication) and Bleak(BLE).
from omron_2jcie_bu01 import Omron2JCIE_BU01
sensor = Omron2JCIE_BU01.serial("/dev/ttyUSB0") # Linux
sensor = Omron2JCIE_BU01.serial("COM5") # Windows
devinfo = sensor.info()
data = sensor.latest_data_long()
# Read latest data with connection
from omron_2jcie_bu01 import Omron2JCIE_BU01
sensor = Omron2JCIE_BU01.ble("AA:BB:CC:DD:EE:FF")
data1 = sensor.latest_sensing_data()
data2 = sensor.latest_calculation_data()
# Read latest data by scan
def on_scan(data):
print("SCAN", data)
# Advertising mode: 0x01 (Passive)
sensor.scan(on_scan, scantime=3)
# Advertising mode: 0x03 (Active)
sensor.scan(on_scan, scantime=3, active=True)
# Notify sensing data
def on_notify(sender, tpl):
print(f"{sender} {tpl}")
sensor.start_notify(0x5012, on_notify)
sensor.start_notify(0x5013, on_notify)
sensor.sleep(5)
sensor.stop_notify(0x5012)
sensor.stop_notify(0x5013)
- omron_2jcie_bu01/ -- This module
- init.py -- Common class for serial and BLE
- ble.py -- Omron2JCIE_BU01_BLE class for BLE
- serial.py -- Omron2JCIE_BU01_Serial class for serial
- test/ -- Unit test (for minimum operation check)
- examples/ -- Example codes
-
pySerial 3.4
pip3 install pyserial
-
Bleak 0.7.1
-
Codes was confirmed the operation on Windows 10
pip3 install bleak
Base class for Omron2JCIE_BU01_Serial and Omron2JCIE_BU01_BLE.
- serial(port)
- Returns Omron2JCIE_BU01_Serial instance.
- ble(hardware_address=None)
- Returns Omron2JCIE_BU01_BLE instance.
Class for serial communication. Parameter port is for example, /dev/ttyUSB0 (Linux), COM5 (Windows).
Class for BLE communication. Hardware address is optional. If ommited, the address will be specified by discover(). The discover() takes time, specifying address are recommended.
Do not instantiate it directly, but inherit it.
- get(address, data=b"", name=None)
- Returns data which is parsed by DataParser.
- vibration_count()
- 4.5.7 Vibration count (Address: 0x5031)
- earthquake: Earthquake count
- vibration: Vibration count
- 4.5.7 Vibration count (Address: 0x5031)
- led(rule: int=None, rgb: tuple=None)
- 4.5.8 LED setting [normal state] (Address: 0x5111)
- Get/Set LED setting
- rule: Display rule (normal state)
- rgb: (red、green、blue) Tuple of intensity
- 4.5.8 LED setting [normal state] (Address: 0x5111)
- advertise_setting(interval=None, mode=None)
- latest_data_long()
- 4.4.3 Latest data long (Address: 0x5021) [USB original address]
- seq: Sequence number (UInt8)
- temperature: Temerature (SInt16); 0.01 degC
- humidity: Relative humidity (SInt16); 0.01 %RH
- light: Ambient light (SInt16); 1 lx
- pressure: Barometric pressure (SInt32); 0.001 hPa
- noise: Sound noise (SInt16); 0.01 dB
- eTVOC: eTVOC (SInt16); 1 ppb
- eCO2: eCO2 (SInt16); 1 ppm
- thi: Discomfort index; THI (SInt16); 0.01
- wbgt: Heat stroke; WBGT (SInt16); 0.01 degC
- vibration: Vibration information (UInt8); See Table 124
- si: SI value (UInt16); 0.1 kine
- pga: PGA (UInt16); 0.1 gal
- seismic_intensity: Seismic intensity (UInt16); 0.001
- 4.4.3 Latest data long (Address: 0x5021) [USB original address]
- info()
- 4.5.25 Device information (Address: 0x180a)
- model: Model
- serial: Serial number
- fw_rev: Firmware version
- hw_rev: Hardware version
- manufacturer: Manufacturer name
- 4.5.25 Device information (Address: 0x180a)
- scan(callback, scantime=10, active=False, distinct=True)
- connect()
- disconnect()
- is_connected()
- latest_sensing_data()
- 2.2 Latest Data Service (Service UUID: 0x5010)
- 0x5012: Latest sensing data
- 2.2 Latest Data Service (Service UUID: 0x5010)
- latest_calculation_data()
- 2.2 Latest Data Service (Service UUID: 0x5010)
- 0x5013: Latest calculation data
- 2.2 Latest Data Service (Service UUID: 0x5010)
- start_notify(characteristic_uuid, callback):
- Activate notifications on a characteristic
def callback(sender, tpl): print(f"{sender} {tpl}") sensor.start_notify(0x5012, callback) sensor.start_notify(0x5013, callback) sensor.sleep(5) sensor.stop_notify(0x5012) sensor.stop_notify(0x5013)
- The callback will be called every time notification arrives.
- Arguments of callback are sender and parsed data.
- Activate notifications on a characteristic
- stop_notify(characteristic_uuid)
- Stop notification.
- sleep(seconds)
- Call asyncio.sleep()
- OMRON 2JCIE-BU Environment Sensor (USB Type)