diff --git a/docs/prerequisites/devices.md b/docs/prerequisites/devices.md index 7503bb8..0386c49 100644 --- a/docs/prerequisites/devices.md +++ b/docs/prerequisites/devices.md @@ -13,19 +13,20 @@ Note that for the moment RF, RF2 and Pilight can not be activated on the same bo ![boards](../img/OpenMQTTGateway_devices_rf3.png ':size=250%') ## For BLE devices -OpenMQTTGateway is able to scan all the BLE devices that advertise their data so as to do presence detection. Added to that it can retrieve the measures from the devices below. +OpenMQTTGateway is able to scan all the BLE devices that advertise their data so as to do presence detection. +Added to that it retrieves the measures from the devices below. By default the data are read from the advertisements (no impact on device battery life). When a (c) is present after the model name, this means that the gateway connects to it so as to retrieve data. For some devices we may connect only to retrieve one or several parameters (the rest being advertised), in this case the (c) is placed with the parameter. |Devices|Model|Measurements| |-|:-:|:-:| | BLE watches with fixed mac||rssi for presence detection| | BLE beacons keychains||rssi for presence detection| | Vegtrug ||temperature/moisture/luminance/fertility| -| XIAOMI Mi Flora |HHCCJCY01HHCC|temperature/moisture/luminance/fertility| +| XIAOMI Mi Flora |HHCCJCY01HHCC|temperature/moisture/luminance/fertility/battery(1)(c)| | XIAOMI Mi Jia |LYWSDCGO|temperature/humidity/battery| -| XIAOMI Mi Jia 2 (1)|LYWSD03MMC|temperature/humidity/battery/volt| +| XIAOMI Mi Jia 2 (1)(c)|LYWSD03MMC|temperature/humidity/battery/volt| | XIAOMI Mi Jia 2 custom firmware (2)|LYWSD03MMC ATC|temperature/humidity/battery/volt| | XIAOMI Mi Jia 2 custom firmware (3)|LYWSD03MMC PVVX|temperature/humidity/battery/volt| -| XIAOMI MHO-C401 (1)|MHO-C401|temperature/humidity/battery/volt| +| XIAOMI MHO-C401 (1)(c)|MHO-C401|temperature/humidity/battery/volt| | XIAOMI Mi Lamp |MUE4094RT|presence| | HONEYWELL |JQJCY01YM|formaldehyde/temperature/humidity/battery| | INKBIRD (1)|IBS-TH1|temperature/humidity/battery| @@ -43,7 +44,7 @@ OpenMQTTGateway is able to scan all the BLE devices that advertise their data so | XIAOMI Mi band (1)||steps| | iNode Energy Meter (1)||power/energy/battery| | Thermobeacon|WS02|temperature/humidity/volt| -| ATorch Battery Capacity Monitor|DT24|volt/amp/watt| +| ATorch Battery Capacity Monitor (c)|DT24|volt/amp/watt| | Eddystone TLM|protocol|temperature/count/volt/time| Exhaustive list [here](https://compatible.openmqttgateway.com/index.php/devices/ble-devices/) diff --git a/main/ZgatewayBLEConnect.h b/main/ZgatewayBLEConnect.h index 3ac1221..12f42da 100644 --- a/main/ZgatewayBLEConnect.h +++ b/main/ZgatewayBLEConnect.h @@ -45,5 +45,14 @@ public: GENERIC_connect(NimBLEAddress& addr) : zBLEConnect(addr) {} }; +class HHCCJCY01HHCC_connect : public zBLEConnect { + std::vector m_data; + void notifyCB(NimBLERemoteCharacteristic* pChar, uint8_t* pData, size_t length, bool isNotify); + +public: + HHCCJCY01HHCC_connect(NimBLEAddress& addr) : zBLEConnect(addr) {} + void publishData() override; +}; + #endif //ESP32 #endif //zBLEConnect_h diff --git a/main/ZgatewayBLEConnect.ino b/main/ZgatewayBLEConnect.ino index 18cd07e..fc8ecad 100644 --- a/main/ZgatewayBLEConnect.ino +++ b/main/ZgatewayBLEConnect.ino @@ -253,5 +253,38 @@ void DT24_connect::publishData() { } } +/*-----------------------HHCCJCY01HHCC HANDLING-----------------------*/ +void HHCCJCY01HHCC_connect::publishData() { + NimBLEUUID serviceUUID("00001204-0000-1000-8000-00805f9b34fb"); + NimBLEUUID charUUID("00001a00-0000-1000-8000-00805f9b34fb"); + NimBLEUUID charUUID2("00001a02-0000-1000-8000-00805f9b34fb"); + NimBLERemoteCharacteristic* pChar = getCharacteristic(serviceUUID, charUUID); + + if (pChar) { + Log.trace(F("Read mode" CR)); + uint8_t buf[2] = {0xA0, 0x1F}; + pChar->writeValue(buf, 2, true); + int batteryValue = -1; + NimBLERemoteCharacteristic* pChar2 = getCharacteristic(serviceUUID, charUUID2); + if (pChar2) { + std::string value; + value = pChar2->readValue(); + const char* val2 = value.c_str(); + batteryValue = val2[0]; + JsonObject& BLEdata = getBTJsonObject(); + String mac_address = m_pClient->getPeerAddress().toString().c_str(); + mac_address.toUpperCase(); + BLEdata.set("model", "HHCCJCY01HHCC"); + BLEdata.set("id", (char*)mac_address.c_str()); + BLEdata.set("batt", (int)batteryValue); + pubBT(BLEdata); + } else { + Log.notice(F("Failed getting characteristic" CR)); + } + } else { + Log.notice(F("Failed getting characteristic" CR)); + } +} + # endif //ZgatewayBT #endif //ESP32 diff --git a/main/ZgatewayBT.ino b/main/ZgatewayBT.ino index c8b36cf..88917c1 100644 --- a/main/ZgatewayBT.ino +++ b/main/ZgatewayBT.ino @@ -84,7 +84,7 @@ static bool oneWhite = false; int minRssi = abs(MinimumRSSI); //minimum rssi value void pubBTMainCore(JsonObject& data, bool haPresenceEnabled = true) { - if (abs((int)data["rssi"] | 0) < minRssi) { + if (abs((int)data["rssi"] | 0) < minRssi && data.containsKey("id")) { String mac_address = data["id"].as(); mac_address.replace(":", ""); String mactopic = subjectBTtoMQTT + String("/") + mac_address; @@ -750,6 +750,11 @@ void BLEconnect() { case GENERIC: { GENERIC_connect BLEclient(addr); BLEclient.processActions(BLEactions); + } + case HHCCJCY01HHCC: { + HHCCJCY01HHCC_connect BLEclient(addr); + BLEclient.processActions(BLEactions); + BLEclient.publishData(); break; } default: @@ -1114,7 +1119,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) { Log.trace(F("mi flora data reading" CR)); BLEdata.set("model", "HHCCJCY01HHCC"); if (device->sensorModel == -1) - createOrUpdateDevice(mac, device_flags_init, HHCCJCY01HHCC); + createOrUpdateDevice(mac, device_flags_connect, HHCCJCY01HHCC); return process_sensors(2, BLEdata); } Log.trace(F("Is it a vegtrug ?" CR));