From 82c7d0c7812195bda4c728d767956b492b1acb13 Mon Sep 17 00:00:00 2001 From: Florian <1technophile@users.noreply.github.com> Date: Fri, 1 Nov 2019 10:25:10 +0100 Subject: [PATCH] Miband steps (#478) add mi band steps reading --- main/ZgatewayBT.ino | 58 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/main/ZgatewayBT.ino b/main/ZgatewayBT.ino index ff52d00..181f5b8 100644 --- a/main/ZgatewayBT.ino +++ b/main/ZgatewayBT.ino @@ -249,6 +249,33 @@ void MiScaleDiscovery(char * mac){ devices.push_back(device); } +void MiBandDiscovery(char * mac){ + #define MiBandparametersCount 1 + trc(F("MiBandDiscovery")); + char * MiBandsensor[MiBandparametersCount][8] = { + {"sensor", "MiBand-steps", mac, "steps","{{ value_json.steps | is_defined }}","", "", "nb"} , + //component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement + }; + + for (int i=0;i(),"fe95") != NULL){ //Mi FLora, Mi jia, Cleargrass, LYWDS02 trc("Processing BLE device data"); @@ -375,6 +402,14 @@ void MiScaleDiscovery(char * mac){ #endif process_scale_v2(service_data,mac); } + if (strstr(BLEdata["servicedatauuid"].as(),"fee0") != NULL){ // Mi Band //0000fee0-0000-1000-8000-00805f9b34fb + trc(F("Mi Band data reading")); + //example "servicedata":a21e0000 + #ifdef ZmqttDiscovery + if(!isDiscovered(mac)) MiBandDiscovery(mac); + #endif + process_miband(service_data,mac); + } } }else{ pub((char *)mactopic.c_str(),BLEdata); // publish device even if there is no service data @@ -720,6 +755,27 @@ bool process_scale_v2(char * rest_data, char * mac_adress){ return true; } +bool process_miband(char * rest_data, char * mac_adress){ + //example "servicedata":"a21e0000" + trc("rest_data"); + trc(rest_data); + + trc(F("Creating BLE buffer")); + StaticJsonBuffer jsonBuffer; + JsonObject& BLEdata = jsonBuffer.createObject(); + + double steps = value_from_service_data(rest_data, 0, 4); + + //Set Json value + BLEdata.set("steps", (double)steps); + + // Publish weight + String mactopic(mac_adress); + mactopic = subjectBTtoMQTT + mactopic; + pub((char *)mactopic.c_str(),BLEdata); + return true; +} + #ifdef subjectHomePresence void haRoomPresence(JsonObject& HomePresence){ int BLErssi = HomePresence["rssi"];