Version 1.11

Web interface minor redesign.
Main code minor changes.
This commit is contained in:
2023-01-12 12:27:38 +03:00
parent e551dfa0fa
commit dfabdd080a
4 changed files with 32 additions and 36 deletions

View File

@ -22,11 +22,11 @@ String getValue(String data, char separator, byte index);
void changeLedState(void);
const String firmware{"1.1"};
const String firmware{"1.11"};
String espnowNetName{"DEFAULT"};
String deviceName{"ESP-NOW light/led strip"};
String deviceName = "ESP-NOW light " + String(ESP.getChipId(), HEX);
uint8_t ledType{ENLT_NONE};
bool ledStatus{false};
@ -46,6 +46,9 @@ bool wasMqttAvailable{false};
uint8_t gatewayMAC[6]{0};
const String payloadOn{"ON"};
const String payloadOff{"OFF"};
ZHNetwork myNet;
AsyncWebServer webServer(80);
@ -106,7 +109,7 @@ void setup()
myNet.setOnConfirmReceivingCallback(onConfirmReceiving);
WiFi.mode(WIFI_AP_STA);
WiFi.softAP(("ESP-NOW Light " + myNet.getNodeMac()).c_str(), "12345678", 1, 0);
WiFi.softAP(("ESP-NOW light " + String(ESP.getChipId(), HEX)).c_str(), "12345678", 1, 0);
apModeHideTimer.once(300, apModeHideTimerCallback);
setupWebServer();
@ -165,7 +168,7 @@ void onUnicastReceiving(const char *data, const byte *sender)
{
deserializeJson(json, incomingData.message);
if (json["set"])
ledStatus = json["set"] == "ON" ? true : false;
ledStatus = json["set"] == payloadOn ? true : false;
if (json["brightness"])
brightness = json["brightness"];
if (json["temperature"])
@ -181,7 +184,7 @@ void onUnicastReceiving(const char *data, const byte *sender)
}
if (incomingData.payloadsType == ENPT_UPDATE)
{
WiFi.softAP(("ESP-NOW Light " + myNet.getNodeMac()).c_str(), "12345678", 1, 0);
WiFi.softAP(("ESP-NOW light " + String(ESP.getChipId(), HEX)).c_str(), "12345678", 1, 0);
webServer.begin();
apModeHideTimer.once(300, apModeHideTimerCallback);
}
@ -311,7 +314,7 @@ void sendAttributesMessage()
uint32_t days = hours / 24;
esp_now_payload_data_t outgoingData{ENDT_LED, ENPT_ATTRIBUTES};
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
json["Type"] = "ESP-NOW Led/Light Strip";
json["Type"] = "ESP-NOW light";
json["MCU"] = "ESP8266";
json["MAC"] = myNet.getNodeMac();
json["Firmware"] = firmware;
@ -352,6 +355,8 @@ void sendConfigMessage()
json["unit"] = 1;
json["type"] = HACT_LIGHT;
json["class"] = ledType;
json["payload_on"] = payloadOn;
json["payload_off"] = payloadOff;
char buffer[sizeof(esp_now_payload_data_t::message)]{0};
serializeJsonPretty(json, buffer);
memcpy(outgoingData.message, buffer, sizeof(esp_now_payload_data_t::message));
@ -360,7 +365,7 @@ void sendConfigMessage()
myNet.sendUnicastMessage(temp, gatewayMAC, true);
configMessageResendTimerSemaphore = true;
configMessageResendTimer.once(5, sendConfigMessage);
configMessageResendTimer.once(1, sendConfigMessage);
}
void sendStatusMessage()
@ -370,7 +375,7 @@ void sendStatusMessage()
statusMessageTimerSemaphore = false;
esp_now_payload_data_t outgoingData{ENDT_LED, ENPT_STATE};
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
json["state"] = ledStatus ? "ON" : "OFF";
json["state"] = ledStatus ? payloadOn : payloadOff;
json["brightness"] = brightness;
json["temperature"] = temperature;
json["rgb"] = String(red) + "," + String(green) + "," + String(blue);
@ -471,7 +476,7 @@ void gatewayAvailabilityCheckTimerCallback()
void apModeHideTimerCallback()
{
WiFi.softAP(("ESP-NOW Light " + myNet.getNodeMac()).c_str(), "12345678", 1, 1);
WiFi.softAP(("ESP-NOW light " + String(ESP.getChipId(), HEX)).c_str(), "12345678", 1, 1);
webServer.end();
}