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...
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? :
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 :
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.
is there any practical way for understanding the hex values?
RépondreSupprimerYou can use this tool:
Supprimerhttps://www.binaryhexconverter.com/hex-to-decimal-converter
https://i.hizliresim.com/mMvO01.png
SupprimerI try to getting value from miflora by Arduino, hm-10. According to value of miflora, I manage somethings. I am looking for automate the hex converting. Of course the hex value has some meaning. I believe that there should be practical way understanding the data, like python project https://github.com/open-homeautomation/miflora. thank you
For example, why "Flower Care" is meaningful but others are not?
SupprimerIf you look at Openmqttgateway code file zgatewaybt.ino it do it out of the box for arduino with hm10
SupprimerI am sorry for occupy you. I am new. As I learn the meaning of mqtt, I don't need any network connection for now, so I dont need any mqtt gateway. Am I right?
SupprimerI try to parse zgatewaybt.ino code, there are some points I cant understand. It is my mistake. I am sorry.
I cant find detailed documentation about using zgatewaybt.ino
Supprimerhow should I give meaning the line https://github.com/1technophile/OpenMQTTGateway/blob/master/ZgatewayBT.ino#L200
Supprimeri think it is main idea.
I download the github project OpenMqttGateway. I put the library on the proper files. I use Arduino IDE. It is last version. When I compile the openmqttgateway.ino I take a lot of errors like "OpenMQTTGateway.ino:154:48: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]". after that, I also try to use platformio but the result is the same. What should I do? What is my mistake?
RépondreSupprimerReally Thank you.
If you are only getting warnings it should not block you. My recommendation for the moment is to stay with arduino IDE (until I port the project to platform.io)
SupprimerHello, when I assign the hex data to a String by openmqttgateway, the String overflow. I also try char array. but the "lastindexof","substring" functions are not available for char array. How did you exceed the problem? I use arduino uno.
RépondreSupprimerHello, Did you think on working with a board with larger memory like MEGA. Or maybe you would have a simpler way by using an ESP32
SupprimerI succeed. Thank you sir.
SupprimerCe commentaire a été supprimé par l'auteur.
RépondreSupprimerHi. I tried with AT+DISA? but I realized that most of the time the HM-10 module can't detect the Xiaomi Flora. Are you facing the similar problem?
RépondreSupprimer