Support or Enquiry :

+91- 8820042010 , +91- 9874986677,  Skype id: euphern

Mi Flora Plant Sensor integration – Ionic Framework

Mi Flora Plant Sensor integration – Ionic Framework

Mi Flora Firmware Version : 2.6.7

 

The Xiaomi Mi plant sensor is a well-made plant sensor that does not only measure the humidity, but also fertility, temperature and environment light. Pretty cool for a small device like this. And even cooler is that it uses Bluetooth Low energy for communication with your mobile device. This should make it easily usable.

 

There are a lots of tutorial for using Mi Flora device in python but there are hardly one or two descriptions for using with mobile devices. So we did a little Research and found out that it is quite easy and can be used for many kind of beautiful mobile apps.

 

Here is the descriptions about what we did :

[* please note that this code is tested for Android Devices only]

 

First we Checked on Ubuntu using gattool ,what data are being sent from the mi flora device

 

handle = 0x0002, char properties = 0x02, char value handle = 0x0003, uuid = 00002a00-0000-1000-8000-00805f9b34fb

handle = 0x0004, char properties = 0x02, char value handle = 0x0005, uuid = 00002a01-0000-1000-8000-00805f9b34fb

handle = 0x0006, char properties = 0x0a, char value handle = 0x0007, uuid = 00002a02-0000-1000-8000-00805f9b34fb

handle = 0x0008, char properties = 0x02, char value handle = 0x0009, uuid = 00002a04-0000-1000-8000-00805f9b34fb

handle = 0x000d, char properties = 0x22, char value handle = 0x000e, uuid = 00002a05-0000-1000-8000-00805f9b34fb

handle = 0x0011, char properties = 0x1a, char value handle = 0x0012, uuid = 00000001-0000-1000-8000-00805f9b34fb

handle = 0x0014, char properties = 0x02, char value handle = 0x0015, uuid = 00000002-0000-1000-8000-00805f9b34fb

handle = 0x0016, char properties = 0x12, char value handle = 0x0017, uuid = 00000004-0000-1000-8000-00805f9b34fb

handle = 0x0018, char properties = 0x08, char value handle = 0x0019, uuid = 00000007-0000-1000-8000-00805f9b34fb

handle = 0x001a, char properties = 0x08, char value handle = 0x001b, uuid = 00000010-0000-1000-8000-00805f9b34fb

handle = 0x001c, char properties = 0x0a, char value handle = 0x001d, uuid = 00000013-0000-1000-8000-00805f9b34fb

handle = 0x001e, char properties = 0x02, char value handle = 0x001f, uuid = 00000014-0000-1000-8000-00805f9b34fb

handle = 0x0020, char properties = 0x10, char value handle = 0x0021, uuid = 00001001-0000-1000-8000-00805f9b34fb

handle = 0x0024, char properties = 0x0a, char value handle = 0x0025, uuid = 8082caa8-41a6-4021-91c6-56f9b954cc34

handle = 0x0026, char properties = 0x0a, char value handle = 0x0027, uuid = 724249f0-5ec3-4b5f-8804-42345af08651

handle = 0x0028, char properties = 0x02, char value handle = 0x0029, uuid = 6c53db25-47a1-45fe-a022-7c92fb334fd4

handle = 0x002a, char properties = 0x0a, char value handle = 0x002b, uuid = 9d84b9a3-000c-49d8-9183-855b673fda31

handle = 0x002c, char properties = 0x0e, char value handle = 0x002d, uuid = 457871e8-d516-4ca1-9116-57d0b17b9cb2

handle = 0x002e, char properties = 0x12, char value handle = 0x002f, uuid = 5f78df94-798c-46f5-990a-b3eb6a065c88

handle = 0x0032, char properties = 0x0a, char value handle = 0x0033, uuid = 00001a00-0000-1000-8000-00805f9b34fb

handle = 0x0034, char properties = 0x1a, char value handle = 0x0035, uuid = 00001a01-0000-1000-8000-00805f9b34fb

handle = 0x0037, char properties = 0x02, char value handle = 0x0038, uuid = 00001a02-0000-1000-8000-00805f9b34fb

handle = 0x003b, char properties = 0x02, char value handle = 0x003c, uuid = 00001a11-0000-1000-8000-00805f9b34fb

handle = 0x003d, char properties = 0x1a, char value handle = 0x003e, uuid = 00001a10-0000-1000-8000-00805f9b34fb

handle = 0x0040, char properties = 0x02, char value handle = 0x0041, uuid = 00001a12-0000-1000-8000-00805f9b34fb

 

 

 

Looks like some standard characteristics

 

