Skip to content

Commit 90f4299

Browse files
authored
Add miflora battery (#992)
1 parent 2708858 commit 90f4299

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

docs/prerequisites/devices.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@ Note that for the moment RF, RF2 and Pilight can not be activated on the same bo
1313
![boards](../img/OpenMQTTGateway_devices_rf3.png ':size=250%')
1414

1515
## For BLE devices
16-
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.
16+
OpenMQTTGateway is able to scan all the BLE devices that advertise their data so as to do presence detection.
17+
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.
1718

1819
|Devices|Model|Measurements|
1920
|-|:-:|:-:|
2021
| BLE watches with fixed mac||rssi for presence detection|
2122
| BLE beacons keychains||rssi for presence detection|
2223
| Vegtrug ||temperature/moisture/luminance/fertility|
23-
| XIAOMI Mi Flora |HHCCJCY01HHCC|temperature/moisture/luminance/fertility|
24+
| XIAOMI Mi Flora |HHCCJCY01HHCC|temperature/moisture/luminance/fertility/battery(1)(c)|
2425
| XIAOMI Mi Jia |LYWSDCGO|temperature/humidity/battery|
25-
| XIAOMI Mi Jia 2 (1)|LYWSD03MMC|temperature/humidity/battery/volt|
26+
| XIAOMI Mi Jia 2 (1)(c)|LYWSD03MMC|temperature/humidity/battery/volt|
2627
| XIAOMI Mi Jia 2 custom firmware (2)|LYWSD03MMC ATC|temperature/humidity/battery/volt|
2728
| XIAOMI Mi Jia 2 custom firmware (3)|LYWSD03MMC PVVX|temperature/humidity/battery/volt|
28-
| XIAOMI MHO-C401 (1)|MHO-C401|temperature/humidity/battery/volt|
29+
| XIAOMI MHO-C401 (1)(c)|MHO-C401|temperature/humidity/battery/volt|
2930
| XIAOMI Mi Lamp |MUE4094RT|presence|
3031
| HONEYWELL |JQJCY01YM|formaldehyde/temperature/humidity/battery|
3132
| 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
4344
| XIAOMI Mi band (1)||steps|
4445
| iNode Energy Meter (1)||power/energy/battery|
4546
| Thermobeacon|WS02|temperature/humidity/volt|
46-
| ATorch Battery Capacity Monitor|DT24|volt/amp/watt|
47+
| ATorch Battery Capacity Monitor (c)|DT24|volt/amp/watt|
4748
| Eddystone TLM|protocol|temperature/count/volt/time|
4849

4950
Exhaustive list [here](https://compatible.openmqttgateway.com/index.php/devices/ble-devices/)

main/ZgatewayBLEConnect.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,14 @@ class GENERIC_connect : public zBLEConnect {
4545
GENERIC_connect(NimBLEAddress& addr) : zBLEConnect(addr) {}
4646
};
4747

48+
class HHCCJCY01HHCC_connect : public zBLEConnect {
49+
std::vector<uint8_t> m_data;
50+
void notifyCB(NimBLERemoteCharacteristic* pChar, uint8_t* pData, size_t length, bool isNotify);
51+
52+
public:
53+
HHCCJCY01HHCC_connect(NimBLEAddress& addr) : zBLEConnect(addr) {}
54+
void publishData() override;
55+
};
56+
4857
#endif //ESP32
4958
#endif //zBLEConnect_h

main/ZgatewayBLEConnect.ino

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,5 +253,38 @@ void DT24_connect::publishData() {
253253
}
254254
}
255255

256+
/*-----------------------HHCCJCY01HHCC HANDLING-----------------------*/
257+
void HHCCJCY01HHCC_connect::publishData() {
258+
NimBLEUUID serviceUUID("00001204-0000-1000-8000-00805f9b34fb");
259+
NimBLEUUID charUUID("00001a00-0000-1000-8000-00805f9b34fb");
260+
NimBLEUUID charUUID2("00001a02-0000-1000-8000-00805f9b34fb");
261+
NimBLERemoteCharacteristic* pChar = getCharacteristic(serviceUUID, charUUID);
262+
263+
if (pChar) {
264+
Log.trace(F("Read mode" CR));
265+
uint8_t buf[2] = {0xA0, 0x1F};
266+
pChar->writeValue(buf, 2, true);
267+
int batteryValue = -1;
268+
NimBLERemoteCharacteristic* pChar2 = getCharacteristic(serviceUUID, charUUID2);
269+
if (pChar2) {
270+
std::string value;
271+
value = pChar2->readValue();
272+
const char* val2 = value.c_str();
273+
batteryValue = val2[0];
274+
JsonObject& BLEdata = getBTJsonObject();
275+
String mac_address = m_pClient->getPeerAddress().toString().c_str();
276+
mac_address.toUpperCase();
277+
BLEdata.set("model", "HHCCJCY01HHCC");
278+
BLEdata.set("id", (char*)mac_address.c_str());
279+
BLEdata.set("batt", (int)batteryValue);
280+
pubBT(BLEdata);
281+
} else {
282+
Log.notice(F("Failed getting characteristic" CR));
283+
}
284+
} else {
285+
Log.notice(F("Failed getting characteristic" CR));
286+
}
287+
}
288+
256289
# endif //ZgatewayBT
257290
#endif //ESP32

main/ZgatewayBT.ino

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static bool oneWhite = false;
8484
int minRssi = abs(MinimumRSSI); //minimum rssi value
8585

8686
void pubBTMainCore(JsonObject& data, bool haPresenceEnabled = true) {
87-
if (abs((int)data["rssi"] | 0) < minRssi) {
87+
if (abs((int)data["rssi"] | 0) < minRssi && data.containsKey("id")) {
8888
String mac_address = data["id"].as<const char*>();
8989
mac_address.replace(":", "");
9090
String mactopic = subjectBTtoMQTT + String("/") + mac_address;
@@ -750,6 +750,11 @@ void BLEconnect() {
750750
case GENERIC: {
751751
GENERIC_connect BLEclient(addr);
752752
BLEclient.processActions(BLEactions);
753+
}
754+
case HHCCJCY01HHCC: {
755+
HHCCJCY01HHCC_connect BLEclient(addr);
756+
BLEclient.processActions(BLEactions);
757+
BLEclient.publishData();
753758
break;
754759
}
755760
default:
@@ -1114,7 +1119,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
11141119
Log.trace(F("mi flora data reading" CR));
11151120
BLEdata.set("model", "HHCCJCY01HHCC");
11161121
if (device->sensorModel == -1)
1117-
createOrUpdateDevice(mac, device_flags_init, HHCCJCY01HHCC);
1122+
createOrUpdateDevice(mac, device_flags_connect, HHCCJCY01HHCC);
11181123
return process_sensors(2, BLEdata);
11191124
}
11201125
Log.trace(F("Is it a vegtrug ?" CR));

0 commit comments

Comments
 (0)