Compare commits
3 Commits
c248a08efe
...
ceb80d8bd7
Author | SHA1 | Date | |
---|---|---|---|
ceb80d8bd7 | |||
53464acb22 | |||
af8cc16675 |
20
src/main.cpp
20
src/main.cpp
@ -172,7 +172,7 @@ void onBroadcastReceiving(const char *data, const uint8_t *sender)
|
||||
if (myNet.macToString(gatewayMAC) == myNet.macToString(sender) && incomingData.payloadsType == ENPT_KEEP_ALIVE)
|
||||
{
|
||||
isGatewayAvailable = true;
|
||||
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
|
||||
DynamicJsonDocument json(sizeof(esp_now_payload_data_t::message));
|
||||
deserializeJson(json, incomingData.message);
|
||||
bool temp = json["MQTT"] == "online" ? true : false;
|
||||
if (wasMqttAvailable != temp)
|
||||
@ -201,7 +201,7 @@ void onUnicastReceiving(const char *data, const uint8_t *sender)
|
||||
memcpy(&incomingData, data, sizeof(esp_now_payload_data_t));
|
||||
if (incomingData.deviceType != ENDT_GATEWAY || myNet.macToString(gatewayMAC) != myNet.macToString(sender))
|
||||
return;
|
||||
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
|
||||
DynamicJsonDocument json(sizeof(esp_now_payload_data_t::message));
|
||||
if (incomingData.payloadsType == ENPT_SET)
|
||||
{
|
||||
deserializeJson(json, incomingData.message);
|
||||
@ -287,9 +287,9 @@ void loadStatus(void)
|
||||
saveStatus();
|
||||
File file = LittleFS.open("/status.json", "r");
|
||||
String jsonFile = file.readString();
|
||||
DynamicJsonDocument json(32);
|
||||
DynamicJsonDocument json(64); // To calculate the buffer size uses https://arduinojson.org/v6/assistant.
|
||||
deserializeJson(json, jsonFile);
|
||||
relayStatus = json["relayStatus"];
|
||||
relayStatus = json["status"];
|
||||
file.close();
|
||||
delay(50);
|
||||
ETS_GPIO_INTR_ENABLE();
|
||||
@ -298,8 +298,8 @@ void loadStatus(void)
|
||||
void saveStatus(void)
|
||||
{
|
||||
ETS_GPIO_INTR_DISABLE();
|
||||
DynamicJsonDocument json(32);
|
||||
json["relayStatus"] = relayStatus;
|
||||
DynamicJsonDocument json(48); // To calculate the buffer size uses https://arduinojson.org/v6/assistant.
|
||||
json["status"] = relayStatus;
|
||||
json["system"] = "empty";
|
||||
File file = LittleFS.open("/status.json", "w");
|
||||
serializeJsonPretty(json, file);
|
||||
@ -340,7 +340,7 @@ void setupWebServer()
|
||||
webServer.on("/config", HTTP_GET, [](AsyncWebServerRequest *request)
|
||||
{
|
||||
String configJson;
|
||||
DynamicJsonDocument json(512);
|
||||
DynamicJsonDocument json(384); // To calculate the buffer size uses https://arduinojson.org/v6/assistant.
|
||||
json["firmware"] = config.firmware;
|
||||
json["espnowNetName"] = config.espnowNetName;
|
||||
json["deviceName"] = config.deviceName;
|
||||
@ -407,7 +407,7 @@ void sendAttributesMessage(const uint8_t type)
|
||||
uint32_t days = hours / 24;
|
||||
esp_now_payload_data_t outgoingData{ENDT_SWITCH, ENPT_ATTRIBUTES};
|
||||
espnow_message_t message;
|
||||
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
|
||||
DynamicJsonDocument json(sizeof(esp_now_payload_data_t::message));
|
||||
if (type == ENST_NONE)
|
||||
json["Type"] = "ESP-NOW switch";
|
||||
else
|
||||
@ -446,7 +446,7 @@ void sendConfigMessage(const uint8_t type)
|
||||
return;
|
||||
esp_now_payload_data_t outgoingData{ENDT_SWITCH, ENPT_CONFIG};
|
||||
espnow_message_t message;
|
||||
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
|
||||
DynamicJsonDocument json(sizeof(esp_now_payload_data_t::message));
|
||||
if (type == ENST_NONE)
|
||||
{
|
||||
json[MCMT_DEVICE_NAME] = config.deviceName;
|
||||
@ -498,7 +498,7 @@ void sendStatusMessage(const uint8_t type)
|
||||
statusMessageTimerSemaphore = false;
|
||||
esp_now_payload_data_t outgoingData{ENDT_SWITCH, ENPT_STATE};
|
||||
espnow_message_t message;
|
||||
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
|
||||
DynamicJsonDocument json(sizeof(esp_now_payload_data_t::message));
|
||||
if (type == ENST_NONE)
|
||||
json["state"] = relayStatus ? "ON" : "OFF";
|
||||
if (type == ENST_DS18B20)
|
||||
|
Reference in New Issue
Block a user