Skip to content

Commit 76f880d

Browse files
authored
Add support for Mokosmart beacons. (#1003)
1 parent 706262c commit 76f880d

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

docs/prerequisites/devices.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ Added to that it retrieves the measures from the devices below. By default the d
4646
| Thermobeacon|WS02|temperature/humidity/volt|
4747
| ATorch Battery Capacity Monitor (c)|DT24|volt/amp/watt|
4848
| Eddystone TLM|protocol|temperature/count/volt/time|
49+
| Mokosmart (1)|M1|x_axis/y_axis/z_axis/battery|
50+
| Mokosmart (1)|H4|temperature/humidity/volt|
4951

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

main/ZgatewayBT.ino

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,10 +1117,21 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
11171117
BLEdevice* device = getDeviceByMac(mac);
11181118
if (BLEdata.containsKey("servicedata")) {
11191119
Log.trace(F("Checking BLE service data validity" CR));
1120+
const char* service_uuid = (const char*)BLEdata["servicedatauuid"];
11201121
const char* service_data = (const char*)(BLEdata["servicedata"] | "");
11211122
int service_len = strlen(service_data);
11221123
if (valid_service_data(service_data, service_len)) {
11231124
Log.trace(F("Searching BLE device data %s size %d" CR), service_data, strlen(service_data));
1125+
Log.trace(F("Is it a mokoBeacon?" CR));
1126+
if (strcmp(service_uuid, "0xff01") == NULL) {
1127+
createOrUpdateDevice(mac, device_flags_init, MOKOBEACON);
1128+
return process_mokobeacon(BLEdata);
1129+
}
1130+
Log.trace(F("Is it a mokoBeaconX Pro?" CR));
1131+
if (strcmp(service_uuid, "0xfeab") == NULL) {
1132+
createOrUpdateDevice(mac, device_flags_init, MOKOBEACONXPRO);
1133+
return process_mokobeaconXPro(BLEdata);
1134+
}
11241135
Log.trace(F("Is it a mi flora ?" CR));
11251136
if (strstr(service_data, "209800") != NULL) {
11261137
Log.trace(F("mi flora data reading" CR));
@@ -1664,6 +1675,60 @@ JsonObject& process_ws02(JsonObject& BLEdata) {
16641675
return BLEdata;
16651676
}
16661677

1678+
JsonObject& process_mokobeacon(JsonObject& BLEdata) {
1679+
const char* servicedata = BLEdata["servicedata"].as<const char*>();
1680+
1681+
long battery = value_from_hex_data(servicedata, 0, 2, false);
1682+
int x_axis = (int)value_from_hex_data(servicedata, 14, 4, false);
1683+
int y_axis = (int)value_from_hex_data(servicedata, 18, 4, false);
1684+
int z_axis = (int)value_from_hex_data(servicedata, 22, 4, false);
1685+
1686+
BLEdata.set("x_axis", x_axis);
1687+
BLEdata.set("y_axis", y_axis);
1688+
BLEdata.set("z_axis", z_axis);
1689+
BLEdata.set("batt", battery);
1690+
1691+
return BLEdata;
1692+
}
1693+
1694+
JsonObject& process_mokobeaconXPro(JsonObject& BLEdata) {
1695+
const char* servicedata = BLEdata["servicedata"].as<const char*>();
1696+
int length = strlen(servicedata);
1697+
1698+
if (length >= 24) {
1699+
if (strncmp(servicedata, "40", 2) == NULL) {
1700+
double voltage = (double)value_from_hex_data(servicedata, 6, 4, false) / 1000;
1701+
BLEdata.set("volt", (double)voltage);
1702+
1703+
} else if (strncmp(servicedata, "60", 2) == NULL) {
1704+
int x_axis = (int)value_from_hex_data(servicedata, 12, 4, false);
1705+
int y_axis = (int)value_from_hex_data(servicedata, 16, 4, false);
1706+
int z_axis = (int)value_from_hex_data(servicedata, 20, 4, false);
1707+
if (length > 24) {
1708+
double voltage = (double)value_from_hex_data(servicedata, 24, 4, false) / 1000;
1709+
BLEdata.set("volt", (double)voltage);
1710+
}
1711+
1712+
BLEdata.set("x_axis", x_axis);
1713+
BLEdata.set("y_axis", y_axis);
1714+
BLEdata.set("z_axis", z_axis);
1715+
return BLEdata;
1716+
1717+
} else if (strncmp(servicedata, "70", 2) == NULL) {
1718+
double temperature = (double)value_from_hex_data(servicedata, 6, 4, false) / 10;
1719+
double humidity = (double)value_from_hex_data(servicedata, 10, 4, false) / 10;
1720+
double voltage = (double)value_from_hex_data(servicedata, 14, 4, false) / 1000;
1721+
1722+
BLEdata.set("tempc", (double)temperature);
1723+
BLEdata.set("tempf", (double)convertTemp_CtoF(temperature));
1724+
BLEdata.set("hum", (double)humidity);
1725+
BLEdata.set("volt", (double)voltage);
1726+
return BLEdata;
1727+
}
1728+
}
1729+
return BLEdata;
1730+
}
1731+
16671732
void hass_presence(JsonObject& HomePresence) {
16681733
int BLErssi = HomePresence["rssi"];
16691734
Log.trace(F("BLErssi %d" CR), BLErssi);

main/config_BT.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ enum ble_sensor_model {
152152
IBT4XS,
153153
DT24,
154154
EDDYSTONE_TLM,
155+
MOKOBEACON,
156+
MOKOBEACONXPRO,
155157
GENERIC,
156158
};
157159

0 commit comments

Comments
 (0)