Reading temperature and humidity data from MHO-C401 with Python
MHO-C401 is new (2020) MMC E-Ink Screen Smart #Bluetooth Thermometer Hygrometer BT2.0 Temperature Humidity Sensor from Xiaomi. You can order yours on Gearbest or Aliexpress.
hcitool is Linux tool for monitoring and configuring Bluetooth devices. It is aptly named hcitool as it communicates via a common HCI (Host Controller Interface port to your bluetooth devices. You
can utilize the utility to scan for devices and send commands/data for standard Bluetooth and Bluetooth Low Energy.
First check, if your hcitool can see your device with hcitool dev command, then you can start lescan for other devices arroud.
You will get output similar to this one:
As you can see from list my MHO-C401 have A4:C1:38:4B:B7:FF MAC address.
Lets read some data!
We will use a Python to read the data from BLE - there are some great libraries for that, like bluepy. Bluepy provide a comprehensive API to allow access to Bluetooth Low Energy devices.
Each BLE devices provide Services and Characteristics. Services are used to break data up into logic entities, and contain specific chunks of data
called characteristics. A service can have one or more characteristics, and each service distinguishes itself from other services by means of a unique numeric ID called a UUID, which can be either 16-bit (for officially adopted BLE Services) or 128-bit (for custom services).
The Python code below will generate a list of all the available services and characteristics on the our BLE device.
Output will looks like that:
Then you can read first device characteristic, with follow code:
Reading temperature and humidity
For reading temperature and humidity you have to subscribe notifications for UUID = EBE0CCC1-7A0A-4B0C-8A1A-6FF2997DA3A6 - there are 3 bytes of data. Notifications are processed by creating a “delegate” object and
registering it with the Peripheral.