Accéder au contenu principal

Mi flora integration to OpenMQttgateway

Following some users requests on OpenMQTTGateway github I made some research and code to be able to read data from Mi Flora sensor also known as xiaomi flower sensor.
The goal is to connect the mi flora to an mqtt compatible controller like openhab or home assistant with a simple arduino or esp8266 connected to an hm10/11 module.



Mi flora use Bluetooth Low Energy technology to communicate to a smartphone. 
It gather on one sensor temperature, humidity, hygro and fertility measurement. These measures are available through an app on your smartphone so as to monitor your plants.

As this device use BLE the idea was to be able to read the measures with OpenMqttgateway through the hm10 component.

Some code and library are already available in python for the pi or equivalents. But not for arduino or esp8266.
This is where it begins.

With the current gateway version we were able to receive the mac adress of ble devices including the mi flora one. But not the device measures.

I tried the different AT commands of my hm10 without sucess I hadn't any return corresponding to the measures I was getting in the android app. After some hours spent, I asked for help in Martin Currey blog, who answered me to upgrade my hm10 version and to test the new commands.
Indeed with the firmware v547 the command AT+DISA?  was introduced, if we check the release note of Jinan Huamao site we see that this command return the following data :

Add AT+DISA? command used to search devices and return full information
Possible return string format:
OK+DISS  --> Search start
<OK+DISA:><Device Address><Device Type><Device RSSI><Rest data length><Rest data>
OK+DISE  --> Search end
Note: <Rest data length> and <Rest data> is Hex format

So as to know if it is relevant for our measures I used the same method of reverse engineering than this blog post

The particular point compared to the previous commands is that we need now to manipulate hexadecimal returns instead of ascii ones. Maybe the points which asked me most of the developments...

What I did is to launch several times the command AT+DISA? In different sensor configuration and saved the returned values. Here is the detail for one AT+DISA? :

Hexadecimal dataAsciiDecimalType of data
4F 4B 2B 44 49 53 41 53OK+DISAScommand return
4F 4B 2B 44 49 53 41 3AOK+DISA:command return
63 B6 65 8D 7C C4MAC adress reverted
00device type
C0192P3: Device RSSI [1Byte]
1C28P4: Rest data length [1Byte]
02 01 06 03 02 95 FE 14 16 95 FE 71 20 98 00 68 63 B6 65 8D 7C C4 0D 09 10 02 00 00P5: Rest data
0D 0ACR LF
4F 4B 2B 44 49 53 41 3AOK+DISA:command return
63 B6 65 8D 7C C4MAC adress reverted
000device type
C0192P3: Device RSSI [1Byte]
0D13P4: Rest data length [1Byte]
0C 09 46 6C 6F 77 65 72 20 63 61 72 65Flower careP5: Rest data
0D 0ACR LF
4F 4B 2B 44 49 53 43 45OK+DISCEcommand return

There is 2 sentence of data begining each time by OK+DISA:
Each sentence contains:
  • The mac adress reverted
  • The device type = 00, seems not used
  • The device RSSI signal strength
  • The rest data length
  • The rest data , the first message contains the measure, the second message contains the name of the device 'flower care"
  • The other are commands return

We already had the mac adress and the rssi with the AT+DISI? command
But we didnt had the first rest data message.

If we put in list this data chain we can isolate certain values : 
02 01 06 03 02 95 FE 14 16 95 FE 71 20 98 00 68 63 B6 65 8D 7C C4 0D 09 10 02 00 00
02 01 06 03 02 95 FE 14 16 95 FE 71 20 98 00 71 63 B6 65 8D 7C C4 0D 04 10 02 D8 00
02 01 06 03 02 95 FE 14 16 95 FE 71 20 98 00 6D 63 B6 65 8D 7C C4 0D 04 10 02 D7 00
02 01 06 03 02 95 FE 13 16 95 FE 71 20 98 00 6B 63 B6 65 8D 7C C4 0D 08 10 01 00
02 01 06 03 02 95 FE 14 16 95 FE 71 20 98 00 1C 63 B6 65 8D 7C C4 0D 09 10 02 00 00
02 01 06 03 02 95 FE 14 16 95 FE 71 20 98 00 20 63 B6 65 8D 7C C4 0D 09 10 02 00 00
02 01 06 03 02 95 FE 15 16 95 FE 71 20 98 00 22 63 B6 65 8D 7C C4 0D 07 10 03 00 00 00
02 01 06 03 02 95 FE 14 16 95 FE 71 20 98 00 24 63 B6 65 8D 7C C4 0D 09 10 02 00 00
02 01 06 03 02 95 FE 15 16 95 FE 71 20 98 00 26 63 B6 65 8D 7C C4 0D 07 10 03 6E 00 00

