Update to use ArduinoJson 6+ (#1071)
This commit is contained in:
1 parent
149712b573
commit
ed4949f769
30 files changed
+452
-430
No files matched your search
@@ -204,7 +204,7 @@ void MQTTtoPWM(char* topicOri, JsonObject& jsonData) {
|
||||
for (int i = 0; i < kNumChannels; ++i) {
|
||||
fadeStartValues[i] = currentValues[i];
|
||||
JsonVariant value = jsonData[channelJsonKeys[i]];
|
||||
if (value.success()) {
|
||||
if (!value.isNull()) {
|
||||
float targetValue = value.as<float>();
|
||||
targetValue = min(targetValue, 1.f);
|
||||
targetValue = max(targetValue, 0.f);
|
||||
@@ -219,7 +219,7 @@ void MQTTtoPWM(char* topicOri, JsonObject& jsonData) {
|
||||
}
|
||||
// ...unless there is a "fade" value in the JSON
|
||||
JsonVariant fade = jsonData["fade"];
|
||||
if (fade.success()) {
|
||||
if (!fade.isNull()) {
|
||||
// "fade" json value is in seconds. Convert to milliseconds
|
||||
long endUpdateTime = currentUpdateTime + (long)(fade.as<float>() * (1000.f));
|
||||
// Set the fadeEndUpdateTime for the channels that were modified in the JSON
|
||||
@@ -236,7 +236,7 @@ void MQTTtoPWM(char* topicOri, JsonObject& jsonData) {
|
||||
char key[64];
|
||||
snprintf(key, sizeof(key), "gamma-%s", channelJsonKeys[i]);
|
||||
JsonVariant value = jsonData[key];
|
||||
if (value.success()) {
|
||||
if (!value.isNull()) {
|
||||
float gamma = value.as<float>();
|
||||
// Sanity check
|
||||
gamma = min(gamma, 4.f);
|
||||
@@ -245,12 +245,12 @@ void MQTTtoPWM(char* topicOri, JsonObject& jsonData) {
|
||||
}
|
||||
snprintf(key, sizeof(key), "min-%s", channelJsonKeys[i]);
|
||||
value = jsonData[key];
|
||||
if (value.success()) {
|
||||
if (!value.isNull()) {
|
||||
calibrationMinLinear[i] = perceptualToLinear(value.as<float>(), i);
|
||||
}
|
||||
snprintf(key, sizeof(key), "max-%s", channelJsonKeys[i]);
|
||||
value = jsonData[key];
|
||||
if (value.success()) {
|
||||
if (!value.isNull()) {
|
||||
calibrationMaxLinear[i] = perceptualToLinear(value.as<float>(), i);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -80,14 +80,14 @@ bool _2GtoMQTT() {
|
||||
// Get the memory locations of unread SMS messages.
|
||||
unreadSMSNum = A6l.getUnreadSMSLocs(unreadSMSLocs, 512);
|
||||
Log.trace(F("Creating SMS buffer" CR));
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject& SMSdata = jsonBuffer.createObject();
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject SMSdata = jsonBuffer.to<JsonObject>();
|
||||
for (int i = 0; i < unreadSMSNum; i++) {
|
||||
Log.notice(F("New message at index: %d" CR), unreadSMSNum);
|
||||
sms = A6l.readSMS(unreadSMSLocs[i]);
|
||||
SMSdata.set("message", (char*)sms.message.c_str());
|
||||
SMSdata.set("date", (char*)sms.date.c_str());
|
||||
SMSdata.set("phone", (char*)sms.number.c_str());
|
||||
SMSdata["message"] = (const char*)sms.message.c_str();
|
||||
SMSdata["date"] = (const char*)sms.date.c_str();
|
||||
SMSdata["phone"] = (const char*)sms.number.c_str();
|
||||
A6l.deleteSMS(unreadSMSLocs[i]); // we delete the SMS received
|
||||
Log.trace(F("Adv data 2GtoMQTT" CR));
|
||||
pub(subject2GtoMQTT, SMSdata);
|
||||
|
||||
+31
-31
@@ -80,14 +80,14 @@ bool zBLEConnect::processActions(std::vector<BLEAction>& actions) {
|
||||
if (actions.size() > 0) {
|
||||
for (auto& it : actions) {
|
||||
if (NimBLEAddress(it.addr) == m_pClient->getPeerAddress()) {
|
||||
JsonObject& BLEresult = getBTJsonObject();
|
||||
BLEresult.set("id", it.addr);
|
||||
BLEresult.set("service", (char*)it.service.toString().c_str());
|
||||
BLEresult.set("characteristic", (char*)it.characteristic.toString().c_str());
|
||||
JsonObject BLEresult = getBTJsonObject();
|
||||
BLEresult["id"] = it.addr;
|
||||
BLEresult["service"] = (char*)it.service.toString().c_str();
|
||||
BLEresult["characteristic"] = (char*)it.characteristic.toString().c_str();
|
||||
|
||||
if (it.write) {
|
||||
Log.trace(F("processing BLE write" CR));
|
||||
BLEresult.set("write", it.value.c_str());
|
||||
BLEresult["write"] = it.value.c_str();
|
||||
result = writeData(&it);
|
||||
} else {
|
||||
Log.trace(F("processing BLE read" CR));
|
||||
@@ -96,29 +96,29 @@ bool zBLEConnect::processActions(std::vector<BLEAction>& actions) {
|
||||
switch (it.value_type) {
|
||||
case BLE_VAL_HEX: {
|
||||
char* pHex = NimBLEUtils::buildHexData(nullptr, (uint8_t*)it.value.c_str(), it.value.length());
|
||||
BLEresult.set("read", pHex);
|
||||
BLEresult["read"] = pHex;
|
||||
free(pHex);
|
||||
break;
|
||||
}
|
||||
case BLE_VAL_INT: {
|
||||
int ival = *(int*)it.value.data();
|
||||
BLEresult.set<int>("read", ival);
|
||||
BLEresult["read"] = ival;
|
||||
break;
|
||||
}
|
||||
case BLE_VAL_FLOAT: {
|
||||
float fval = *(double*)it.value.data();
|
||||
BLEresult.set<float>("read", fval);
|
||||
BLEresult["read"] = fval;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BLEresult.set("read", it.value.c_str());
|
||||
BLEresult["read"] = it.value.c_str();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
it.complete = true;
|
||||
BLEresult.set("success", result);
|
||||
BLEresult["success"] = result;
|
||||
pubBT(BLEresult);
|
||||
}
|
||||
}
|
||||
@@ -137,25 +137,25 @@ void LYWSD03MMC_connect::notifyCB(NimBLERemoteCharacteristic* pChar, uint8_t* pD
|
||||
|
||||
if (length == 5) {
|
||||
Log.trace(F("Device identified creating BLE buffer" CR));
|
||||
JsonObject& BLEdata = getBTJsonObject();
|
||||
JsonObject BLEdata = getBTJsonObject();
|
||||
String mac_address = m_pClient->getPeerAddress().toString().c_str();
|
||||
mac_address.toUpperCase();
|
||||
for (std::vector<BLEdevice*>::iterator it = devices.begin(); it != devices.end(); ++it) {
|
||||
BLEdevice* p = *it;
|
||||
if ((strcmp(p->macAdr, (char*)mac_address.c_str()) == 0)) {
|
||||
if (p->sensorModel == LYWSD03MMC)
|
||||
BLEdata.set("model", "LYWSD03MMC");
|
||||
BLEdata["model"] = "LYWSD03MMC";
|
||||
else if (p->sensorModel == MHO_C401)
|
||||
BLEdata.set("model", "MHO_C401");
|
||||
BLEdata["model"] = "MHO_C401";
|
||||
}
|
||||
}
|
||||
BLEdata.set("id", (char*)mac_address.c_str());
|
||||
BLEdata["id"] = (char*)mac_address.c_str();
|
||||
Log.trace(F("Device identified in CB: %s" CR), (char*)mac_address.c_str());
|
||||
BLEdata.set("tempc", (float)((pData[0] | (pData[1] << 8)) * 0.01));
|
||||
BLEdata.set("tempf", (float)(convertTemp_CtoF((pData[0] | (pData[1] << 8)) * 0.01)));
|
||||
BLEdata.set("hum", (float)(pData[2]));
|
||||
BLEdata.set("volt", (float)(((pData[4] * 256) + pData[3]) / 1000.0));
|
||||
BLEdata.set("batt", (float)(((((pData[4] * 256) + pData[3]) / 1000.0) - 2.1) * 100));
|
||||
BLEdata["tempc"] = (float)((pData[0] | (pData[1] << 8)) * 0.01);
|
||||
BLEdata["tempf"] = (float)(convertTemp_CtoF((pData[0] | (pData[1] << 8)) * 0.01));
|
||||
BLEdata["hum"] = (float)(pData[2]);
|
||||
BLEdata["volt"] = (float)(((pData[4] * 256) + pData[3]) / 1000.0);
|
||||
BLEdata["batt"] = (float)(((((pData[4] * 256) + pData[3]) / 1000.0) - 2.1) * 100);
|
||||
|
||||
pubBT(BLEdata);
|
||||
} else {
|
||||
@@ -210,16 +210,16 @@ void DT24_connect::notifyCB(NimBLERemoteCharacteristic* pChar, uint8_t* pData, s
|
||||
JsonObject& BLEdata = getBTJsonObject();
|
||||
String mac_address = m_pClient->getPeerAddress().toString().c_str();
|
||||
mac_address.toUpperCase();
|
||||
BLEdata.set("model", "DT24");
|
||||
BLEdata.set("id", (char*)mac_address.c_str());
|
||||
BLEdata["model"] = "DT24";
|
||||
BLEdata["id"] = (char*)mac_address.c_str();
|
||||
Log.trace(F("Device identified in CB: %s" CR), (char*)mac_address.c_str());
|
||||
BLEdata.set("volt", (float)(((m_data[4] * 256 * 256) + (m_data[5] * 256) + m_data[6]) / 10.0));
|
||||
BLEdata.set("current", (float)(((m_data[7] * 256 * 256) + (m_data[8] * 256) + m_data[9]) / 1000.0));
|
||||
BLEdata.set("power", (float)(((m_data[10] * 256 * 256) + (m_data[11] * 256) + m_data[12]) / 10.0));
|
||||
BLEdata.set("energy", (float)(((m_data[13] * 256 * 256 * 256) + (m_data[14] * 256 * 256) + (m_data[15] * 256) + m_data[16]) / 100.0));
|
||||
BLEdata.set("price", (float)(((m_data[17] * 256 * 256) + (m_data[18] * 256) + m_data[19]) / 100.0));
|
||||
BLEdata.set("tempc", (float)(m_data[24] * 256) + m_data[25]);
|
||||
BLEdata.set("tempf", (float)(convertTemp_CtoF((m_data[24] * 256) + m_data[25])));
|
||||
BLEdata["volt"] = (float)(((m_data[4] * 256 * 256) + (m_data[5] * 256) + m_data[6]) / 10.0);
|
||||
BLEdata["current"] = (float)(((m_data[7] * 256 * 256) + (m_data[8] * 256) + m_data[9]) / 1000.0);
|
||||
BLEdata["power"] = (float)(((m_data[10] * 256 * 256) + (m_data[11] * 256) + m_data[12]) / 10.0);
|
||||
BLEdata["energy"] = (float)(((m_data[13] * 256 * 256 * 256) + (m_data[14] * 256 * 256) + (m_data[15] * 256) + m_data[16]) / 100.0);
|
||||
BLEdata["price"] = (float)(((m_data[17] * 256 * 256) + (m_data[18] * 256) + m_data[19]) / 100.0);
|
||||
BLEdata["tempc"] = (float)(m_data[24] * 256) + m_data[25];
|
||||
BLEdata["tempf"] = (float)(convertTemp_CtoF((m_data[24] * 256) + m_data[25]));
|
||||
|
||||
pubBT(BLEdata);
|
||||
} else {
|
||||
@@ -274,9 +274,9 @@ void HHCCJCY01HHCC_connect::publishData() {
|
||||
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);
|
||||
BLEdata["model"] = "HHCCJCY01HHCC";
|
||||
BLEdata["id"] = (char*)mac_address.c_str();
|
||||
BLEdata["batt"] = (int)batteryValue;
|
||||
pubBT(BLEdata);
|
||||
} else {
|
||||
Log.notice(F("Failed getting characteristic" CR));
|
||||
|
||||
+142
-135
@@ -102,15 +102,22 @@ void pubBTMainCore(JsonObject& data, bool haPresenceEnabled = true) {
|
||||
|
||||
class JsonBundle {
|
||||
public:
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> buffer;
|
||||
JsonObject* object;
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> buffer;
|
||||
JsonObject object;
|
||||
bool haPresence;
|
||||
|
||||
JsonObject& createObject(const char* json = NULL, bool haPresenceEnabled = true) {
|
||||
buffer.clear();
|
||||
haPresence = haPresenceEnabled;
|
||||
object = &(json == NULL ? buffer.createObject() : buffer.parseObject(json));
|
||||
return *object;
|
||||
object = buffer.to<JsonObject>();
|
||||
|
||||
if (json != nullptr) {
|
||||
auto error = deserializeJson(buffer, json);
|
||||
if (error) {
|
||||
Log.error(F("deserialize object failed: %s" CR), error.c_str());
|
||||
}
|
||||
}
|
||||
return object;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -161,7 +168,7 @@ void emptyBTQueue() {
|
||||
first = false;
|
||||
}
|
||||
JsonBundle& bundle = jsonBTBufferQueue[next % BTQueueSize];
|
||||
pubBTMainCore(*bundle.object, bundle.haPresence);
|
||||
pubBTMainCore(bundle.object, bundle.haPresence);
|
||||
atomic_store_explicit(&jsonBTBufferQueueNext, (next + 1) % (2 * BTQueueSize), ::memory_order_seq_cst); // use namespace std -> ambiguous error...
|
||||
vTaskDelay(1);
|
||||
}
|
||||
@@ -645,7 +652,7 @@ class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
|
||||
JsonObject& BLEdata = getBTJsonObject();
|
||||
String mac_adress = advertisedDevice->getAddress().toString().c_str();
|
||||
mac_adress.toUpperCase();
|
||||
BLEdata.set("id", (char*)mac_adress.c_str());
|
||||
BLEdata["id"] = (char*)mac_adress.c_str();
|
||||
Log.notice(F("Device detected: %s" CR), (char*)mac_adress.c_str());
|
||||
BLEdevice* device = getDeviceByMac(BLEdata["id"].as<const char*>());
|
||||
|
||||
@@ -658,17 +665,17 @@ class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
|
||||
|
||||
if ((!oneWhite || isWhite(device)) && !isBlack(device)) { //if not black listed mac we go AND if we have no white mac or this mac is white we go out
|
||||
if (advertisedDevice->haveName())
|
||||
BLEdata.set("name", (char*)advertisedDevice->getName().c_str());
|
||||
BLEdata["name"] = (char*)advertisedDevice->getName().c_str();
|
||||
if (advertisedDevice->haveManufacturerData()) {
|
||||
char* manufacturerdata = BLEUtils::buildHexData(NULL, (uint8_t*)advertisedDevice->getManufacturerData().data(), advertisedDevice->getManufacturerData().length());
|
||||
Log.trace(F("Manufacturer Data: %s" CR), manufacturerdata);
|
||||
BLEdata.set("manufacturerdata", manufacturerdata);
|
||||
BLEdata["manufacturerdata"] = manufacturerdata;
|
||||
free(manufacturerdata);
|
||||
}
|
||||
if (advertisedDevice->haveRSSI())
|
||||
BLEdata.set("rssi", (int)advertisedDevice->getRSSI());
|
||||
BLEdata["rssi"] = (int)advertisedDevice->getRSSI();
|
||||
if (advertisedDevice->haveTXPower())
|
||||
BLEdata.set("txpower", (int8_t)advertisedDevice->getTXPower());
|
||||
BLEdata["txpower"] = (int8_t)advertisedDevice->getTXPower();
|
||||
if (advertisedDevice->haveRSSI() && !publishOnlySensors && hassPresence) {
|
||||
hass_presence(BLEdata); // this device has an rssi and we don't want only sensors so in consequence we can use it for home assistant room presence component
|
||||
}
|
||||
@@ -678,10 +685,10 @@ class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
|
||||
for (int j = 0; j < serviceDataCount; j++) {
|
||||
std::string service_data = convertServiceData(advertisedDevice->getServiceData(j));
|
||||
Log.trace(F("Service data: %s" CR), service_data.c_str());
|
||||
BLEdata.set("servicedata", (char*)service_data.c_str());
|
||||
BLEdata["servicedata"] = (char*)service_data.c_str();
|
||||
std::string serviceDatauuid = advertisedDevice->getServiceDataUUID(j).toString();
|
||||
Log.trace(F("Service data UUID: %s" CR), (char*)serviceDatauuid.c_str());
|
||||
BLEdata.set("servicedatauuid", (char*)serviceDatauuid.c_str());
|
||||
BLEdata["servicedatauuid"] = (char*)serviceDatauuid.c_str();
|
||||
process_bledata(BLEdata); // this will force to resolve all the service data
|
||||
}
|
||||
|
||||
@@ -990,7 +997,7 @@ bool BTtoMQTT() {
|
||||
JsonObject& BLEdata = getBTJsonObject();
|
||||
|
||||
Log.trace(F("Id %s" CR), (char*)mac.c_str());
|
||||
BLEdata.set("id", (char*)mac.c_str());
|
||||
BLEdata["id"] = (const char*)mac.c_str();
|
||||
BLEdevice* device = getDeviceByMac((char*)mac.c_str());
|
||||
|
||||
if (isBlack(device))
|
||||
@@ -998,11 +1005,11 @@ bool BTtoMQTT() {
|
||||
if (oneWhite && !isWhite(device))
|
||||
return false; //if we have at least one white mac and this mac is not white we go out
|
||||
|
||||
BLEdata.set("rssi", (int)rssi);
|
||||
BLEdata["rssi"] = (int)rssi;
|
||||
if (!publishOnlySensors && hassPresence)
|
||||
hass_presence(BLEdata); // this device has an rssi and we don't want only sensors so in consequence we can use it for home assistant room presence component
|
||||
Log.trace(F("Service data: %s" CR), restData.c_str());
|
||||
BLEdata.set("servicedata", restData.c_str());
|
||||
BLEdata["servicedata"] = restData.c_str();
|
||||
PublishDeviceData(BLEdata);
|
||||
}
|
||||
}
|
||||
@@ -1127,7 +1134,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
Log.trace(F("Is it a mi flora ?" CR));
|
||||
if (strstr(service_data, "209800") != NULL) {
|
||||
Log.trace(F("mi flora data reading" CR));
|
||||
BLEdata.set("model", "HHCCJCY01HHCC");
|
||||
BLEdata["model"] = "HHCCJCY01HHCC";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_connect, HHCCJCY01HHCC);
|
||||
return process_sensors(2, BLEdata);
|
||||
@@ -1135,7 +1142,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
Log.trace(F("Is it a vegtrug ?" CR));
|
||||
if (service_len > ServicedataMinLength && strstr(service_data, "20bc03") != NULL) {
|
||||
Log.trace(F("vegtrug data reading" CR));
|
||||
BLEdata.set("model", "VEGTRUG");
|
||||
BLEdata["model"] = "VEGTRUG";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_init, VEGTRUG);
|
||||
return process_sensors(2, BLEdata);
|
||||
@@ -1143,7 +1150,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
Log.trace(F("Is it a LYWSDCGQ?" CR));
|
||||
if (service_len > ServicedataMinLength && strstr(service_data, "20aa01") != NULL) {
|
||||
Log.trace(F("LYWSDCGQ data reading" CR));
|
||||
BLEdata.set("model", "LYWSDCGQ");
|
||||
BLEdata["model"] = "LYWSDCGQ";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_init, LYWSDCGQ);
|
||||
return process_sensors(0, BLEdata);
|
||||
@@ -1151,7 +1158,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
Log.trace(F("Is it a JQJCY01YM?" CR));
|
||||
if (service_len > ServicedataMinLength && strstr(service_data, "20df02") != NULL) {
|
||||
Log.trace(F("JQJCY01YM data reading" CR));
|
||||
BLEdata.set("model", "JQJCY01YM");
|
||||
BLEdata["model"] = "JQJCY01YM";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_init, JQJCY01YM);
|
||||
return process_sensors(0, BLEdata);
|
||||
@@ -1159,7 +1166,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
Log.trace(F("Is it a LYWSD02?" CR));
|
||||
if (service_len > ServicedataMinLength && strstr(service_data, "205b04") != NULL) {
|
||||
Log.trace(F("LYWSD02 data reading" CR));
|
||||
BLEdata.set("model", "LYWSD02");
|
||||
BLEdata["model"] = "LYWSD02";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_init, LYWSD02);
|
||||
return process_sensors(2, BLEdata);
|
||||
@@ -1167,7 +1174,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
Log.trace(F("Is it a MUE4094RT?" CR));
|
||||
if (strstr(service_data, "4030dd") != NULL) {
|
||||
Log.trace(F("MUE4094RT data reading" CR));
|
||||
BLEdata.set("model", "MUE4094RT");
|
||||
BLEdata["model"] = "MUE4094RT";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_init, MUE4094RT);
|
||||
return process_milamp(BLEdata);
|
||||
@@ -1175,7 +1182,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
Log.trace(F("Is it a CGP1W?" CR));
|
||||
if (service_len > ServicedataMinLength && strncmp(service_data, "0809", 4) == 0) {
|
||||
Log.trace(F("CGP1W data reading" CR));
|
||||
BLEdata.set("model", "CGP1W");
|
||||
BLEdata["model"] = "CGP1W";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_init, CGP1W);
|
||||
return process_cleargrass(BLEdata, true);
|
||||
@@ -1185,7 +1192,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
// Another type of the advertising packet started with 0807 or 8816
|
||||
if ((service_len > ServicedataMinLength && strncmp(&service_data[2], "4703", 4) == 0) || (strncmp(service_data, "0807", 4) == 0) || (strncmp(service_data, "8816", 4) == 0)) {
|
||||
Log.trace(F("CGG1 data reading" CR));
|
||||
BLEdata.set("model", "CGG1");
|
||||
BLEdata["model"] = "CGG1";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_init, CGG1);
|
||||
return strncmp(&service_data[2], "4703", 4) == 0 ? process_sensors(0, BLEdata) : process_cleargrass(BLEdata, false);
|
||||
@@ -1193,7 +1200,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
Log.trace(F("Is it a CGD1?" CR));
|
||||
if ((service_len > ServicedataMinLength && (strstr(service_data, "080caf") != NULL || strstr(service_data, "080c09") != NULL)) || (service_len > ServicedataMinLength - 6 && strstr(service_data, "080cd0") != NULL)) {
|
||||
Log.trace(F("CGD1 data reading" CR));
|
||||
BLEdata.set("model", "CGD1");
|
||||
BLEdata["model"] = "CGD1";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_init, CGD1);
|
||||
return process_cleargrass(BLEdata, false);
|
||||
@@ -1201,7 +1208,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
Log.trace(F("Is it a CGDK2?" CR));
|
||||
if (service_len > ServicedataMinLength && strncmp(&service_data[0], "8810", 4) == 0) {
|
||||
Log.trace(F("CGDK2 data reading" CR));
|
||||
BLEdata.set("model", "CGDK2");
|
||||
BLEdata["model"] = "CGDK2";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_init, CGDK2);
|
||||
return process_cleargrass(BLEdata, false);
|
||||
@@ -1209,7 +1216,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
Log.trace(F("Is it a CGPR1?" CR));
|
||||
if ((service_len > ServicedataMinLength) && (strncmp(&service_data[0], "4812", 4) == 0 || strncmp(&service_data[0], "0812", 4) == 0)) {
|
||||
Log.trace(F("CGPR1 data reading" CR));
|
||||
BLEdata.set("model", "CGPR1");
|
||||
BLEdata["model"] = "CGPR1";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_init, CGPR1);
|
||||
return process_cgpr1(BLEdata);
|
||||
@@ -1217,7 +1224,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
Log.trace(F("Is it a CGH1?" CR));
|
||||
if (service_len > ServicedataMinLength && (strncmp(&service_data[0], "c804", 4) == 0 || strncmp(&service_data[0], "8804", 4) == 0 || strncmp(&service_data[0], "0804", 4) == 0 || strncmp(&service_data[0], "4804", 4) == 0)) {
|
||||
Log.trace(F("CGH1 data reading" CR));
|
||||
BLEdata.set("model", "CGH1");
|
||||
BLEdata["model"] = "CGH1";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_init, CGH1);
|
||||
return process_cgh1(BLEdata);
|
||||
@@ -1237,7 +1244,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
Log.trace(F("Is it a custom (pvvx) LYWSD03MMC?" CR));
|
||||
if (service_len >= 30 && strncmp(service_data + 6, "38c1a4", 6) == 0) {
|
||||
Log.trace(F("LYWSD03MMC PVVX" CR));
|
||||
BLEdata.set("model", "LYWSD03MMC_PVVX");
|
||||
BLEdata["model"] = "LYWSD03MMC_PVVX";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_init, LYWSD03MMC_PVVX);
|
||||
return process_pvvx(BLEdata);
|
||||
@@ -1245,7 +1252,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
Log.trace(F("Is it a custom (atc1441) LYWSD03MMC?" CR));
|
||||
if (strstr(service_data, "a4c138") != NULL) {
|
||||
Log.trace(F("LYWSD03MMC ATC" CR));
|
||||
BLEdata.set("model", "LYWSD03MMC_ATC");
|
||||
BLEdata["model"] = "LYWSD03MMC_ATC";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_init, LYWSD03MMC_ATC);
|
||||
return process_atc(BLEdata);
|
||||
@@ -1256,7 +1263,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
Log.trace(F("Is it a MiBand?" CR));
|
||||
if (strstr(service_datauuid, "fee0") != NULL) {
|
||||
Log.trace(F("Mi Band data reading" CR));
|
||||
BLEdata.set("model", "MIBAND");
|
||||
BLEdata["model"] = "MIBAND";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_init, MIBAND);
|
||||
return process_miband(BLEdata);
|
||||
@@ -1264,7 +1271,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
Log.trace(F("Is it a XMTZC04HM?" CR));
|
||||
if (strstr(service_datauuid, "181d") != NULL) {
|
||||
Log.trace(F("XMTZC04HM data reading" CR));
|
||||
BLEdata.set("model", "XMTZC04HM");
|
||||
BLEdata["model"] = "XMTZC04HM";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_init, XMTZC04HM);
|
||||
return process_scale_v1(BLEdata);
|
||||
@@ -1272,7 +1279,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
Log.trace(F("Is it a XMTZC05HM?" CR));
|
||||
if (strstr(service_datauuid, "181b") != NULL) {
|
||||
Log.trace(F("XMTZC05HM data reading" CR));
|
||||
BLEdata.set("model", "XMTZC05HM");
|
||||
BLEdata["model"] = "XMTZC05HM";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_init, XMTZC05HM);
|
||||
return process_scale_v2(BLEdata);
|
||||
@@ -1281,7 +1288,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
Log.trace(F("Is it an EddystoneTLM?" CR));
|
||||
if (strncmp(&service_data[0], "20", 2) == 0 && strstr(service_datauuid, "0xfeaa") != NULL) {
|
||||
Log.trace(F("Eddystone TLM" CR));
|
||||
BLEdata.set("model", "EDDYSTONE_TLM");
|
||||
BLEdata["model"] = "EDDYSTONE_TLM";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_init, EDDYSTONE_TLM);
|
||||
return process_eddystonetlm(BLEdata);
|
||||
@@ -1307,7 +1314,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
Log.trace(F("Is it a INKBIRD IBS-TH1?" CR));
|
||||
if (strcmp(name, "sps") == 0) {
|
||||
Log.trace(F("INKBIRD TH1 data reading" CR));
|
||||
BLEdata.set("model", "IBS-TH1");
|
||||
BLEdata["model"] = "IBS-TH1";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_init, IBSTH1);
|
||||
return process_inkbird_th1(BLEdata);
|
||||
@@ -1315,7 +1322,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
Log.trace(F("Is it a INKBIRD IBS-TH2?" CR));
|
||||
if (strcmp(name, "tps") == 0) {
|
||||
Log.trace(F("INKBIRD TH2 data reading" CR));
|
||||
BLEdata.set("model", "IBS-TH2");
|
||||
BLEdata["model"] = "IBS-TH2";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_init, IBSTH2);
|
||||
return process_inkbird_th2(BLEdata);
|
||||
@@ -1323,7 +1330,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
Log.trace(F("Is it a INKBIRD IBT-4XS?" CR));
|
||||
if (strcmp(name, "iBBQ") == 0) {
|
||||
Log.trace(F("INKBIRD IBT-4XS data reading" CR));
|
||||
BLEdata.set("model", "IBT-4XS");
|
||||
BLEdata["model"] = "IBT-4XS";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_init, IBT4XS);
|
||||
return process_inkbird_4xs(BLEdata);
|
||||
@@ -1331,7 +1338,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
Log.trace(F("Is it a DT24?" CR));
|
||||
if (strcmp(name, "DT24-BLE") == 0) {
|
||||
Log.trace(F("DT24 data reading data reading" CR));
|
||||
BLEdata.set("model", "DT24");
|
||||
BLEdata["model"] = "DT24";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_connect, DT24);
|
||||
return BLEdata;
|
||||
@@ -1339,7 +1346,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
Log.trace(F("Is it a TPMS? %u" CR), strlen(manufacturerdata));
|
||||
if (strlen(manufacturerdata) == 36 && strstr(name, "TPMS") != NULL) {
|
||||
Log.trace(F("TPMS data reading" CR));
|
||||
BLEdata.set("model", "TPMS");
|
||||
BLEdata["model"] = "TPMS";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_init, TPMS);
|
||||
return process_tpms(BLEdata);
|
||||
@@ -1348,7 +1355,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
Log.trace(F("Is it a iNode Energy Meter?" CR));
|
||||
if (strlen(manufacturerdata) == 26 && ((long)value_from_hex_data(manufacturerdata, 0, 4, true) & 0xFFF9) == 0x8290) {
|
||||
Log.trace(F("iNode Energy Meter data reading" CR));
|
||||
BLEdata.set("model", "INODE_EM");
|
||||
BLEdata["model"] = "INODE_EM";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_init, INODE_EM);
|
||||
return process_inode_em(BLEdata);
|
||||
@@ -1356,7 +1363,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
Log.trace(F("Is it a WS02?" CR));
|
||||
if (strlen(manufacturerdata) >= 40 && (strstr(manufacturerdata, "100000001a11") != NULL)) {
|
||||
Log.trace(F("WS02 data reading data reading" CR));
|
||||
BLEdata.set("model", "WS02");
|
||||
BLEdata["model"] = "WS02";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_init, WS02);
|
||||
return process_ws02(BLEdata);
|
||||
@@ -1364,7 +1371,7 @@ JsonObject& process_bledata(JsonObject& BLEdata) {
|
||||
Log.trace(F("Is it an iBeacon? %u" CR), strlen(manufacturerdata));
|
||||
if (strlen(manufacturerdata) == 50 && strncmp(&manufacturerdata[0], "4c00", 4) == NULL) {
|
||||
Log.trace(F("iBeacon data reading" CR));
|
||||
BLEdata.set("model", "IBEACON");
|
||||
BLEdata["model"] = "IBEACON";
|
||||
if (device->sensorModel == -1)
|
||||
createOrUpdateDevice(mac, device_flags_init, IBEACON);
|
||||
return process_ibeacon(BLEdata);
|
||||
@@ -1403,35 +1410,35 @@ JsonObject& process_sensors(int offset, JsonObject& BLEdata) {
|
||||
// following the value of digit 23 + offset we determine the type of data we get from the sensor
|
||||
switch (servicedata[23 + offset]) {
|
||||
case '0':
|
||||
BLEdata.set("for", (double)value / 100);
|
||||
BLEdata["for"] = (double)value / 100;
|
||||
break;
|
||||
case '4':
|
||||
BLEdata.set("tempc", (double)value / 10);
|
||||
BLEdata.set("tempf", (double)convertTemp_CtoF(value / 10));
|
||||
BLEdata["tempc"] = (double)value / 10;
|
||||
BLEdata["tempf"] = (double)convertTemp_CtoF(value / 10);
|
||||
break;
|
||||
case '6':
|
||||
BLEdata.set("hum", (double)value / 10);
|
||||
BLEdata["hum"] = (double)value / 10;
|
||||
break;
|
||||
case '7':
|
||||
BLEdata.set("lux", (double)value);
|
||||
BLEdata["lux"] = (double)value;
|
||||
break;
|
||||
case '8':
|
||||
BLEdata.set("moi", (double)value);
|
||||
BLEdata["moi"] = (double)value;
|
||||
break;
|
||||
case '9':
|
||||
BLEdata.set("fer", (double)value);
|
||||
BLEdata["fer"] = (double)value;
|
||||
break;
|
||||
case 'a':
|
||||
BLEdata.set("batt", (double)value);
|
||||
BLEdata["batt"] = (double)value;
|
||||
break;
|
||||
case 'd':
|
||||
// temperature
|
||||
value = (double)value_from_hex_data(servicedata, 28 + offset, 4, true);
|
||||
BLEdata.set("tempc", (double)value / 10);
|
||||
BLEdata.set("tempf", (double)convertTemp_CtoF(value / 10));
|
||||
BLEdata["tempc"], (double)value / 10;
|
||||
BLEdata["tempf"], (double)convertTemp_CtoF(value / 10);
|
||||
// humidity
|
||||
value = (double)value_from_hex_data(servicedata, 32 + offset, 4, true);
|
||||
BLEdata.set("hum", (double)value / 10);
|
||||
BLEdata["hum"] = (double)value / 10;
|
||||
break;
|
||||
default:
|
||||
Log.trace(F("can't read values" CR));
|
||||
@@ -1447,15 +1454,15 @@ JsonObject& process_scale_v1(JsonObject& BLEdata) {
|
||||
double weight = 0;
|
||||
if (servicedata[1] == '2') { //kg
|
||||
weight = (double)value_from_hex_data(servicedata, 2, 4, true) / 200;
|
||||
BLEdata.set("unit", "kg");
|
||||
BLEdata["unit"] = "kg";
|
||||
} else if (servicedata[1] == '3') { //lbs
|
||||
weight = (double)value_from_hex_data(servicedata, 2, 4, true) / 100;
|
||||
BLEdata.set("unit", "lbs");
|
||||
BLEdata["unit"] = "lbs";
|
||||
} else { //unknown unit
|
||||
BLEdata.set("unit", "unknown");
|
||||
BLEdata["unit"] = "unknown";
|
||||
}
|
||||
//Set Json value
|
||||
BLEdata.set("weight", (double)weight);
|
||||
BLEdata["weight"] = (double)weight;
|
||||
}
|
||||
|
||||
return BLEdata;
|
||||
@@ -1467,18 +1474,18 @@ JsonObject& process_scale_v2(JsonObject& BLEdata) {
|
||||
double weight = 0;
|
||||
if (servicedata[1] == '2') { //kg
|
||||
weight = (double)value_from_hex_data(servicedata, 22, 4, true) / 200;
|
||||
BLEdata.set("unit", "kg");
|
||||
BLEdata["unit"] = "kg";
|
||||
} else if (servicedata[1] == '3') { //lbs
|
||||
weight = (double)value_from_hex_data(servicedata, 22, 4, true) / 100;
|
||||
BLEdata.set("unit", "lbs");
|
||||
BLEdata["unit"] = "lbs";
|
||||
} else { //unknown unit
|
||||
BLEdata.set("unit", "unknown");
|
||||
BLEdata["unit"] = "unknown";
|
||||
}
|
||||
double impedance = (double)value_from_hex_data(servicedata, 18, 4, true);
|
||||
|
||||
//Set Json values
|
||||
BLEdata.set("weight", (double)weight);
|
||||
BLEdata.set("impedance", (double)impedance);
|
||||
BLEdata["weight"] = (double)weight;
|
||||
BLEdata["impedance"] = (double)impedance;
|
||||
|
||||
return BLEdata;
|
||||
}
|
||||
@@ -1486,11 +1493,11 @@ JsonObject& process_scale_v2(JsonObject& BLEdata) {
|
||||
JsonObject& process_eddystonetlm(JsonObject& BLEdata) {
|
||||
const char* servicedata = BLEdata["servicedata"].as<const char*>();
|
||||
|
||||
BLEdata.set("volt", (float)value_from_hex_data(servicedata, 4, 4, false) / 1000);
|
||||
BLEdata.set("tempc", (float)value_from_hex_data(servicedata, 8, 2, false));
|
||||
BLEdata.set("tempf", (float)convertTemp_CtoF(value_from_hex_data(servicedata, 8, 2, false)));
|
||||
BLEdata.set("count", value_from_hex_data(servicedata, 12, 8, false));
|
||||
BLEdata.set("time", value_from_hex_data(servicedata, 20, 8, false) / 100);
|
||||
BLEdata["volt"] = (float)value_from_hex_data(servicedata, 4, 4, false) / 1000;
|
||||
BLEdata["tempc"] = (float)value_from_hex_data(servicedata, 8, 2, false);
|
||||
BLEdata["tempf"] = (float)convertTemp_CtoF(value_from_hex_data(servicedata, 8, 2, false));
|
||||
BLEdata["count"] = value_from_hex_data(servicedata, 12, 8, false);
|
||||
BLEdata["time"] = value_from_hex_data(servicedata, 20, 8, false) / 100;
|
||||
|
||||
return BLEdata;
|
||||
}
|
||||
@@ -1503,10 +1510,10 @@ JsonObject& process_inkbird_th1(JsonObject& BLEdata) {
|
||||
double battery = (double)value_from_hex_data(manufacturerdata, 14, 2, true);
|
||||
|
||||
//Set Json values
|
||||
BLEdata.set("tempc", (double)temperature);
|
||||
BLEdata.set("tempf", (double)convertTemp_CtoF(temperature));
|
||||
BLEdata.set("hum", (double)humidity);
|
||||
BLEdata.set("batt", (double)battery);
|
||||
BLEdata["tempc"] = (double)temperature;
|
||||
BLEdata["tempf"] = (double)convertTemp_CtoF(temperature);
|
||||
BLEdata["hum"] = (double)humidity;
|
||||
BLEdata["batt"] = (double)battery;
|
||||
|
||||
return BLEdata;
|
||||
}
|
||||
@@ -1518,9 +1525,9 @@ JsonObject& process_inkbird_th2(JsonObject& BLEdata) {
|
||||
double battery = (double)value_from_hex_data(manufacturerdata, 14, 2, true);
|
||||
|
||||
//Set Json values
|
||||
BLEdata.set("tempc", (double)temperature);
|
||||
BLEdata.set("tempf", (double)convertTemp_CtoF(temperature));
|
||||
BLEdata.set("batt", (double)battery);
|
||||
BLEdata["tempc"] = (double)temperature;
|
||||
BLEdata["tempf"] = (double)convertTemp_CtoF(temperature);
|
||||
BLEdata["batt"] = (double)battery;
|
||||
|
||||
return BLEdata;
|
||||
}
|
||||
@@ -1534,14 +1541,14 @@ JsonObject& process_inkbird_4xs(JsonObject& BLEdata) {
|
||||
double temperature4 = (double)value_from_hex_data(manufacturerdata, 32, 4, true) / 10;
|
||||
|
||||
//Set Json values
|
||||
BLEdata.set("tempc", (double)temperature);
|
||||
BLEdata.set("tempf", (double)convertTemp_CtoF(temperature));
|
||||
BLEdata.set("tempc2", (double)temperature2);
|
||||
BLEdata.set("tempf2", (double)convertTemp_CtoF(temperature2));
|
||||
BLEdata.set("tempc3", (double)temperature3);
|
||||
BLEdata.set("tempf3", (double)convertTemp_CtoF(temperature3));
|
||||
BLEdata.set("tempc4", (double)temperature4);
|
||||
BLEdata.set("tempf4", (double)convertTemp_CtoF(temperature4));
|
||||
BLEdata["tempc"] = (double)temperature;
|
||||
BLEdata["tempf"] = (double)convertTemp_CtoF(temperature);
|
||||
BLEdata["tempc2"] = (double)temperature2;
|
||||
BLEdata["tempf2"] = (double)convertTemp_CtoF(temperature2);
|
||||
BLEdata["tempc3"] = (double)temperature3;
|
||||
BLEdata["tempf3"] = (double)convertTemp_CtoF(temperature3);
|
||||
BLEdata["tempc4"] = (double)temperature4;
|
||||
BLEdata["tempf4"] = (double)convertTemp_CtoF(temperature4);
|
||||
|
||||
return BLEdata;
|
||||
}
|
||||
@@ -1552,7 +1559,7 @@ JsonObject& process_miband(JsonObject& BLEdata) {
|
||||
double steps = (double)value_from_hex_data(servicedata, 0, 4, true);
|
||||
|
||||
//Set Json value
|
||||
BLEdata.set("steps", (double)steps);
|
||||
BLEdata["steps"] = (double)steps;
|
||||
|
||||
return BLEdata;
|
||||
}
|
||||
@@ -1563,8 +1570,8 @@ JsonObject& process_milamp(JsonObject& BLEdata) {
|
||||
long darkness = (double)value_from_hex_data(servicedata, 8, 2, true);
|
||||
|
||||
//Set Json value
|
||||
BLEdata.set("presence", (bool)"true");
|
||||
BLEdata.set("darkness", (long)darkness);
|
||||
BLEdata["presence"] = (bool)"true";
|
||||
BLEdata["darkness"] = (long)darkness;
|
||||
|
||||
return BLEdata;
|
||||
}
|
||||
@@ -1575,15 +1582,15 @@ JsonObject& process_cleargrass(JsonObject& BLEdata, boolean air) {
|
||||
double value = 9999;
|
||||
// temperature
|
||||
value = (double)value_from_hex_data(servicedata, 20, 4, true);
|
||||
BLEdata.set("tempc", (double)value / 10);
|
||||
BLEdata.set("tempf", (double)convertTemp_CtoF(value / 10));
|
||||
BLEdata["tempc"] = (double)value / 10;
|
||||
BLEdata["tempf"] = (double)convertTemp_CtoF(value / 10);
|
||||
// humidity
|
||||
value = (double)value_from_hex_data(servicedata, 24, 4, true);
|
||||
BLEdata.set("hum", (double)value / 10);
|
||||
BLEdata["hum"] = (double)value / 10;
|
||||
if (air) {
|
||||
// air pressure
|
||||
value = (double)value_from_hex_data(servicedata, 32, 4, true);
|
||||
BLEdata.set("pres", (double)value / 100);
|
||||
BLEdata["pres"] = (double)value / 100;
|
||||
}
|
||||
|
||||
return BLEdata;
|
||||
@@ -1595,13 +1602,13 @@ JsonObject& process_cgpr1(JsonObject& BLEdata) {
|
||||
if (strncmp(&servicedata[0], "0812", 4) == 0) { // lux
|
||||
value = value_from_hex_data(servicedata, 33, 4, true);
|
||||
if (value >= 0)
|
||||
BLEdata.set("lux", value);
|
||||
BLEdata["lux"] = value;
|
||||
} else if (strncmp(&servicedata[0], "4812", 4) == 0) { // presence
|
||||
value = value_from_hex_data(servicedata, 21, 1, false);
|
||||
if (value == 0)
|
||||
BLEdata.set("pres", false);
|
||||
BLEdata["pres"] = false;
|
||||
if (value == 1)
|
||||
BLEdata.set("pres", true);
|
||||
BLEdata["pres"] = true;
|
||||
}
|
||||
|
||||
return BLEdata;
|
||||
@@ -1617,9 +1624,9 @@ JsonObject& process_cgh1(JsonObject& BLEdata) {
|
||||
}
|
||||
|
||||
if (value == 0)
|
||||
BLEdata.set("open", true);
|
||||
BLEdata["open"] = true;
|
||||
if (value == 1)
|
||||
BLEdata.set("open", false);
|
||||
BLEdata["open"] = false;
|
||||
|
||||
return BLEdata;
|
||||
}
|
||||
@@ -1633,11 +1640,11 @@ JsonObject& process_atc(JsonObject& BLEdata) {
|
||||
double voltage = (double)value_from_hex_data(servicedata, 20, 4, false) / 1000;
|
||||
|
||||
//Set Json values
|
||||
BLEdata.set("tempc", (double)temperature);
|
||||
BLEdata.set("tempf", (double)convertTemp_CtoF(temperature));
|
||||
BLEdata.set("hum", (double)humidity);
|
||||
BLEdata.set("batt", (double)battery);
|
||||
BLEdata.set("volt", (double)voltage);
|
||||
BLEdata["tempc"] = (double)temperature;
|
||||
BLEdata["tempf"] = (double)convertTemp_CtoF(temperature);
|
||||
BLEdata["hum"] = (double)humidity;
|
||||
BLEdata["batt"] = (double)battery;
|
||||
BLEdata["volt"] = (double)voltage;
|
||||
|
||||
return BLEdata;
|
||||
}
|
||||
@@ -1651,11 +1658,11 @@ JsonObject& process_pvvx(JsonObject& BLEdata) {
|
||||
double voltage = (double)value_from_hex_data(servicedata, 20, 4, true) / 1000;
|
||||
|
||||
//Set Json values
|
||||
BLEdata.set("tempc", (double)temperature);
|
||||
BLEdata.set("tempf", (double)convertTemp_CtoF(temperature));
|
||||
BLEdata.set("hum", (double)humidity);
|
||||
BLEdata.set("batt", (double)battery);
|
||||
BLEdata.set("volt", (double)voltage);
|
||||
BLEdata["tempc"] = (double)temperature;
|
||||
BLEdata["tempf"] = (double)convertTemp_CtoF(temperature);
|
||||
BLEdata["hum"] = (double)humidity;
|
||||
BLEdata["batt"] = (double)battery;
|
||||
BLEdata["volt"] = (double)voltage;
|
||||
|
||||
return BLEdata;
|
||||
}
|
||||
@@ -1669,9 +1676,9 @@ JsonObject& process_inode_em(JsonObject& BLEdata) {
|
||||
long battery = ((value_from_hex_data(manufacturerdata, 20, 2, true) >> 4) - 2) * 10;
|
||||
|
||||
//Set Json values
|
||||
BLEdata.set("power", (double)power);
|
||||
BLEdata.set("energy", (double)energy);
|
||||
BLEdata.set("batt", battery);
|
||||
BLEdata["power"] = (double)power;
|
||||
BLEdata["energy"] = (double)energy;
|
||||
BLEdata["batt"] = battery;
|
||||
|
||||
return BLEdata;
|
||||
}
|
||||
@@ -1684,10 +1691,10 @@ JsonObject& process_ws02(JsonObject& BLEdata) {
|
||||
double voltage = (double)value_from_hex_data(manufacturerdata, 16, 4, true) / 1000;
|
||||
|
||||
//Set Json values
|
||||
BLEdata.set("tempc", (double)temperature);
|
||||
BLEdata.set("tempf", (double)convertTemp_CtoF(temperature));
|
||||
BLEdata.set("hum", (double)humidity);
|
||||
BLEdata.set("volt", (double)voltage);
|
||||
BLEdata["tempc"] = (double)temperature;
|
||||
BLEdata["tempf"] = (double)convertTemp_CtoF(temperature);
|
||||
BLEdata["hum"] = (double)humidity;
|
||||
BLEdata["volt"] = (double)voltage;
|
||||
|
||||
return BLEdata;
|
||||
}
|
||||
@@ -1700,10 +1707,10 @@ JsonObject& process_mokobeacon(JsonObject& BLEdata) {
|
||||
int y_axis = (int)value_from_hex_data(servicedata, 18, 4, false);
|
||||
int z_axis = (int)value_from_hex_data(servicedata, 22, 4, false);
|
||||
|
||||
BLEdata.set("x_axis", x_axis);
|
||||
BLEdata.set("y_axis", y_axis);
|
||||
BLEdata.set("z_axis", z_axis);
|
||||
BLEdata.set("batt", battery);
|
||||
BLEdata["x_axis"] = x_axis;
|
||||
BLEdata["y_axis"] = y_axis;
|
||||
BLEdata["z_axis"] = z_axis;
|
||||
BLEdata["batt"] = battery;
|
||||
|
||||
return BLEdata;
|
||||
}
|
||||
@@ -1715,7 +1722,7 @@ JsonObject& process_mokobeaconXPro(JsonObject& BLEdata) {
|
||||
if (length >= 24) {
|
||||
if (strncmp(servicedata, "40", 2) == NULL) {
|
||||
double voltage = (double)value_from_hex_data(servicedata, 6, 4, false) / 1000;
|
||||
BLEdata.set("volt", (double)voltage);
|
||||
BLEdata["volt"] = (double)voltage;
|
||||
|
||||
} else if (strncmp(servicedata, "60", 2) == NULL) {
|
||||
int x_axis = (int)value_from_hex_data(servicedata, 12, 4, false);
|
||||
@@ -1723,12 +1730,12 @@ JsonObject& process_mokobeaconXPro(JsonObject& BLEdata) {
|
||||
int z_axis = (int)value_from_hex_data(servicedata, 20, 4, false);
|
||||
if (length > 24) {
|
||||
double voltage = (double)value_from_hex_data(servicedata, 24, 4, false) / 1000;
|
||||
BLEdata.set("volt", (double)voltage);
|
||||
BLEdata["volt"] = (double)voltage;
|
||||
}
|
||||
|
||||
BLEdata.set("x_axis", x_axis);
|
||||
BLEdata.set("y_axis", y_axis);
|
||||
BLEdata.set("z_axis", z_axis);
|
||||
BLEdata["x_axis"] = x_axis;
|
||||
BLEdata["y_axis"] = y_axis;
|
||||
BLEdata["z_axis"] = z_axis;
|
||||
return BLEdata;
|
||||
|
||||
} else if (strncmp(servicedata, "70", 2) == NULL) {
|
||||
@@ -1736,10 +1743,10 @@ JsonObject& process_mokobeaconXPro(JsonObject& BLEdata) {
|
||||
double humidity = (double)value_from_hex_data(servicedata, 10, 4, false) / 10;
|
||||
double voltage = (double)value_from_hex_data(servicedata, 14, 4, false) / 1000;
|
||||
|
||||
BLEdata.set("tempc", (double)temperature);
|
||||
BLEdata.set("tempf", (double)convertTemp_CtoF(temperature));
|
||||
BLEdata.set("hum", (double)humidity);
|
||||
BLEdata.set("volt", (double)voltage);
|
||||
BLEdata["tempc"] = (double)temperature;
|
||||
BLEdata["tempf"] = (double)convertTemp_CtoF(temperature);
|
||||
BLEdata["hum"] = (double)humidity;
|
||||
BLEdata["volt"] = (double)voltage;
|
||||
return BLEdata;
|
||||
}
|
||||
}
|
||||
@@ -1752,11 +1759,11 @@ JsonObject& process_ibeacon(JsonObject& BLEdata) {
|
||||
char proxUUID[33] = {NULL};
|
||||
strncpy(&mfid[0], manufacturerdata, 4);
|
||||
strncpy(&proxUUID[0], manufacturerdata + 8, 32);
|
||||
BLEdata.set("mfid", mfid);
|
||||
BLEdata.set("uuid", proxUUID);
|
||||
BLEdata.set("major", (uint16_t)value_from_hex_data(manufacturerdata, 40, 4, false, false));
|
||||
BLEdata.set("minor", (uint16_t)value_from_hex_data(manufacturerdata, 44, 4, false, false));
|
||||
BLEdata.set("power", (int8_t)value_from_hex_data(manufacturerdata, 48, 4, false));
|
||||
BLEdata["mfid"] = mfid;
|
||||
BLEdata["uuid"] = proxUUID;
|
||||
BLEdata["major"] = (uint16_t)value_from_hex_data(manufacturerdata, 40, 4, false, false);
|
||||
BLEdata["minor"] = (uint16_t)value_from_hex_data(manufacturerdata, 44, 4, false, false);
|
||||
BLEdata["power"] = (int8_t)value_from_hex_data(manufacturerdata, 48, 4, false);
|
||||
|
||||
return BLEdata;
|
||||
}
|
||||
@@ -1770,15 +1777,15 @@ JsonObject& process_tpms(JsonObject& BLEdata) {
|
||||
int battery = (int)value_from_hex_data(manufacturerdata, 32, 2, true);
|
||||
int alarm = (int)value_from_hex_data(manufacturerdata, 35, 1, false);
|
||||
|
||||
BLEdata.set("count", (int)(id + 1));
|
||||
BLEdata.set("pres", (double)pressure);
|
||||
BLEdata.set("tempc", (double)temperature);
|
||||
BLEdata.set("tempf", (double)convertTemp_CtoF(temperature));
|
||||
BLEdata.set("batt", (int)battery);
|
||||
BLEdata["count"] = (int)id + 1;
|
||||
BLEdata["pres"] = (double)pressure;
|
||||
BLEdata["tempc"] = (double)temperature;
|
||||
BLEdata["tempf"] = (double)convertTemp_CtoF(temperature);
|
||||
BLEdata["batt"] = (int)battery;
|
||||
if (alarm == 1)
|
||||
BLEdata.set("alarm", true);
|
||||
BLEdata["alarm"] = true;
|
||||
if (alarm == 0)
|
||||
BLEdata.set("alarm", false);
|
||||
BLEdata["alarm"] = false;
|
||||
|
||||
return BLEdata;
|
||||
}
|
||||
|
||||
@@ -30,33 +30,33 @@
|
||||
GfSun2000 GF = GfSun2000();
|
||||
|
||||
void GFSunInverterDataHandler(GfSun2000Data data) {
|
||||
StaticJsonBuffer<2 * JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject& jdata = jsonBuffer.createObject();
|
||||
StaticJsonDocument<2 * JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject jdata = jsonBuffer.to<JsonObject>();
|
||||
|
||||
jdata.set("device_id", (char*)data.deviceID);
|
||||
jdata["device_id"] = (char*)data.deviceID;
|
||||
Log.trace(F("Device ID : %s\n" CR), data.deviceID);
|
||||
jdata.set("ac_voltage", data.ACVoltage);
|
||||
jdata["ac_voltage"] = data.ACVoltage;
|
||||
Log.trace(F("AC Voltage : %.1f\tV\n" CR), data.ACVoltage);
|
||||
jdata.set("dc_voltage", data.DCVoltage);
|
||||
jdata["dc_voltage"] = data.DCVoltage;
|
||||
Log.trace(F("DC Voltage : %.1f\tV\n" CR), data.DCVoltage);
|
||||
jdata.set("power", data.averagePower);
|
||||
jdata["power"] = data.averagePower;
|
||||
Log.trace(F("Output Power : %.1f\tW (5min avg)\n" CR), data.averagePower);
|
||||
jdata.set("c_energy", data.customEnergyCounter);
|
||||
jdata["c_energy"] = data.customEnergyCounter;
|
||||
Log.trace(F("Custom Energy : %.1f\tkW/h (can be reseted)\n" CR), data.customEnergyCounter);
|
||||
jdata.set("t_energy", data.totalEnergyCounter);
|
||||
jdata["t_energy"] = data.totalEnergyCounter;
|
||||
Log.trace(F("Total Energy : %.1f\tkW/h\n" CR), data.totalEnergyCounter);
|
||||
|
||||
# ifdef GFSUNINVERTER_DEVEL
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer2;
|
||||
JsonObject& jregister = jsonBuffer2.createObject();
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer2;
|
||||
JsonObject jregister = jsonBuffer2.to<JsonObject>();
|
||||
char buffer[4];
|
||||
std::map<int16_t, int16_t>::iterator itr;
|
||||
for (itr = data.modbusRegistry.begin(); itr != data.modbusRegistry.end(); ++itr) {
|
||||
Log.notice("%d: %d\n", itr->first, itr->second);
|
||||
sprintf(buffer, "%d", itr->first);
|
||||
jregister.set(buffer, itr->second);
|
||||
jregister[buffer] = itr->second;
|
||||
}
|
||||
jdata.set("register", jregister);
|
||||
jdata["register"] = jregister;
|
||||
# endif
|
||||
pub(subjectRFtoMQTT, jdata);
|
||||
}
|
||||
@@ -65,11 +65,11 @@ void GFSunInverterErrorHandler(int errorId, char* errorMessage) {
|
||||
char buffer[50];
|
||||
sprintf(buffer, "Error response: %02X - %s\n", errorId, errorMessage);
|
||||
Log.error(buffer);
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject& jdata = jsonBuffer.createObject();
|
||||
jdata.set("status", "error");
|
||||
jdata.set("msg", errorMessage);
|
||||
jdata.set("id", errorId);
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject jdata = jsonBuffer.to<JsonObject>();
|
||||
jdata["status"] = "error";
|
||||
jdata["msg"] = errorMessage;
|
||||
jdata["id"] = errorId;
|
||||
pub(subjectRFtoMQTT, jdata);
|
||||
}
|
||||
|
||||
|
||||
+10
-10
@@ -115,20 +115,20 @@ void IRtoMQTT() {
|
||||
|
||||
if (irrecv.decode(&results)) {
|
||||
Log.trace(F("Creating IR buffer" CR));
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject& IRdata = jsonBuffer.createObject();
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject IRdata = jsonBuffer.to<JsonObject>();
|
||||
|
||||
Log.trace(F("Rcv. IR" CR));
|
||||
# ifdef ESP32
|
||||
Log.trace(F("IR Task running on core :%d" CR), xPortGetCoreID());
|
||||
# endif
|
||||
IRdata.set("value", (SIGNAL_SIZE_UL_ULL)(results.value));
|
||||
IRdata.set("protocol", (int)(results.decode_type));
|
||||
IRdata.set("bits", (int)(results.bits));
|
||||
IRdata["value"] = (SIGNAL_SIZE_UL_ULL)(results.value);
|
||||
IRdata["protocol"] = (int)(results.decode_type);
|
||||
IRdata["bits"] = (int)(results.bits);
|
||||
# if defined(ESP8266) || defined(ESP32) //resultToHexidecimal is only available with IRremoteESP8266
|
||||
String hex = resultToHexidecimal(&results);
|
||||
IRdata.set("hex", (char*)hex.c_str());
|
||||
IRdata.set("protocol_name", (char*)(typeToString(results.decode_type, false)).c_str());
|
||||
IRdata["hex"] = (const char*)hex.c_str();
|
||||
IRdata["protocol_name"] = (const char*)(typeToString(results.decode_type, false)).c_str();
|
||||
# endif
|
||||
String rawCode = "";
|
||||
// Dump data
|
||||
@@ -144,7 +144,7 @@ void IRtoMQTT() {
|
||||
rawCode = rawCode + ","; // ',' not needed on last one
|
||||
}
|
||||
//trc(rawCode);
|
||||
IRdata.set("raw", rawCode);
|
||||
IRdata["raw"] = rawCode;
|
||||
// if needed we directly resend the raw code
|
||||
# ifdef RawDirectForward
|
||||
# if defined(ESP8266) || defined(ESP32)
|
||||
@@ -162,9 +162,9 @@ void IRtoMQTT() {
|
||||
Log.trace(F("raw redirected" CR));
|
||||
# endif
|
||||
irrecv.resume(); // Receive the next value
|
||||
SIGNAL_SIZE_UL_ULL MQTTvalue = IRdata.get<SIGNAL_SIZE_UL_ULL>("value");
|
||||
SIGNAL_SIZE_UL_ULL MQTTvalue = IRdata["value"].as<SIGNAL_SIZE_UL_ULL>();
|
||||
//trc(MQTTvalue);
|
||||
if ((pubIRunknownPrtcl == false && IRdata.get<int>("protocol") == -1)) { // don't publish unknown IR protocol
|
||||
if ((pubIRunknownPrtcl == false && IRdata["protocol"].as<int>() == -1)) { // don't publish unknown IR protocol
|
||||
Log.notice(F("--no pub unknwn prt--" CR));
|
||||
} else if (!isAduplicateSignal(MQTTvalue) && MQTTvalue != 0) { // conditions to avoid duplications of IR -->MQTT
|
||||
Log.trace(F("Adv data IRtoMQTT" CR));
|
||||
|
||||
@@ -55,8 +55,8 @@ void setupLORA() {
|
||||
void LORAtoMQTT() {
|
||||
int packetSize = LoRa.parsePacket();
|
||||
if (packetSize) {
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject& LORAdata = jsonBuffer.createObject();
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject LORAdata = jsonBuffer.to<JsonObject>();
|
||||
Log.trace(F("Rcv. LORA" CR));
|
||||
# ifdef ESP32
|
||||
String taskMessage = "LORA Task running on core ";
|
||||
@@ -68,11 +68,11 @@ void LORAtoMQTT() {
|
||||
for (int i = 0; i < packetSize; i++) {
|
||||
packet += (char)LoRa.read();
|
||||
}
|
||||
LORAdata.set("rssi", (int)LoRa.packetRssi());
|
||||
LORAdata.set("snr", (float)LoRa.packetSnr());
|
||||
LORAdata.set("pferror", (float)LoRa.packetFrequencyError());
|
||||
LORAdata.set("packetSize", (int)packetSize);
|
||||
LORAdata.set("message", (char*)packet.c_str());
|
||||
LORAdata["rssi"] = (int)LoRa.packetRssi();
|
||||
LORAdata["snr"] = (float)LoRa.packetSnr();
|
||||
LORAdata["pferror"] = (float)LoRa.packetFrequencyError();
|
||||
LORAdata["packetSize"] = (int)packetSize;
|
||||
LORAdata["message"] = (char*)packet.c_str();
|
||||
pub(subjectLORAtoMQTT, LORAdata);
|
||||
if (repeatLORAwMQTT) {
|
||||
Log.trace(F("Pub LORA for rpt" CR));
|
||||
|
||||
+15
-10
@@ -40,13 +40,18 @@ void pilightCallback(const String& protocol, const String& message, int status,
|
||||
size_t repeats, const String& deviceID) {
|
||||
if (status == VALID) {
|
||||
Log.trace(F("Creating RF PiLight buffer" CR));
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject& RFPiLightdata = jsonBuffer.createObject();
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer2;
|
||||
JsonObject& msg = jsonBuffer2.parseObject(message);
|
||||
RFPiLightdata.set("message", msg);
|
||||
RFPiLightdata.set("protocol", (char*)protocol.c_str());
|
||||
RFPiLightdata.set("length", (char*)deviceID.c_str());
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject RFPiLightdata = jsonBuffer.to<JsonObject>();
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer2;
|
||||
JsonObject msg = jsonBuffer2.to<JsonObject>();
|
||||
auto error = deserializeJson(jsonBuffer2, message);
|
||||
if (error) {
|
||||
Log.error(F("deserializeJson() failed: %s" CR), error.c_str());
|
||||
return;
|
||||
}
|
||||
RFPiLightdata["message"] = msg;
|
||||
RFPiLightdata["protocol"] = (const char*)protocol.c_str();
|
||||
RFPiLightdata["length"] = (const char*)deviceID.c_str();
|
||||
|
||||
const char* device_id = deviceID.c_str();
|
||||
if (!strlen(device_id)) {
|
||||
@@ -62,9 +67,9 @@ void pilightCallback(const String& protocol, const String& message, int status,
|
||||
}
|
||||
}
|
||||
|
||||
RFPiLightdata.set("value", device_id);
|
||||
RFPiLightdata.set("repeats", (int)repeats);
|
||||
RFPiLightdata.set("status", (int)status);
|
||||
RFPiLightdata["value"] = device_id;
|
||||
RFPiLightdata["repeats"] = (int)repeats;
|
||||
RFPiLightdata["status"] = (int)status;
|
||||
pub(subjectPilighttoMQTT, RFPiLightdata);
|
||||
if (repeatPilightwMQTT) {
|
||||
Log.trace(F("Pub Pilight for rpt" CR));
|
||||
|
||||
+7
-7
@@ -81,19 +81,19 @@ void RFtoMQTT() {
|
||||
# else
|
||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(4);
|
||||
# endif
|
||||
StaticJsonBuffer<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
||||
JsonObject& RFdata = jsonBuffer.createObject();
|
||||
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
||||
JsonObject RFdata = jsonBuffer.to<JsonObject>();
|
||||
Log.trace(F("Rcv. RF" CR));
|
||||
# ifdef ESP32
|
||||
Log.trace(F("RF Task running on core :%d" CR), xPortGetCoreID());
|
||||
# endif
|
||||
SIGNAL_SIZE_UL_ULL MQTTvalue = mySwitch.getReceivedValue();
|
||||
RFdata.set("value", (SIGNAL_SIZE_UL_ULL)MQTTvalue);
|
||||
RFdata.set("protocol", (int)mySwitch.getReceivedProtocol());
|
||||
RFdata.set("length", (int)mySwitch.getReceivedBitlength());
|
||||
RFdata.set("delay", (int)mySwitch.getReceivedDelay());
|
||||
RFdata["value"] = (SIGNAL_SIZE_UL_ULL)MQTTvalue;
|
||||
RFdata["protocol"] = (int)mySwitch.getReceivedProtocol();
|
||||
RFdata["length"] = (int)mySwitch.getReceivedBitlength();
|
||||
RFdata["delay"] = (int)mySwitch.getReceivedDelay();
|
||||
# ifdef ZradioCC1101 // set Receive off and Transmitt on
|
||||
RFdata.set("mhz", receiveMhz);
|
||||
RFdata["mhz"] = receiveMhz;
|
||||
# endif
|
||||
mySwitch.resetAvailable();
|
||||
|
||||
|
||||
+12
-12
@@ -78,11 +78,11 @@ void RF2toMQTTdiscovery(JsonObject& data) {
|
||||
String payloadoffstr;
|
||||
|
||||
int org_switchtype = data["switchType"]; // Store original switchvalue
|
||||
data.set("switchType", 1); // switchtype = 1 turns switch on.
|
||||
data.printTo(payloadonstr);
|
||||
data.set("switchType", 0); // switchtype = 0 turns switch off.
|
||||
data.printTo(payloadoffstr);
|
||||
data.set("switchType", org_switchtype); // Restore original switchvalue
|
||||
data["switchType"] = 1; // switchtype = 1 turns switch on.
|
||||
serializeJson(data, payloadonstr);
|
||||
data["switchType"] = 0; // switchtype = 0 turns switch off.
|
||||
serializeJson(data, payloadonstr);
|
||||
data["switchType"] = org_switchtype; // Restore original switchvalue
|
||||
|
||||
String switchname;
|
||||
switchname = "RF2_" + String((int)data["unit"]) + "_" +
|
||||
@@ -119,17 +119,17 @@ void RF2toMQTT() {
|
||||
if (rf2rd.hasNewData) {
|
||||
Log.trace(F("Creating RF2 buffer" CR));
|
||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(5);
|
||||
StaticJsonBuffer<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
||||
JsonObject& RF2data = jsonBuffer.createObject();
|
||||
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
||||
JsonObject RF2data = jsonBuffer.to<JsonObject>();
|
||||
|
||||
rf2rd.hasNewData = false;
|
||||
|
||||
Log.trace(F("Rcv. RF2" CR));
|
||||
RF2data.set("unit", (int)rf2rd.unit);
|
||||
RF2data.set("groupBit", (int)rf2rd.groupBit);
|
||||
RF2data.set("period", (int)rf2rd.period);
|
||||
RF2data.set("address", (unsigned long)rf2rd.address);
|
||||
RF2data.set("switchType", (int)rf2rd.switchType);
|
||||
RF2data["unit"] = (int)rf2rd.unit;
|
||||
RF2data["groupBit"] = (int)rf2rd.groupBit;
|
||||
RF2data["period"] = (int)rf2rd.period;
|
||||
RF2data["address"] = (unsigned long)rf2rd.address;
|
||||
RF2data["switchType"] = (int)rf2rd.switchType;
|
||||
# ifdef ZmqttDiscovery //component creation for HA
|
||||
if (disc)
|
||||
RF2toMQTTdiscovery(RF2data);
|
||||
|
||||
@@ -142,8 +142,8 @@ bool RFM69toMQTT(void) {
|
||||
//check if something was received (could be an interrupt from the radio)
|
||||
if (radio.receiveDone()) {
|
||||
Log.trace(F("Creating RFM69 buffer" CR));
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject& RFM69data = jsonBuffer.createObject();
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject RFM69data = jsonBuffer.to<JsonObject>();
|
||||
uint8_t data[RF69_MAX_DATA_LEN + 1]; // For the null character
|
||||
uint8_t SENDERID = radio.SENDERID;
|
||||
uint8_t DATALEN = radio.DATALEN;
|
||||
@@ -164,9 +164,9 @@ bool RFM69toMQTT(void) {
|
||||
|
||||
char buff[sizeof(subjectRFM69toMQTT) + 4];
|
||||
sprintf(buff, "%s/%d", subjectRFM69toMQTT, SENDERID);
|
||||
RFM69data.set("data", (char*)data);
|
||||
RFM69data.set("rssi", (int)radio.RSSI);
|
||||
RFM69data.set("senderid", (int)radio.SENDERID);
|
||||
RFM69data["data"] = (char*)data;
|
||||
RFM69data["rssi"] = (int)radio.RSSI;
|
||||
RFM69data["senderid"] = (int)radio.SENDERID;
|
||||
pub(buff, RFM69data);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -41,8 +41,13 @@ rtl_433_ESP rtl_433(-1); // use -1 to disable transmitter
|
||||
# include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||
|
||||
void rtl_433_Callback(char* message) {
|
||||
DynamicJsonBuffer jsonBuffer2(JSON_MSG_BUFFER);
|
||||
JsonObject& RFrtl_433_ESPdata = jsonBuffer2.parseObject(message);
|
||||
DynamicJsonDocument jsonBuffer2(JSON_MSG_BUFFER);
|
||||
JsonObject RFrtl_433_ESPdata = jsonBuffer2.to<JsonObject>();
|
||||
auto error = deserializeJson(jsonBuffer2, message);
|
||||
if (error) {
|
||||
Log.error(F("deserializeJson() failed: %s" CR), error.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
String topic = String(subjectRTL_433toMQTT);
|
||||
# ifdef valueAsASubject
|
||||
|
||||
@@ -102,21 +102,21 @@ void _rfbDecode() {
|
||||
_rfbToChar(&_uartbuf[1], buffer);
|
||||
|
||||
Log.trace(F("Creating SRFB buffer" CR));
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject& SRFBdata = jsonBuffer.createObject();
|
||||
SRFBdata.set("raw", String(buffer).substring(0, 18));
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject SRFBdata = jsonBuffer.to<JsonObject>();
|
||||
SRFBdata["raw"] = String(buffer).substring(0, 18);
|
||||
|
||||
int val_Tsyn = (int)(int)value_from_hex_data(buffer, 0, 4, false, false);
|
||||
SRFBdata.set("delay", (int)val_Tsyn);
|
||||
SRFBdata["delay"] = (int)val_Tsyn;
|
||||
|
||||
int val_Tlow = (int)value_from_hex_data(buffer, 4, 4, false, false);
|
||||
SRFBdata.set("val_Tlow", (int)val_Tlow);
|
||||
SRFBdata["val_Tlow"] = (int)val_Tlow;
|
||||
|
||||
int val_Thigh = (int)value_from_hex_data(buffer, 8, 4, false, false);
|
||||
SRFBdata.set("val_Thigh", (int)val_Thigh);
|
||||
SRFBdata["val_Thigh"] = (int)val_Thigh;
|
||||
|
||||
unsigned long MQTTvalue = (unsigned long)value_from_hex_data(buffer, 12, 8, false, false);
|
||||
SRFBdata.set("value", (unsigned long)MQTTvalue);
|
||||
SRFBdata["value"] = (unsigned long)MQTTvalue;
|
||||
|
||||
if (!isAduplicateSignal(MQTTvalue) && MQTTvalue != 0) { // conditions to avoid duplications of RF -->MQTT
|
||||
Log.trace(F("Adv data SRFBtoMQTT" CR));
|
||||
|
||||
@@ -37,10 +37,10 @@ void PairedDeviceAdded(byte newID) {
|
||||
Serial.println(newID, DEC);
|
||||
# endif
|
||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(2);
|
||||
StaticJsonBuffer<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
||||
JsonObject& RFdata = jsonBuffer.createObject();
|
||||
RFdata.set("sensor", newID);
|
||||
RFdata.set("action", "paired");
|
||||
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
||||
JsonObject RFdata = jsonBuffer.to<JsonObject>();
|
||||
RFdata["sensor"] = newID;
|
||||
RFdata["action"] = "paired";
|
||||
pub(subjectRFtoMQTT, RFdata);
|
||||
wsdr.pair(NULL, PairedDeviceAdded);
|
||||
}
|
||||
@@ -56,11 +56,11 @@ void sendWindSpeedData(byte id, float wind_speed, byte battery_status) {
|
||||
unsigned long MQTTvalue = 10000 + round(wind_speed);
|
||||
if (!isAduplicateSignal(MQTTvalue)) { // conditions to avoid duplications of RF -->MQTT
|
||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(3);
|
||||
StaticJsonBuffer<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
||||
JsonObject& RFdata = jsonBuffer.createObject();
|
||||
RFdata.set("sensor", id);
|
||||
RFdata.set("wind_speed", wind_speed);
|
||||
RFdata.set("battery", bitRead(battery_status, 0) == 0 ? "OK" : "Low");
|
||||
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
||||
JsonObject RFdata = jsonBuffer.to<JsonObject>();
|
||||
RFdata["sensor"] = id;
|
||||
RFdata["wind_speed"] = wind_speed;
|
||||
RFdata["battery"] = bitRead(battery_status, 0) == 0 ? "OK" : "Low";
|
||||
pub(subjectRFtoMQTT, RFdata);
|
||||
Log.trace(F("Store wind speed val: %lu" CR), MQTTvalue);
|
||||
storeSignalValue(MQTTvalue);
|
||||
@@ -71,11 +71,11 @@ void sendRainData(byte id, float rain_volume, byte battery_status) {
|
||||
unsigned long MQTTvalue = 11000 + round(rain_volume * 10.0);
|
||||
if (!isAduplicateSignal(MQTTvalue)) { // conditions to avoid duplications of RF -->MQTT
|
||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(3);
|
||||
StaticJsonBuffer<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
||||
JsonObject& RFdata = jsonBuffer.createObject();
|
||||
RFdata.set("sensor", id);
|
||||
RFdata.set("rain_volume", rain_volume);
|
||||
RFdata.set("battery", bitRead(battery_status, 1) == 0 ? "OK" : "Low");
|
||||
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
||||
JsonObject RFdata = jsonBuffer.to<JsonObject>();
|
||||
RFdata["sensor"] = id;
|
||||
RFdata["rain_volume"] = rain_volume;
|
||||
RFdata["battery"] = bitRead(battery_status, 1) == 0 ? "OK" : "Low";
|
||||
pub(subjectRFtoMQTT, RFdata);
|
||||
Log.trace(F("Store rain_volume: %lu" CR), MQTTvalue);
|
||||
storeSignalValue(MQTTvalue);
|
||||
@@ -86,12 +86,12 @@ void sendWindData(byte id, int wind_direction, float wind_gust, byte battery_sta
|
||||
unsigned long MQTTvalue = 20000 + round(wind_gust * 10.0) + wind_direction;
|
||||
if (!isAduplicateSignal(MQTTvalue)) { // conditions to avoid duplications of RF -->MQTT
|
||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(4);
|
||||
StaticJsonBuffer<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
||||
JsonObject& RFdata = jsonBuffer.createObject();
|
||||
RFdata.set("sensor", id);
|
||||
RFdata.set("wind_direction", wind_direction);
|
||||
RFdata.set("wind_gust", wind_gust);
|
||||
RFdata.set("battery", bitRead(battery_status, 0) == 0 ? "OK" : "Low");
|
||||
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
||||
JsonObject RFdata = jsonBuffer.to<JsonObject>();
|
||||
RFdata["sensor"] = id;
|
||||
RFdata["wind_direction"] = wind_direction;
|
||||
RFdata["wind_gust"] = wind_gust;
|
||||
RFdata["battery"] = bitRead(battery_status, 0) == 0 ? "OK" : "Low";
|
||||
pub(subjectRFtoMQTT, RFdata);
|
||||
Log.trace(F("Store wind data val: %lu" CR), MQTTvalue);
|
||||
storeSignalValue(MQTTvalue);
|
||||
@@ -102,13 +102,13 @@ void sendTemperatureData(byte id, float temperature, int humidity, byte battery_
|
||||
unsigned long MQTTvalue = 40000 + abs(round(temperature * 100.0)) + humidity;
|
||||
if (!isAduplicateSignal(MQTTvalue)) { // conditions to avoid duplications of RF -->MQTT
|
||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(4);
|
||||
StaticJsonBuffer<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
||||
JsonObject& RFdata = jsonBuffer.createObject();
|
||||
RFdata.set("sensor", id);
|
||||
RFdata.set("tempc", temperature);
|
||||
RFdata.set("tempf", wsdr.convertCtoF(temperature));
|
||||
RFdata.set("humidity", humidity);
|
||||
RFdata.set("battery", bitRead(battery_status, 0) == 0 ? "OK" : "Low");
|
||||
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
||||
JsonObject RFdata = jsonBuffer.to<JsonObject>();
|
||||
RFdata["sensor"] = id;
|
||||
RFdata["tempc"] = temperature;
|
||||
RFdata["tempf"] = wsdr.convertCtoF(temperature);
|
||||
RFdata["humidity"] = humidity;
|
||||
RFdata["battery"] = bitRead(battery_status, 0) == 0 ? "OK" : "Low";
|
||||
pub(subjectRFtoMQTT, RFdata);
|
||||
Log.trace(F("Store temp val: %lu" CR), MQTTvalue);
|
||||
storeSignalValue(MQTTvalue);
|
||||
|
||||
+34
-34
@@ -72,8 +72,8 @@ void createDiscovery(const char* sensor_type,
|
||||
const char* payload_available, const char* payload_not_avalaible, bool gateway_entity, const char* cmd_topic,
|
||||
const char* device_name, const char* device_manufacturer, const char* device_model, const char* device_mac, bool retainCmd) {
|
||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(14) + JSON_OBJECT_SIZE(5) + JSON_ARRAY_SIZE(1);
|
||||
StaticJsonBuffer<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
||||
JsonObject& sensor = jsonBuffer.createObject();
|
||||
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
||||
JsonObject sensor = jsonBuffer.to<JsonObject>();
|
||||
|
||||
// If a component cannot render it's state (f.i. KAKU relays) no state topic
|
||||
// should be added. Without a state topic HA will use optimistic mode for the
|
||||
@@ -92,76 +92,76 @@ void createDiscovery(const char* sensor_type,
|
||||
strcpy(state_topic, "+/+");
|
||||
}
|
||||
strcat(state_topic, st_topic);
|
||||
sensor.set("stat_t", state_topic);
|
||||
sensor["stat_t"] = state_topic;
|
||||
}
|
||||
|
||||
sensor.set("name", s_name); //name
|
||||
sensor.set("uniq_id", unique_id); //unique_id
|
||||
sensor["name"] = s_name; //name
|
||||
sensor["uniq_id"] = unique_id; //unique_id
|
||||
if (retainCmd)
|
||||
sensor.set("retain", retainCmd); // Retain command
|
||||
sensor["retain"] = retainCmd; // Retain command
|
||||
if (device_class[0])
|
||||
sensor.set("dev_cla", device_class); //device_class
|
||||
sensor["dev_cla"] = device_class; //device_class
|
||||
if (value_template[0])
|
||||
sensor.set("val_tpl", value_template); //value_template
|
||||
sensor["val_tpl"] = value_template; //value_template
|
||||
if (payload_on[0])
|
||||
sensor.set("pl_on", payload_on); // payload_on
|
||||
sensor["pl_on"] = payload_on; // payload_on
|
||||
if (payload_off[0])
|
||||
sensor.set("pl_off", payload_off); //payload_off
|
||||
sensor["pl_off"] = payload_off; //payload_off
|
||||
if (unit_of_meas[0])
|
||||
sensor.set("unit_of_meas", unit_of_meas); //unit_of_measurement*/
|
||||
sensor["unit_of_meas"] = unit_of_meas; //unit_of_measurement*/
|
||||
if (off_delay != 0)
|
||||
sensor.set("off_delay", off_delay); //off_delay
|
||||
sensor["off_delay"] = off_delay; //off_delay
|
||||
if (payload_available[0])
|
||||
sensor.set("pl_avail", payload_available); // payload_on
|
||||
sensor["pl_avail"] = payload_available; // payload_on
|
||||
if (payload_not_avalaible[0])
|
||||
sensor.set("pl_not_avail", payload_not_avalaible); //payload_off
|
||||
sensor["pl_not_avail"] = payload_not_avalaible; //payload_off
|
||||
|
||||
if (cmd_topic[0]) {
|
||||
char command_topic[mqtt_topic_max_size];
|
||||
strcpy(command_topic, mqtt_topic);
|
||||
strcat(command_topic, gateway_name);
|
||||
strcat(command_topic, cmd_topic);
|
||||
sensor.set("cmd_t", command_topic); //command_topic
|
||||
sensor["cmd_t"] = command_topic; //command_topic
|
||||
}
|
||||
|
||||
if (gateway_entity) {
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonDeviceBuffer;
|
||||
JsonObject& device = jsonDeviceBuffer.createObject();
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonDeviceBuffer;
|
||||
JsonObject device = jsonDeviceBuffer.to<JsonObject>();
|
||||
char JSONmessageBuffer[JSON_MSG_BUFFER];
|
||||
modules.printTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
|
||||
serializeJson(modules, JSONmessageBuffer, sizeof(JSONmessageBuffer));
|
||||
Log.notice(F("Received json : %s" CR), JSONmessageBuffer);
|
||||
device.set("name", gateway_name);
|
||||
device.set("model", JSONmessageBuffer);
|
||||
device.set("manufacturer", DEVICEMANUFACTURER);
|
||||
device.set("sw_version", OMG_VERSION);
|
||||
JsonArray& identifiers = device.createNestedArray("identifiers");
|
||||
device["name"] = gateway_name;
|
||||
device["model"] = JSONmessageBuffer;
|
||||
device["manufacturer"] = DEVICEMANUFACTURER;
|
||||
device["sw_version"] = OMG_VERSION;
|
||||
JsonArray identifiers = device.createNestedArray("identifiers");
|
||||
identifiers.add(getMacAddress());
|
||||
sensor.set("device", device); //device representing the board
|
||||
sensor["device"] = device; //device representing the board
|
||||
} else {
|
||||
char deviceid[13];
|
||||
memcpy(deviceid, &unique_id[0], 12);
|
||||
deviceid[12] = '\0';
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonDeviceBuffer;
|
||||
JsonObject& device = jsonDeviceBuffer.createObject();
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonDeviceBuffer;
|
||||
JsonObject device = jsonDeviceBuffer.to<JsonObject>();
|
||||
if (device_mac[0] != 0) {
|
||||
JsonArray& connections = device.createNestedArray("connections");
|
||||
JsonArray& connection_mac = connections.createNestedArray();
|
||||
JsonArray connections = device.createNestedArray("connections");
|
||||
JsonArray connection_mac = connections.createNestedArray();
|
||||
connection_mac.add("mac");
|
||||
connection_mac.add(device_mac);
|
||||
}
|
||||
JsonArray& identifiers = device.createNestedArray("identifiers");
|
||||
JsonArray identifiers = device.createNestedArray("identifiers");
|
||||
identifiers.add(deviceid);
|
||||
if (device_manufacturer[0]) {
|
||||
device.set("manufacturer", device_manufacturer);
|
||||
device["manufacturer"] = device_manufacturer;
|
||||
}
|
||||
if (device_model[0]) {
|
||||
device.set("model", device_model);
|
||||
device["model"] = device_model;
|
||||
}
|
||||
if (device_name[0]) {
|
||||
device.set("name", device_name);
|
||||
device["name"] = device_name;
|
||||
}
|
||||
device.set("via_device", gateway_name); //device name of the board
|
||||
sensor.set("device", device); //device representing the actual sensor/switch device
|
||||
device["via_device"] = gateway_name; //device name of the board
|
||||
sensor["device"] = device; //device representing the actual sensor/switch device
|
||||
}
|
||||
String topic = String(discovery_Topic) + "/" + String(sensor_type) + "/" + String(unique_id) + "/config";
|
||||
pub_custom_topic((char*)topic.c_str(), sensor, true);
|
||||
|
||||
+4
-4
@@ -59,9 +59,9 @@ void MeasureADC() {
|
||||
# else
|
||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(1);
|
||||
# endif
|
||||
StaticJsonBuffer<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
||||
JsonObject& ADCdata = jsonBuffer.createObject();
|
||||
ADCdata.set("adc", (int)val);
|
||||
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
||||
JsonObject ADCdata = jsonBuffer.to<JsonObject>();
|
||||
ADCdata["adc"] = (int)val;
|
||||
# if defined(ADC_DIVIDER)
|
||||
float volt = 0;
|
||||
# if defined(ESP32)
|
||||
@@ -78,7 +78,7 @@ void MeasureADC() {
|
||||
// let's give 2 decimal point
|
||||
val = (volt * 100);
|
||||
volt = (float)val / 100.0;
|
||||
ADCdata.set("volt", (float)volt);
|
||||
ADCdata["volt"] = (float)volt;
|
||||
# endif
|
||||
pub(ADCTOPIC, ADCdata);
|
||||
persistedadc = val;
|
||||
|
||||
@@ -86,20 +86,20 @@ void MeasureAHTTempHum() {
|
||||
Log.error(F("Failed to read from sensor AHTx0!" CR));
|
||||
} else {
|
||||
Log.notice(F("Creating AHTx0 buffer" CR));
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject& AHTx0data = jsonBuffer.createObject();
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject AHTx0data = jsonBuffer.to<JsonObject>();
|
||||
// Generate Temperature in degrees C
|
||||
if (ahtTempC.temperature != persisted_aht_tempc || AHTx0_always) {
|
||||
float ahtTempF = convertTemp_CtoF(ahtTempC.temperature);
|
||||
AHTx0data.set("tempc", (float)ahtTempC.temperature);
|
||||
AHTx0data.set("tempf", (float)ahtTempF);
|
||||
AHTx0data["tempc"] = (float)ahtTempC.temperature;
|
||||
AHTx0data["tempf"] = (float)ahtTempF;
|
||||
} else {
|
||||
Log.notice(F("Same Temp. Don't send it" CR));
|
||||
}
|
||||
|
||||
// Generate Humidity in percent
|
||||
if (ahtHum.relative_humidity != persisted_aht_hum || AHTx0_always) {
|
||||
AHTx0data.set("hum", (float)ahtHum.relative_humidity);
|
||||
AHTx0data["hum"] = (float)ahtHum.relative_humidity;
|
||||
} else {
|
||||
Log.notice(F("Same Humidity. Don't send it" CR));
|
||||
}
|
||||
|
||||
@@ -54,8 +54,8 @@ void setupZsensorBH1750() {
|
||||
void MeasureLightIntensity() {
|
||||
if (millis() > (timebh1750 + TimeBetweenReadingBH1750)) { //retrieving value of Lux, FtCd and Wattsm2 from BH1750
|
||||
Log.trace(F("Creating BH1750 buffer" CR));
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject& BH1750data = jsonBuffer.createObject();
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject BH1750data = jsonBuffer.to<JsonObject>();
|
||||
|
||||
timebh1750 = millis();
|
||||
unsigned int i = 0;
|
||||
@@ -82,21 +82,21 @@ void MeasureLightIntensity() {
|
||||
|
||||
// Generate Lux
|
||||
if (Lux != persistedll || bh1750_always) {
|
||||
BH1750data.set("lux", (unsigned int)Lux);
|
||||
BH1750data["lux"] = (unsigned int)Lux;
|
||||
} else {
|
||||
Log.trace(F("Same lux don't send it" CR));
|
||||
}
|
||||
|
||||
// Generate FtCd
|
||||
if (ftcd != persistedlf || bh1750_always) {
|
||||
BH1750data.set("ftcd", (unsigned int)ftcd);
|
||||
BH1750data["ftcd"] = (unsigned int)ftcd;
|
||||
} else {
|
||||
Log.trace(F("Same ftcd don't send it" CR));
|
||||
}
|
||||
|
||||
// Generate Watts/m2
|
||||
if (Wattsm2 != persistedlw || bh1750_always) {
|
||||
BH1750data.set("wattsm2", (unsigned int)Wattsm2);
|
||||
BH1750data["wattsm2"] = (unsigned int)Wattsm2;
|
||||
} else {
|
||||
Log.trace(F("Same wattsm2 don't send it" CR));
|
||||
}
|
||||
|
||||
@@ -145,32 +145,32 @@ void MeasureTempHumAndPressure() {
|
||||
Log.error(F("Failed to read from BME280!" CR));
|
||||
} else {
|
||||
Log.trace(F("Creating BME280 buffer" CR));
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject& BME280data = jsonBuffer.createObject();
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject BME280data = jsonBuffer.to<JsonObject>();
|
||||
// Generate Temperature in degrees C
|
||||
if (BmeTempC != persisted_bme_tempc || bme280_always) {
|
||||
BME280data.set("tempc", (float)BmeTempC);
|
||||
BME280data["tempc"] = (float)BmeTempC;
|
||||
} else {
|
||||
Log.trace(F("Same Degrees C don't send it" CR));
|
||||
}
|
||||
|
||||
// Generate Temperature in degrees F
|
||||
if (BmeTempF != persisted_bme_tempf || bme280_always) {
|
||||
BME280data.set("tempf", (float)BmeTempF);
|
||||
BME280data["tempf"] = (float)BmeTempF;
|
||||
} else {
|
||||
Log.trace(F("Same Degrees F don't send it" CR));
|
||||
}
|
||||
|
||||
// Generate Humidity in percent
|
||||
if (BmeHum != persisted_bme_hum || bme280_always) {
|
||||
BME280data.set("hum", (float)BmeHum);
|
||||
BME280data["hum"] = (float)BmeHum;
|
||||
} else {
|
||||
Log.trace(F("Same Humidity don't send it" CR));
|
||||
}
|
||||
|
||||
// Generate Pressure in Pa
|
||||
if (BmePa != persisted_bme_pa || bme280_always) {
|
||||
BME280data.set("pa", (float)BmePa);
|
||||
BME280data["pa"] = (float)BmePa;
|
||||
} else {
|
||||
Log.trace(F("Same Pressure don't send it" CR));
|
||||
}
|
||||
@@ -178,14 +178,14 @@ void MeasureTempHumAndPressure() {
|
||||
// Generate Altitude in Meter
|
||||
if (BmeAltiM != persisted_bme_altim || bme280_always) {
|
||||
Log.trace(F("Sending Altitude Meter to MQTT" CR));
|
||||
BME280data.set("altim", (float)BmeAltiM);
|
||||
BME280data["altim"] = (float)BmeAltiM;
|
||||
} else {
|
||||
Log.trace(F("Same Altitude Meter don't send it" CR));
|
||||
}
|
||||
|
||||
// Generate Altitude in Feet
|
||||
if (BmeAltiFt != persisted_bme_altift || bme280_always) {
|
||||
BME280data.set("altift", (float)BmeAltiFt);
|
||||
BME280data["altift"] = (float)BmeAltiFt;
|
||||
} else {
|
||||
Log.trace(F("Same Altitude Feet don't send it" CR));
|
||||
}
|
||||
|
||||
+5
-5
@@ -55,16 +55,16 @@ void MeasureTempAndHum() {
|
||||
Log.error(F("Failed to read from DHT sensor!" CR));
|
||||
} else {
|
||||
Log.trace(F("Creating DHT buffer" CR));
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject& DHTdata = jsonBuffer.createObject();
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject DHTdata = jsonBuffer.to<JsonObject>();
|
||||
if (h != persistedh || dht_always) {
|
||||
DHTdata.set("hum", (float)h);
|
||||
DHTdata["hum"] = (float)h;
|
||||
} else {
|
||||
Log.trace(F("Same hum don't send it" CR));
|
||||
}
|
||||
if (t != persistedt || dht_always) {
|
||||
DHTdata.set("tempc", (float)t);
|
||||
DHTdata.set("tempf", dht.convertCtoF(t));
|
||||
DHTdata["tempc"] = (float)t;
|
||||
DHTdata["tempf"] = dht.convertCtoF(t);
|
||||
} else {
|
||||
Log.trace(F("Same temp don't send it" CR));
|
||||
}
|
||||
|
||||
@@ -139,21 +139,21 @@ void MeasureDS1820Temp() {
|
||||
Log.error(F("DS1820: Failed to identify any temperature sensors on 1-wire bus during setup!" CR));
|
||||
} else {
|
||||
Log.trace(F("DS1820: Reading temperature(s) from %d sensor(s)..." CR), ds1820_count);
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject& DS1820data = jsonBuffer.createObject();
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject DS1820data = jsonBuffer.to<JsonObject>();
|
||||
|
||||
for (uint8_t i = 0; i < ds1820_count; i++) {
|
||||
current_temp[i] = round(ds1820.getTempC(ds1820_devices[i]) * 10) / 10.0;
|
||||
if (current_temp[i] == -127) {
|
||||
Log.error(F("DS1820: Device %s currently disconnected!" CR), (char*)ds1820_addr[i].c_str());
|
||||
} else if (DS1820_ALWAYS || current_temp[i] != persisted_temp[i]) {
|
||||
DS1820data.set("tempc", (float)DallasTemperature::toFahrenheit(current_temp[i]));
|
||||
DS1820data.set("tempf", (float)current_temp[i]);
|
||||
DS1820data["tempc"] = (float)DallasTemperature::toFahrenheit(current_temp[i]);
|
||||
DS1820data["tempf"] = (float)current_temp[i];
|
||||
|
||||
if (DS1820_DETAILS) {
|
||||
DS1820data.set("type", ds1820_type[i]);
|
||||
DS1820data.set("res", ds1820_resolution[i] + String("bit" CR));
|
||||
DS1820data.set("addr", ds1820_addr[i]);
|
||||
DS1820data["type"] = ds1820_type[i];
|
||||
DS1820data["res"] = ds1820_resolution[i] + String("bit" CR);
|
||||
DS1820data["addr"] = ds1820_addr[i];
|
||||
}
|
||||
pub((char*)(String(OW_TOPIC) + "/" + ds1820_addr[i]).c_str(), DS1820data);
|
||||
delay(10);
|
||||
|
||||
@@ -78,13 +78,13 @@ void MeasureGPIOInput() {
|
||||
InputState = reading;
|
||||
Log.trace(F("Creating GPIOInput buffer" CR));
|
||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(1);
|
||||
StaticJsonBuffer<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
||||
JsonObject& GPIOdata = jsonBuffer.createObject();
|
||||
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
||||
JsonObject GPIOdata = jsonBuffer.to<JsonObject>();
|
||||
if (InputState == HIGH) {
|
||||
GPIOdata.set("gpio", "HIGH");
|
||||
GPIOdata["gpio"] = "HIGH";
|
||||
}
|
||||
if (InputState == LOW) {
|
||||
GPIOdata.set("gpio", "LOW");
|
||||
GPIOdata["gpio"] = "LOW";
|
||||
}
|
||||
if (GPIOdata.size() > 0)
|
||||
pub(subjectGPIOInputtoMQTT, GPIOdata);
|
||||
|
||||
@@ -44,8 +44,8 @@ void MeasureDistance() {
|
||||
if (millis() > (timeHCSR04 + TimeBetweenReadingHCSR04)) {
|
||||
timeHCSR04 = millis();
|
||||
Log.trace(F("Creating HCSR04 buffer" CR));
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject& HCSR04data = jsonBuffer.createObject();
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject HCSR04data = jsonBuffer.to<JsonObject>();
|
||||
digitalWrite(HCSR04_TRI_GPIO, LOW);
|
||||
delayMicroseconds(2);
|
||||
digitalWrite(HCSR04_TRI_GPIO, HIGH);
|
||||
@@ -57,15 +57,15 @@ void MeasureDistance() {
|
||||
} else {
|
||||
static unsigned int distance = 99999;
|
||||
unsigned int d = duration / 58.2;
|
||||
HCSR04data.set("distance", (int)d);
|
||||
HCSR04data["distance"] = (int)d;
|
||||
if (d > distance) {
|
||||
HCSR04data.set("direction", "away");
|
||||
HCSR04data["direction"] = "away";
|
||||
Log.trace(F("HC SR04 Distance changed" CR));
|
||||
} else if (d < distance) {
|
||||
HCSR04data.set("direction", "towards");
|
||||
HCSR04data["direction"] = "towards";
|
||||
Log.trace(F("HC SR04 Distance changed" CR));
|
||||
} else if (HCSR04_always) {
|
||||
HCSR04data.set("direction", "static");
|
||||
HCSR04data["direction"] = "static";
|
||||
Log.trace(F("HC SR04 Distance hasn't changed" CR));
|
||||
}
|
||||
distance = d;
|
||||
|
||||
@@ -42,8 +42,8 @@ void setupHCSR501() {
|
||||
void MeasureHCSR501() {
|
||||
if (millis() > TimeBeforeStartHCSR501) { //let time to init the PIR sensor
|
||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(1);
|
||||
StaticJsonBuffer<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
||||
JsonObject& HCSR501data = jsonBuffer.createObject();
|
||||
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
||||
JsonObject HCSR501data = jsonBuffer.to<JsonObject>();
|
||||
static int pirState = LOW;
|
||||
int PresenceValue = digitalRead(HCSR501_GPIO);
|
||||
# if defined(ESP8266) || defined(ESP32)
|
||||
@@ -52,13 +52,13 @@ void MeasureHCSR501() {
|
||||
if (PresenceValue == HIGH) {
|
||||
if (pirState == LOW) {
|
||||
//turned on
|
||||
HCSR501data.set("presence", "true");
|
||||
HCSR501data["presence"] = "true";
|
||||
pirState = HIGH;
|
||||
}
|
||||
} else {
|
||||
if (pirState == HIGH) {
|
||||
// turned off
|
||||
HCSR501data.set("presence", "false");
|
||||
HCSR501data["presence"] = "false";
|
||||
pirState = LOW;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,20 +83,20 @@ void MeasureTempHum() {
|
||||
Log.error(F("Failed to read from sensor HTU21!" CR));
|
||||
} else {
|
||||
Log.notice(F("Creating HTU21 buffer" CR));
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject& HTU21data = jsonBuffer.createObject();
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject HTU21data = jsonBuffer.to<JsonObject>();
|
||||
// Generate Temperature in degrees C
|
||||
if (HtuTempC != persisted_htu_tempc || htu21_always) {
|
||||
float HtuTempF = (HtuTempC * 1.8) + 32;
|
||||
HTU21data.set("tempc", (float)HtuTempC);
|
||||
HTU21data.set("tempf", (float)HtuTempF);
|
||||
HTU21data["tempc"] = (float)HtuTempC;
|
||||
HTU21data["tempf"] = (float)HtuTempF;
|
||||
} else {
|
||||
Log.notice(F("Same Temp. Don't send it" CR));
|
||||
}
|
||||
|
||||
// Generate Humidity in percent
|
||||
if (HtuHum != persisted_htu_hum || htu21_always) {
|
||||
HTU21data.set("hum", (float)HtuHum);
|
||||
HTU21data["hum"] = (float)HtuHum;
|
||||
} else {
|
||||
Log.notice(F("Same Humidity. Don't send it" CR));
|
||||
}
|
||||
|
||||
@@ -53,8 +53,8 @@ void MeasureINA226() {
|
||||
if (millis() > (timeINA226 + TimeBetweenReadingINA226)) { //retrieving value of temperature and humidity of the box from DHT every xUL
|
||||
timeINA226 = millis();
|
||||
Log.trace(F("Creating INA226 buffer" CR));
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject& INA226data = jsonBuffer.createObject();
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject INA226data = jsonBuffer.to<JsonObject>();
|
||||
// Topic on which we will send data
|
||||
Log.trace(F("Retrieving electrical data" CR));
|
||||
// Bus Spannung, read-only, 16Bit, 0...40.96V max., LSB 1.25mV
|
||||
@@ -75,9 +75,9 @@ void MeasureINA226() {
|
||||
dtostrf(volt, 6, 3, volt_c);
|
||||
dtostrf(current, 6, 3, current_c);
|
||||
dtostrf(power, 6, 3, power_c);
|
||||
INA226data.set("volt", (char*)volt_c);
|
||||
INA226data.set("current", (char*)current_c);
|
||||
INA226data.set("power", (char*)power_c);
|
||||
INA226data["volt"] = (char*)volt_c;
|
||||
INA226data["current"] = (char*)current_c;
|
||||
INA226data["power"] = (char*)power_c;
|
||||
pub(subjectINA226toMQTT, INA226data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,16 +47,16 @@ void MeasureTempAndHum() {
|
||||
Log.error(F("Failed to read from SHTC3 sensor!" CR));
|
||||
} else {
|
||||
Log.trace(F("Creating SHTC3 buffer" CR));
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject& SHTC3data = jsonBuffer.createObject();
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject SHTC3data = jsonBuffer.to<JsonObject>();
|
||||
if (h != persistedh || shtc3_always) {
|
||||
SHTC3data.set("hum", (float)h);
|
||||
SHTC3data["hum"] = (float)h;
|
||||
} else {
|
||||
Log.trace(F("Same hum don't send it" CR));
|
||||
}
|
||||
if (t != persistedt || shtc3_always) {
|
||||
SHTC3data.set("tempc", (float)t);
|
||||
SHTC3data.set("tempf", mySHTC3.toDegF());
|
||||
SHTC3data["tempc"] = (float)t;
|
||||
SHTC3data["tempf"] = mySHTC3.toDegF();
|
||||
} else {
|
||||
Log.trace(F("Same temp don't send it" CR));
|
||||
}
|
||||
|
||||
@@ -90,8 +90,8 @@ void MeasureLightIntensityTSL2561() {
|
||||
timetsl2561 = millis();
|
||||
|
||||
Log.trace(F("Creating TSL2561 buffer" CR));
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject& TSL2561data = jsonBuffer.createObject();
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject TSL2561data = jsonBuffer.to<JsonObject>();
|
||||
|
||||
sensors_event_t event;
|
||||
tsl.getEvent(&event);
|
||||
@@ -101,9 +101,9 @@ void MeasureLightIntensityTSL2561() {
|
||||
if (persisted_lux != event.light || tsl2561_always) {
|
||||
persisted_lux = event.light;
|
||||
|
||||
TSL2561data.set("lux", (float)event.light);
|
||||
TSL2561data.set("ftcd", (float)(event.light) / 10.764);
|
||||
TSL2561data.set("wattsm2", (float)(event.light) / 683.0);
|
||||
TSL2561data["lux"] = (float)event.light;
|
||||
TSL2561data["ftcd"] = (float)(event.light) / 10.764;
|
||||
TSL2561data["wattsm2"] = (float)(event.light) / 683.0;
|
||||
|
||||
pub(subjectTSL12561toMQTT, TSL2561data);
|
||||
} else {
|
||||
|
||||
+51
-47
@@ -52,8 +52,8 @@ unsigned long timer_sys_measures = 0;
|
||||
#include <ArduinoLog.h>
|
||||
#include <PubSubClient.h>
|
||||
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> modulesBuffer;
|
||||
JsonArray& modules = modulesBuffer.createArray();
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> modulesBuffer;
|
||||
JsonArray modules = modulesBuffer.to<JsonArray>();
|
||||
|
||||
#ifndef ZgatewayGFSunInverter
|
||||
// Arduino IDE compiles, it automatically creates all the header declarations for all the functions you have in your *.ino file.
|
||||
@@ -315,33 +315,33 @@ void pub(const char* topicori, JsonObject& data) {
|
||||
#ifdef jsonPublishing
|
||||
Log.trace(F("jsonPublishing" CR));
|
||||
# if defined(ESP8266) || defined(ESP32) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)
|
||||
char JSONmessageBuffer[data.measureLength() + 1];
|
||||
char JSONmessageBuffer[measureJson(data) + 1];
|
||||
# else
|
||||
char JSONmessageBuffer[JSON_MSG_BUFFER];
|
||||
# endif
|
||||
data.printTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
|
||||
serializeJson(data, JSONmessageBuffer, sizeof(JSONmessageBuffer));
|
||||
pubMQTT(topic, JSONmessageBuffer);
|
||||
#endif
|
||||
|
||||
#ifdef simplePublishing
|
||||
Log.trace(F("simplePublishing" CR));
|
||||
// Loop through all the key-value pairs in obj
|
||||
for (JsonPair& p : data) {
|
||||
for (JsonPair p : data) {
|
||||
# if defined(ESP8266)
|
||||
yield();
|
||||
# endif
|
||||
if (p.value.is<SIGNAL_SIZE_UL_ULL>() && strcmp(p.key, "rssi") != 0) { //test rssi , bypass solution due to the fact that a int is considered as an SIGNAL_SIZE_UL_ULL
|
||||
if (strcmp(p.key, "value") == 0) { // if data is a value we don't integrate the name into the topic
|
||||
pubMQTT(topic, p.value.as<SIGNAL_SIZE_UL_ULL>());
|
||||
if (p.value().is<SIGNAL_SIZE_UL_ULL>() && strcmp(p.key().c_str(), "rssi") != 0) { //test rssi , bypass solution due to the fact that a int is considered as an SIGNAL_SIZE_UL_ULL
|
||||
if (strcmp(p.key().c_str(), "value") == 0) { // if data is a value we don't integrate the name into the topic
|
||||
pubMQTT(topic, p.value().as<SIGNAL_SIZE_UL_ULL>());
|
||||
} else { // if data is not a value we integrate the name into the topic
|
||||
pubMQTT(topic + "/" + String(p.key), p.value.as<SIGNAL_SIZE_UL_ULL>());
|
||||
pubMQTT(topic + "/" + String(p.key().c_str()), p.value().as<SIGNAL_SIZE_UL_ULL>());
|
||||
}
|
||||
} else if (p.value.is<int>()) {
|
||||
pubMQTT(topic + "/" + String(p.key), p.value.as<int>());
|
||||
} else if (p.value.is<float>()) {
|
||||
pubMQTT(topic + "/" + String(p.key), p.value.as<float>());
|
||||
} else if (p.value.is<char*>()) {
|
||||
pubMQTT(topic + "/" + String(p.key), p.value.as<const char*>());
|
||||
} else if (p.value().is<int>()) {
|
||||
pubMQTT(topic + "/" + String(p.key().c_str()), p.value().as<int>());
|
||||
} else if (p.value().is<float>()) {
|
||||
pubMQTT(topic + "/" + String(p.key().c_str()), p.value().as<float>());
|
||||
} else if (p.value().is<char*>()) {
|
||||
pubMQTT(topic + "/" + String(p.key().c_str()), p.value().as<const char*>());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -363,11 +363,11 @@ void pub(const char* topicori, const char* payload) {
|
||||
void pub_custom_topic(const char* topicori, JsonObject& data, boolean retain) {
|
||||
if (client.connected()) {
|
||||
#if defined(ESP8266) || defined(ESP32) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)
|
||||
char JSONmessageBuffer[data.measureLength() + 1];
|
||||
char JSONmessageBuffer[measureJson(data) + 1];
|
||||
#else
|
||||
char JSONmessageBuffer[JSON_MSG_BUFFER];
|
||||
#endif
|
||||
data.printTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
|
||||
serializeJson(data, JSONmessageBuffer, sizeof(JSONmessageBuffer));
|
||||
Log.trace(F("Pub json :%s into custom topic: %s" CR), JSONmessageBuffer, topicori);
|
||||
pubMQTT(topicori, JSONmessageBuffer, retain);
|
||||
} else {
|
||||
@@ -464,11 +464,11 @@ void pubMQTT(String topic, unsigned long payload) {
|
||||
|
||||
void logJson(JsonObject& jsondata) {
|
||||
#if defined(ESP8266) || defined(ESP32) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)
|
||||
char JSONmessageBuffer[jsondata.measureLength() + 1];
|
||||
char JSONmessageBuffer[measureJson(jsondata) + 1];
|
||||
#else
|
||||
char JSONmessageBuffer[JSON_MSG_BUFFER];
|
||||
#endif
|
||||
jsondata.printTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
|
||||
serializeJson(jsondata, JSONmessageBuffer, sizeof(JSONmessageBuffer));
|
||||
Log.notice(F("Received json : %s" CR), JSONmessageBuffer);
|
||||
}
|
||||
|
||||
@@ -798,7 +798,7 @@ void setup() {
|
||||
|
||||
#ifndef ARDUINO_AVR_UNO // Space issues with the UNO
|
||||
char jsonChar[100];
|
||||
modules.printTo((char*)jsonChar, modules.measureLength() + 1);
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
Log.notice(F("OpenMQTTGateway modules: %s" CR), jsonChar);
|
||||
#endif
|
||||
Log.notice(F("************** Setup OpenMQTTGateway end **************" CR));
|
||||
@@ -1021,8 +1021,7 @@ void eraseAndRestart() {
|
||||
|
||||
void saveMqttConfig() {
|
||||
Log.trace(F("saving config" CR));
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonObject& json = jsonBuffer.createObject();
|
||||
DynamicJsonDocument json(512 + ota_server_cert.length() + mqtt_cert.length());
|
||||
json["mqtt_server"] = mqtt_server;
|
||||
json["mqtt_port"] = mqtt_port;
|
||||
json["mqtt_user"] = mqtt_user;
|
||||
@@ -1039,8 +1038,8 @@ void saveMqttConfig() {
|
||||
Log.error(F("failed to open config file for writing" CR));
|
||||
}
|
||||
|
||||
json.printTo(Serial);
|
||||
json.printTo(configFile);
|
||||
serializeJsonPretty(json, Serial);
|
||||
serializeJson(json, configFile);
|
||||
configFile.close();
|
||||
}
|
||||
|
||||
@@ -1071,15 +1070,14 @@ void setup_wifimanager(bool reset_settings) {
|
||||
File configFile = SPIFFS.open("/config.json", "r");
|
||||
if (configFile) {
|
||||
Log.trace(F("opened config file" CR));
|
||||
size_t size = configFile.size();
|
||||
// Allocate a buffer to store contents of the file.
|
||||
std::unique_ptr<char[]> buf(new char[size]);
|
||||
configFile.readBytes(buf.get(), size);
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonObject& json = jsonBuffer.parseObject(buf.get());
|
||||
json.printTo(Serial);
|
||||
if (json.success()) {
|
||||
Log.trace(F("\nparsed json" CR));
|
||||
DynamicJsonDocument json(configFile.size() * 2);
|
||||
auto error = deserializeJson(json, configFile);
|
||||
if (error) {
|
||||
Log.error(F("deserialize config failed: %s, buffer capacity: %u" CR), error.c_str(), json.capacity());
|
||||
}
|
||||
serializeJsonPretty(json, Serial);
|
||||
if (!json.isNull()) {
|
||||
Log.trace(F("\nparsed json, size: %u" CR), json.memoryUsage());
|
||||
if (json.containsKey("mqtt_server"))
|
||||
strcpy(mqtt_server, json["mqtt_server"]);
|
||||
if (json.containsKey("mqtt_port"))
|
||||
@@ -1091,18 +1089,19 @@ void setup_wifimanager(bool reset_settings) {
|
||||
if (json.containsKey("mqtt_topic"))
|
||||
strcpy(mqtt_topic, json["mqtt_topic"]);
|
||||
if (json.containsKey("mqtt_broker_secure"))
|
||||
mqtt_secure = json.get<bool>("mqtt_broker_secure");
|
||||
mqtt_secure = json["mqtt_broker_secure"].as<bool>();
|
||||
if (json.containsKey("mqtt_broker_cert"))
|
||||
mqtt_cert = json.get<const char*>("mqtt_broker_cert");
|
||||
mqtt_cert = json["mqtt_broker_cert"].as<const char*>();
|
||||
if (json.containsKey("mqtt_ss_index"))
|
||||
mqtt_ss_index = json.get<uint8_t>("mqtt_ss_index");
|
||||
mqtt_ss_index = json["mqtt_ss_index"].as<uint8_t>();
|
||||
if (json.containsKey("gateway_name"))
|
||||
strcpy(gateway_name, json["gateway_name"]);
|
||||
if (json.containsKey("ota_server_cert"))
|
||||
ota_server_cert = json.get<const char*>("ota_server_cert");
|
||||
ota_server_cert = json["ota_server_cert"].as<const char*>();
|
||||
} else {
|
||||
Log.warning(F("failed to load json config" CR));
|
||||
}
|
||||
configFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1499,8 +1498,8 @@ unsigned long uptime() {
|
||||
|
||||
#if defined(ESP8266) || defined(ESP32) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)
|
||||
void stateMeasures() {
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject& SYSdata = jsonBuffer.createObject();
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject SYSdata = jsonBuffer.to<JsonObject>();
|
||||
SYSdata["uptime"] = uptime();
|
||||
SYSdata["version"] = OMG_VERSION;
|
||||
Log.trace(F("retrieving value of system characteristics Uptime (s):%u" CR), uptime());
|
||||
@@ -1572,7 +1571,7 @@ void stateMeasures() {
|
||||
SYSdata["RTLCnt"] = (int)getRTLMessageCount();
|
||||
}
|
||||
# endif
|
||||
SYSdata.set("modules", modules);
|
||||
SYSdata["modules"] = modules;
|
||||
pub(subjectSYStoMQTT, SYSdata);
|
||||
}
|
||||
#endif
|
||||
@@ -1632,19 +1631,24 @@ bool isAduplicateSignal(SIGNAL_SIZE_UL_ULL value) {
|
||||
#endif
|
||||
|
||||
void receivingMQTT(char* topicOri, char* datacallback) {
|
||||
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject& jsondata = jsonBuffer.parseObject(datacallback);
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject jsondata = jsonBuffer.to<JsonObject>();
|
||||
auto error = deserializeJson(jsonBuffer, datacallback);
|
||||
if (error) {
|
||||
Log.error(F("deserialize MQTT data failed: %s" CR), error.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(ZgatewayRF) || defined(ZgatewayIR) || defined(ZgatewaySRFB) || defined(ZgatewayWeatherStation)
|
||||
if (strstr(topicOri, subjectMultiGTWKey) != NULL) { // storing received value so as to avoid publishing this value if it has been already sent by this or another OpenMQTTGateway
|
||||
SIGNAL_SIZE_UL_ULL data = jsondata.success() ? jsondata["value"] : STRTO_UL_ULL(datacallback, NULL, 10);
|
||||
SIGNAL_SIZE_UL_ULL data = jsondata.isNull() ? STRTO_UL_ULL(datacallback, NULL, 10) : jsondata["value"];
|
||||
if (data != 0 && !isAduplicateSignal(data)) {
|
||||
storeSignalValue(data);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (jsondata.success()) { // json object ok -> json decoding
|
||||
if (!jsondata.isNull()) { // json object ok -> json decoding
|
||||
// log the received json
|
||||
logJson(jsondata);
|
||||
#ifdef ZgatewayPilight // ZgatewayPilight is only defined with json publishing due to its numerous parameters
|
||||
@@ -1933,7 +1937,7 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding
|
||||
# ifdef MQTTsetMQTT
|
||||
if (SYSdata.containsKey("mqtt_user") && SYSdata.containsKey("mqtt_pass")) {
|
||||
bool update_server = false;
|
||||
bool secure_connect = SYSdata.get<bool>("mqtt_secure");
|
||||
bool secure_connect = SYSdata["mqtt_secure"].as<bool>();
|
||||
void* prev_client = nullptr;
|
||||
bool use_ss_cert = SYSdata.containsKey("mqtt_cert_index");
|
||||
uint8_t cert_index = mqtt_ss_index;
|
||||
@@ -1974,7 +1978,7 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding
|
||||
setupTLS(use_ss_cert, cert_index);
|
||||
}
|
||||
|
||||
client.setServer(SYSdata.get<const char*>("mqtt_server"), SYSdata.get<unsigned int>("mqtt_port"));
|
||||
client.setServer(SYSdata["mqtt_server"].as<const char*>(), SYSdata["mqtt_port"].as<unsigned int>());
|
||||
} else {
|
||||
# if defined(ZgatewayBT) && defined(ESP32)
|
||||
stopProcessing();
|
||||
@@ -2040,7 +2044,7 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding
|
||||
|
||||
#ifdef ZmqttDiscovery
|
||||
if (SYSdata.containsKey("discovery")) {
|
||||
if (SYSdata.is<bool>("discovery")) {
|
||||
if (SYSdata["discovery"].is<bool>()) {
|
||||
disc = SYSdata["discovery"];
|
||||
if (disc)
|
||||
pubMqttDiscovery();
|
||||
|
||||
+2
-1
@@ -84,7 +84,7 @@ extra_configs =
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
[libraries]
|
||||
arduinojson = ArduinoJson@5.13.4
|
||||
arduinojson = https://github.com/bblanchon/ArduinoJson.git@6.18.3
|
||||
arduinolog = https://github.com/1technophile/Arduino-Log.git#d13cd80
|
||||
pubsubclient = PubSubClient@2.8
|
||||
rc-switch = https://github.com/1technophile/rc-switch.git#36dfb45
|
||||
@@ -1044,6 +1044,7 @@ build_flags =
|
||||
${com-arduino-low-memory.build_flags}
|
||||
'-DZgatewayRF="RF"'
|
||||
'-DGateway_Name="OMG_1_RF"'
|
||||
'-DDISABLE_LOGGING'
|
||||
|
||||
[env:uno-fastled]
|
||||
platform = ${com.atmelavr_platform}
|
||||
|
||||
Reference in new issue
Block a user