(the UUID’s starting with 00002) and a lot of non-standard. Let’s check the standard characteristics first.

UUID : 00002a00-0000-1000-8000-00805f9b34fb

 

should contain the device name:

 

“70 108 111 119 101 114 32 99 97 114 101” is “Flower care” in ASCII. Seems that Xiaomi is using the standards

 

 

Flora plant sensor integration

 


[How do you know that this UUID contains the name? Check out the
list of GATT characteristics on the Bluetooth web site.]

 

Ok, let’s have a look at all characteristics that return values:

 

0x03 : 160823-164329 : 46 6c 6f 77 65 72 20 6d 61 74 65

0x05 : 160823-164329 : 00 00

0x07 : 160823-164329 : 00

0x09 : 160823-164329 : 0a 00 14 00 00 00 f4 01

0x0e : 160823-164329 : 01 00 ff ff

0x12 : 160823-164329 : c3 c8 fd 30

0x15 : 160823-164329 : 98 00

0x17 : 160823-164329 : 1f 8e 8e 13 86 dd a0 d8 52 66

0x1d : 160823-164329 : 4c cc ca 13 fc fa f7 a6 51 50 c6 85 ee 61 85 47 7f 3d d6 6b

0x1f : 160823-164329 : 2e a1 bc 3e b3 87 94 e9 68 6f ff b7

0x2f : 160823-164329 : 00

0x33 : 160823-164329 : aa bb

0x35 : 160823-164329 : f5 00 00 00 00 00 00 10 61 00 00 00 00 00 00 00

0x38 : 160823-164329 : 64 10 32 2e 36 2e 32

0x3c : 160823-164329 : aa bb cc dd ee ff 99 88 77 66 55 44 33 22 11 10

0x3e : 160823-164329 : aa bb cc

0x41 : 160823-164329 : 81 8d 23 00

 

So these are lots of data but we need only some of them.

If we consider the handles to read or write data the only handle we need to work with are :

 


0x03 -> to get the name of the ble device
0x038 -> to get the firmware version and the battery level of the device

0x33 -> to write “A01F” in the device so that receiver device can read other data from the Mi Flora device.

0x35 -> To get the Temperature, moisture, light, conductivity data from the mi flora device.

 

Flora plant sensor integration

 

But In case of ionic the problem is we can not use this handle to read or write data from or to the ble devices.

 

The solution is we need to install Cordova and Ionic Native plugins:

$ ionic cordova plugin add cordova-plugin-ble-central

$ npm install –save @ionic-native/ble

 

[for more info about ionic native ble plugins please visit this site:

 

https://ionicframework.com/docs/native/ble/]

 

in case of ionic we need to first scan for the ble devices:

ble.startScan([],

        function(device){

       //for each device we can get the name,id

});

          }

        },

        function(err){

          alert(‘Scanning failed. Please try again.’);

        }

      );

 

 

 

After getting the id of mi flora device we can connect and get the list of services and characteristics
the available list of services and characteristics are as follows:

 