The hex value number 8 doesn't seems to vary enough to be a measurement but if we convert it to decimals it gives 14->20, 13->19, 15->21 which corresponds exactly to the number of hex value following.

The last values seems more interesting, we have 4 different values 09, 04, 08, 07 as we have exactly 4 different measure type for this sensor maybe we have a first track.
The 10 is constant.
The 02, 01, 03 correspond to the number of values following.
After that we have some values that we can convert to decimals:
00 00 -> 0
D8 00 -> 55296
D7 00 -> 55040
6E 00 00 -> 7208960

Not so relevant...

If we revert these values as the mac adress we get:
00 00 -> 0
00 D8  -> 216
00 D7  -> 215
00 00 6E  -> 110
More interesting, indeed we can deduct that the values after the 10 are the measures if we revert the hexa values order.

After some trials I deducted that:
  • 9 = ferti,
  • 4 = temp, 
  • 7 = lux, 
  • 8 = hum

By comparaison with the values in the app I saw that the temperature is multiplied by a factor 10. The others seems usable like that.

Once this analyse done I had to recode the ZgatewayBT to be able to analyse hexadecimals data.

The gateway now support mi flora & presence detection!


To follow the test/integration process of the code you can subscribe to this issue.

Next step will be to make some code factoring and why not creating a library dedicated to HM10-11 for arduino and esp8266!


Xiaomi and Mi Flora are registered trademarks of BEIJING XIAOMI TECHNOLOGY CO., LTD.


Commentaires

Posts les plus consultés de ce blog

433toMQTTto433 - Bidirectional ESP8266 NodeMCU gateway between RF 433Mhz signal and MQTT

The goal  is to act as a gateway between 433Mhz sensors and a MQTT broker or between the MQTT broker and 433Mhz actuators, It enables to:
receive MQTT data from a topic and send RF 433Mhz signal corresponding to the received MQTT data publish MQTT data to a different topic related to received 433Mhz signal 
It can be an interesting part in an home automation system so as to interface sensors and actuators (wall sockets) with software like openhab.

List of compatible sensors here

The interest of putting this gateway to an ESP8266 and not on a raspberry pi is to be able to manage security actions at gateway level (power on a siren, cut power to certain devices) following RF data received by sensors without being dependent to the PI for security related actions.

[EDIT] all infos are now centralized into the github repository take a look at it you will find up to date info about OpenMQTTGateway

You need:

Software:

MosquittoArduino IDE latest version (tested ok with 1.6.10)esp8266 board added to t…

Infrared IR, 433mhz and MQTT on ESP8266 bidirectional gateway OpenMQTTGateway

Following discussions on the home assistant forum people gave me the idea to add Infrared communication to the 433mhz gateway. 

The goal is to act as a gateway between 433Mhz sensors, infrared remote controls and a MQTT broker or between the MQTT broker and 433Mhz actuators, infrared devices, It enables to:
receive MQTT data from a topic and send RF 433Mhz signal corresponding to the received MQTT data publish MQTT data to a different topic related to received 433Mhz signal receive MQTT data from a topic and send infrared signal corresponding to the received MQTT data publish MQTT data to a different topic related to received infrared signal 
It can be an interesting part in an home automation system so as to interface sensors and actuators (wall sockets), your tv, home cinema, hifi ... with software like openhab or home assistant.

List of compatible RF sensors here

[EDIT] all infos are now centralized into the github repository take a look at it you will find up to date info about OpenMQT…

433toMQTTto433 - Bidirectional Arduino gateway between RF 433Mhz signal and MQTT

The goal of the Arduino 433toMQTTto433 is to act as a gateway between 433Mhz sensors and a MQTT broker or between the MQTT broker and 433Mhz actuators, It enables to:
receive MQTT data from a topic and send RF 433Mhz signal corresponding to the received MQTT data publish MQTT data to a different topic related to received 433Mhz signal 
It can be an interesting part in an home automation system so as to interface sensors and actuators with software like openhab.

The interest of putting this gateway to an arduino and not on a raspberry pi is to be able to manage security actions at arduino level (power on a siren, cut power to certain devices) following RF data received by sensors without being dependent to the PI for security related actions.

[EDIT] all infos are now centralized into the github repository take a look at it you will find up to date info about OpenMQTTGateway

You need:
Arduino UNO W5100 Ethernet shield 433Mhz Receiver XD RF 5V and transmitter FS1000A 
Transmitter VCC must be p…