Version 1.11

Web interface minor redesign.
Main code minor changes.
This commit is contained in:
Alexey Zholtikov 2023-01-12 12:30:16 +03:00
parent 439722511f
commit 82e736dc8b
3 changed files with 29 additions and 12 deletions

View File

@ -1,3 +1,7 @@
p{
margin: 0 0;
}
body { body {
font-family: "Gill Sans", sans-serif; font-family: "Gill Sans", sans-serif;
background: rgb(255, 255, 255); background: rgb(255, 255, 255);
@ -21,13 +25,15 @@ h1 {
font-weight: 600; font-weight: 600;
flex-shrink: 0; flex-shrink: 0;
margin-right: 10px; margin-right: 10px;
margin-left: 10px;
margin: 10px 0;
} }
.text-select { .text-select {
width: 35%; width: 35%;
font-weight: 600; font-weight: 600;
flex-shrink: 0; flex-shrink: 0;
margin-right: 10px; margin-right: 10px;
} }
.wrapper { .wrapper {
@ -42,6 +48,7 @@ input {
border-radius: 5px; border-radius: 5px;
border: none; border: none;
margin-bottom: 10px; margin-bottom: 10px;
margin-left: 10px;
padding: 0 10px; padding: 0 10px;
color: rgb(0, 0, 0); color: rgb(0, 0, 0);
background: #a3e0f1; background: #a3e0f1;
@ -76,6 +83,8 @@ select:hover {
background: rgb(65, 125, 238); background: rgb(65, 125, 238);
color: white; color: white;
transition: .5s; transition: .5s;
margin-left: 0;
margin-top: 8px;
} }
.btn:hover { .btn:hover {
@ -89,6 +98,10 @@ select:hover {
width: 100%; width: 100%;
} }
#espnowNetName {
margin-bottom: 15px;
}
.wrapper.wrapper--end { .wrapper.wrapper--end {
align-items: baseline; align-items: baseline;
} }

View File

@ -9,4 +9,4 @@
``` ```
2. AUBESS 1CH 16A (Coming soon) 2. AUBESS 1CH 16A (Coming soon)
3. LIGHT E27 ADAPTER (Coming soon) 3. LIGHT E27 SOCKET (Coming soon)

View File

@ -21,11 +21,11 @@ void sendKeepAliveMessage(void);
void sendConfigMessage(void); void sendConfigMessage(void);
void sendStatusMessage(void); void sendStatusMessage(void);
const String firmware{"1.1"}; const String firmware{"1.11"};
String espnowNetName{"DEFAULT"}; String espnowNetName{"DEFAULT"};
String deviceName{"ESP-NOW switch"}; String deviceName = "ESP-NOW switch " + String(ESP.getChipId(), HEX);
bool relayStatus{false}; bool relayStatus{false};
uint8_t relayPin{0}; uint8_t relayPin{0};
@ -41,6 +41,9 @@ bool wasMqttAvailable{false};
uint8_t gatewayMAC[6]{0}; uint8_t gatewayMAC[6]{0};
const String payloadOn{"ON"};
const String payloadOff{"OFF"};
ZHNetwork myNet; ZHNetwork myNet;
AsyncWebServer webServer(80); AsyncWebServer webServer(80);
@ -103,7 +106,7 @@ void setup()
myNet.setOnConfirmReceivingCallback(onConfirmReceiving); myNet.setOnConfirmReceivingCallback(onConfirmReceiving);
WiFi.mode(WIFI_AP_STA); WiFi.mode(WIFI_AP_STA);
WiFi.softAP(("ESP-NOW Switch " + myNet.getNodeMac()).c_str(), "12345678", 1, 0); WiFi.softAP(("ESP-NOW switch " + String(ESP.getChipId(), HEX)).c_str(), "12345678", 1, 0);
apModeHideTimer.once(300, apModeHideTimerCallback); apModeHideTimer.once(300, apModeHideTimerCallback);
setupWebServer(); setupWebServer();
@ -161,7 +164,7 @@ void onUnicastReceiving(const char *data, const uint8_t *sender)
if (incomingData.payloadsType == ENPT_SET) if (incomingData.payloadsType == ENPT_SET)
{ {
deserializeJson(json, incomingData.message); deserializeJson(json, incomingData.message);
relayStatus = json["set"] == "ON" ? true : false; relayStatus = json["set"] == payloadOn ? true : false;
if (relayPin) if (relayPin)
digitalWrite(relayPin, relayPinType ? relayStatus : !relayStatus); digitalWrite(relayPin, relayPinType ? relayStatus : !relayStatus);
if (ledPin) if (ledPin)
@ -171,7 +174,7 @@ void onUnicastReceiving(const char *data, const uint8_t *sender)
} }
if (incomingData.payloadsType == ENPT_UPDATE) if (incomingData.payloadsType == ENPT_UPDATE)
{ {
WiFi.softAP(("ESP-NOW Switch " + myNet.getNodeMac()).c_str(), "12345678", 1, 0); WiFi.softAP(("ESP-NOW switch " + String(ESP.getChipId(), HEX)).c_str(), "12345678", 1, 0);
webServer.begin(); webServer.begin();
apModeHideTimer.once(300, apModeHideTimerCallback); apModeHideTimer.once(300, apModeHideTimerCallback);
} }
@ -315,7 +318,7 @@ void sendAttributesMessage()
uint32_t days = hours / 24; uint32_t days = hours / 24;
esp_now_payload_data_t outgoingData{ENDT_SWITCH, ENPT_ATTRIBUTES}; esp_now_payload_data_t outgoingData{ENDT_SWITCH, ENPT_ATTRIBUTES};
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json; StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
json["Type"] = "ESP-NOW Switch"; json["Type"] = "ESP-NOW switch";
json["MCU"] = "ESP8266"; json["MCU"] = "ESP8266";
json["MAC"] = myNet.getNodeMac(); json["MAC"] = myNet.getNodeMac();
json["Firmware"] = firmware; json["Firmware"] = firmware;
@ -356,7 +359,8 @@ void sendConfigMessage()
json["unit"] = 1; json["unit"] = 1;
json["type"] = HACT_SWITCH; json["type"] = HACT_SWITCH;
json["class"] = HASWDC_SWITCH; json["class"] = HASWDC_SWITCH;
json["reverse"] = "false"; json["payload_on"] = payloadOn;
json["payload_off"] = payloadOff;
char buffer[sizeof(esp_now_payload_data_t::message)]{0}; char buffer[sizeof(esp_now_payload_data_t::message)]{0};
serializeJsonPretty(json, buffer); serializeJsonPretty(json, buffer);
memcpy(outgoingData.message, buffer, sizeof(esp_now_payload_data_t::message)); memcpy(outgoingData.message, buffer, sizeof(esp_now_payload_data_t::message));
@ -365,7 +369,7 @@ void sendConfigMessage()
myNet.sendUnicastMessage(temp, gatewayMAC, true); myNet.sendUnicastMessage(temp, gatewayMAC, true);
configMessageResendTimerSemaphore = true; configMessageResendTimerSemaphore = true;
configMessageResendTimer.once(5, sendConfigMessage); configMessageResendTimer.once(1, sendConfigMessage);
} }
void sendStatusMessage() void sendStatusMessage()
@ -375,7 +379,7 @@ void sendStatusMessage()
statusMessageTimerSemaphore = false; statusMessageTimerSemaphore = false;
esp_now_payload_data_t outgoingData{ENDT_SWITCH, ENPT_STATE}; esp_now_payload_data_t outgoingData{ENDT_SWITCH, ENPT_STATE};
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json; StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
json["state"] = relayStatus ? "ON" : "OFF"; json["state"] = relayStatus ? payloadOn : payloadOff;
char buffer[sizeof(esp_now_payload_data_t::message)]{0}; char buffer[sizeof(esp_now_payload_data_t::message)]{0};
serializeJsonPretty(json, buffer); serializeJsonPretty(json, buffer);
memcpy(&outgoingData.message, &buffer, sizeof(esp_now_payload_data_t::message)); memcpy(&outgoingData.message, &buffer, sizeof(esp_now_payload_data_t::message));
@ -395,7 +399,7 @@ void gatewayAvailabilityCheckTimerCallback()
void apModeHideTimerCallback() void apModeHideTimerCallback()
{ {
WiFi.softAP(("ESP-NOW Switch " + myNet.getNodeMac()).c_str(), "12345678", 1, 1); WiFi.softAP(("ESP-NOW switch " + String(ESP.getChipId(), HEX)).c_str(), "12345678", 1, 1);
webServer.end(); webServer.end();
} }