{“characteristics”:[{“characteristic”:”2a00″,”service”:”1800″,”properties”:[“Read”]},{“characteristic”:”2a01″,”service”:”1800″,”properties”:[“Read”]},{“characteristic”:”2a02″,”service”:”1800″,”properties”:[“Read”,”Write”]},{“characteristic”:”2a04″,”service”:”1800″,”properties”:[“Read”]},{“descriptors”:[{“uuid”:”2902″}],”characteristic”:”2a05″,”service”:”1801″,”properties”:[“Read”,”Indicate”]},{“descriptors”:[{“uuid”:”2902″}],”characteristic”:”0001″,”service”:”fe95″,”properties”:[“Read”,”Write”,”Notify”]},{“characteristic”:”0002″,”service”:”fe95″,”properties”:[“Read”]},{“characteristic”:”0004″,”service”:”fe95″,”properties”:[“Read”,”Notify”]},{“characteristic”:”0007″,”service”:”fe95″,”properties”:[“Write”]},{“characteristic”:”0010″,”service”:”fe95″,”properties”:[“Write”]},{“characteristic”:”0013″,”service”:”fe95″,”properties”:[“Read”,”Write”]},{“characteristic”:”0014″,”service”:”fe95″,”properties”:[“Read”]},{“descriptors”:[{“uuid”:”2902″}],”characteristic”:”1001″,”service”:”fe95″,”properties”:[“Notify”]},{“characteristic”:”8082caa8-41a6-4021-91c6-56f9b954cc34″,”service”:”fef5″,”properties”:[“Read”,”Write”]},{“characteristic”:”724249f0-5ec3-4b5f-8804-42345af08651″,”service”:”fef5″,”properties”:[“Read”,”Write”]},{“characteristic”:”6c53db25-47a1-45fe-a022-7c92fb334fd4″,”service”:”fef5″,”properties”:[“Read”]},{“characteristic”:”9d84b9a3-000c-49d8-9183-855b673fda31″,”service”:”fef5″,”properties”:[“Read”,”Write”]},{“characteristic”:”457871e8-d516-4ca1-9116-57d0b17b9cb2″,”service”:”fef5″,”properties”:[“Read”,”WriteWithoutResponse”,”Write”]},{“descriptors”:[{“uuid”:”2902″}],”characteristic”:”5f78df94-798c-46f5-990a-b3eb6a065c88″,”service”:”fef5″,”properties”:[“Read”,”Notify”]},{“characteristic”:”1a00″,”service”:”1204″,”properties”:[“Read”,”Write”]},{“descriptors”:[{“uuid”:”2902″}],”characteristic”:”1a01″,”service”:”1204″,”properties”:[“Read”,”Write”,”Notify”]},{“descriptors”:[{“uuid”:”1a02″}],”characteristic”:”1a02″,”service”:”1204″,”properties”:[“Read”]},{“characteristic”:”1a11″,”service”:”1206″,”properties”:[“Read”]},{“descriptors”:[{“uuid”:”2902″}],”characteristic”:”1a10″,”service”:”1206″,”properties”:[“Read”,”Write”,”Notify”]},{“descriptors”:[{“uuid”:”1a12″}],”characteristic”:”1a12″,”service”:”1206″,”properties”:[“Read”]}],”advertising”:{},”id”:”C4:7C:8D:63:81:E2″,”services”:[“1800″,”1801″,”fe95″,”fef5″,”1204″,”1206″],”rssi”:-55,”name”:”Flower care”}

 

 

 

 

These are the massive data which are not in a good shape but we need only services and characteristics value from here. So I we filter and sort out the raw date we get something like this:

 

{‘1801’: [‘2a05’], ‘1206’: [‘1a11’, ‘1a10’, ‘1a12’], ‘fe95’: [‘0001’, ‘0002’, ‘0004’, ‘0007’, ‘0010’, ‘0013’, ‘0014’, ‘1001’], ‘1800’: [‘2a00’, ‘2a01’, ‘2a02’, ‘2a04’], ‘fef5’: [‘8082caa8-41a6-4021-91c6-56f9b954cc34’, ‘724249f0-5ec3-4b5f-8804-42345af08651’, ‘6c53db25-47a1-45fe-a022-7c92fb334fd4’, ‘9d84b9a3-000c-49d8-9183-855b673fda31’, ‘457871e8-d516-4ca1-9116-57d0b17b9cb2’, ‘5f78df94-798c-46f5-990a-b3eb6a065c88’], ‘1204’: [‘1a00’, ‘1a01’, ‘1a02’]}

 

 

So the services are 1801,1206,fe95 …

 

And the value of the service keys in this dictionary are the list of characteristics . if we can go slightly up while using handle value to get data we can see that for handle 0x33,0x35,0x38 the uuid are :
1a00,1a01 and 1a02 so the service will be 1204.

 

for reading the data from the sensor we can use following template code [*remember we are only getting the light, moisture, temperature and conductivity data from this code ..to get name and firmware version please change to according service and characteristic id ]

 

ble.connect(id,function(res){

    var id1 = res.id;

    var data = new Uint8Array([0xA0,0x1F]).buffer;

    ble.write(id1, ‘1204’, ‘1A00’, data, function(res){

     ble.read(id1,’1204′,’1A01′,function(buffer){

      var data = new Uint8Array(buffer);

      $scope.fdata.temp = (data[1] * 256 + data[0]) / 10;

      $scope.fdata.moist = data[7];

      $scope.fdata.light = data[4] * 256 + data[3];

      $scope.fdata.conductivity = data[9] * 256 + data[8];

      $ionicLoading.hide();

    },function(reason) {

    })

   },function(error){

   })

  },function(error){

  })

 

The ble.connect function takes the id of the ble device as the first parameter which is stored in a variable named “id”

 

The second parameter is a function which is called if the mobile device is successfully connected with the mi flora device

 

and the third parameter is a error function which is called if any error occurs while trying to connect to the mi flora device

 

In the success function of ble.connect [ which is the second parameter of the function] first we try to write some data to the ble devices so that we can get the valid data from the device

 

And in ble.read we try to read the data from ble device.

 

After successfully getting the data from device we try to format in readable structure so that we can work with the data.

 

Do you want Mi Flora Plant Sensor Integration with your app? Please let us know