Version 1.11
Web interface minor redesign. Main code minor changes.
This commit is contained in:
parent
e551dfa0fa
commit
dfabdd080a
@ -5,12 +5,12 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=0.9">
|
<meta name="viewport" content="width=device-width, initial-scale=0.9">
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="style.css">
|
||||||
<script type="text/javascript" src="function.js"></script>
|
<script type="text/javascript" src="function.js"></script>
|
||||||
<title>ESP-NOW Led/Light Strip</title>
|
<title>ESP-NOW Light</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body onload="load();">
|
<body onload="load();">
|
||||||
<form class="box">
|
<form class="box">
|
||||||
<h1>ESP-NOW Led/Light Strip </h1>
|
<h1>ESP-NOW Light </h1>
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
<p class="text">Firmware:</p>
|
<p class="text">Firmware:</p>
|
||||||
<p class="text" id="version"></p>
|
<p class="text" id="version"></p>
|
||||||
|
@ -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,6 +25,8 @@ 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 {
|
||||||
@ -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;
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
[env:esp8266]
|
[env:ESP-12E]
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
board = esp12e
|
board = esp12e
|
||||||
framework = arduino
|
framework = arduino
|
||||||
@ -8,7 +8,7 @@ lib_deps =
|
|||||||
bblanchon/ArduinoJson@^6.19.4
|
bblanchon/ArduinoJson@^6.19.4
|
||||||
me-no-dev/ESP Async WebServer@^1.2.3
|
me-no-dev/ESP Async WebServer@^1.2.3
|
||||||
|
|
||||||
[env:esp8266-ota]
|
[env:ESP-12E-OTA]
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
board = esp12e
|
board = esp12e
|
||||||
framework = arduino
|
framework = arduino
|
||||||
@ -18,26 +18,4 @@ lib_deps =
|
|||||||
https://github.com/aZholtikov/ZHNetwork
|
https://github.com/aZholtikov/ZHNetwork
|
||||||
https://github.com/aZholtikov/ZHConfig
|
https://github.com/aZholtikov/ZHConfig
|
||||||
bblanchon/ArduinoJson@^6.19.4
|
bblanchon/ArduinoJson@^6.19.4
|
||||||
me-no-dev/ESP Async WebServer@^1.2.3
|
me-no-dev/ESP Async WebServer@^1.2.3
|
||||||
|
|
||||||
[env:esp8285]
|
|
||||||
platform = espressif8266
|
|
||||||
board = esp8285
|
|
||||||
framework = arduino
|
|
||||||
lib_deps =
|
|
||||||
https://github.com/aZholtikov/ZHNetwork
|
|
||||||
https://github.com/aZholtikov/ZHConfig
|
|
||||||
bblanchon/ArduinoJson@^6.19.4
|
|
||||||
me-no-dev/ESP Async WebServer@^1.2.3
|
|
||||||
|
|
||||||
[env:esp8285-ota]
|
|
||||||
platform = espressif8266
|
|
||||||
board = esp8285
|
|
||||||
framework = arduino
|
|
||||||
upload_port = 192.168.4.1
|
|
||||||
upload_protocol = espota
|
|
||||||
lib_deps =
|
|
||||||
https://github.com/aZholtikov/ZHNetwork
|
|
||||||
https://github.com/aZholtikov/ZHConfig
|
|
||||||
bblanchon/ArduinoJson@^6.19.4
|
|
||||||
me-no-dev/ESP Async WebServer@^1.2.3
|
|
23
src/main.cpp
23
src/main.cpp
@ -22,11 +22,11 @@ String getValue(String data, char separator, byte index);
|
|||||||
|
|
||||||
void changeLedState(void);
|
void changeLedState(void);
|
||||||
|
|
||||||
const String firmware{"1.1"};
|
const String firmware{"1.11"};
|
||||||
|
|
||||||
String espnowNetName{"DEFAULT"};
|
String espnowNetName{"DEFAULT"};
|
||||||
|
|
||||||
String deviceName{"ESP-NOW light/led strip"};
|
String deviceName = "ESP-NOW light " + String(ESP.getChipId(), HEX);
|
||||||
|
|
||||||
uint8_t ledType{ENLT_NONE};
|
uint8_t ledType{ENLT_NONE};
|
||||||
bool ledStatus{false};
|
bool ledStatus{false};
|
||||||
@ -46,6 +46,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);
|
||||||
|
|
||||||
@ -106,7 +109,7 @@ void setup()
|
|||||||
myNet.setOnConfirmReceivingCallback(onConfirmReceiving);
|
myNet.setOnConfirmReceivingCallback(onConfirmReceiving);
|
||||||
|
|
||||||
WiFi.mode(WIFI_AP_STA);
|
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);
|
apModeHideTimer.once(300, apModeHideTimerCallback);
|
||||||
|
|
||||||
setupWebServer();
|
setupWebServer();
|
||||||
@ -165,7 +168,7 @@ void onUnicastReceiving(const char *data, const byte *sender)
|
|||||||
{
|
{
|
||||||
deserializeJson(json, incomingData.message);
|
deserializeJson(json, incomingData.message);
|
||||||
if (json["set"])
|
if (json["set"])
|
||||||
ledStatus = json["set"] == "ON" ? true : false;
|
ledStatus = json["set"] == payloadOn ? true : false;
|
||||||
if (json["brightness"])
|
if (json["brightness"])
|
||||||
brightness = json["brightness"];
|
brightness = json["brightness"];
|
||||||
if (json["temperature"])
|
if (json["temperature"])
|
||||||
@ -181,7 +184,7 @@ void onUnicastReceiving(const char *data, const byte *sender)
|
|||||||
}
|
}
|
||||||
if (incomingData.payloadsType == ENPT_UPDATE)
|
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();
|
webServer.begin();
|
||||||
apModeHideTimer.once(300, apModeHideTimerCallback);
|
apModeHideTimer.once(300, apModeHideTimerCallback);
|
||||||
}
|
}
|
||||||
@ -311,7 +314,7 @@ void sendAttributesMessage()
|
|||||||
uint32_t days = hours / 24;
|
uint32_t days = hours / 24;
|
||||||
esp_now_payload_data_t outgoingData{ENDT_LED, ENPT_ATTRIBUTES};
|
esp_now_payload_data_t outgoingData{ENDT_LED, ENPT_ATTRIBUTES};
|
||||||
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
|
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["MCU"] = "ESP8266";
|
||||||
json["MAC"] = myNet.getNodeMac();
|
json["MAC"] = myNet.getNodeMac();
|
||||||
json["Firmware"] = firmware;
|
json["Firmware"] = firmware;
|
||||||
@ -352,6 +355,8 @@ void sendConfigMessage()
|
|||||||
json["unit"] = 1;
|
json["unit"] = 1;
|
||||||
json["type"] = HACT_LIGHT;
|
json["type"] = HACT_LIGHT;
|
||||||
json["class"] = ledType;
|
json["class"] = ledType;
|
||||||
|
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));
|
||||||
@ -360,7 +365,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()
|
||||||
@ -370,7 +375,7 @@ void sendStatusMessage()
|
|||||||
statusMessageTimerSemaphore = false;
|
statusMessageTimerSemaphore = false;
|
||||||
esp_now_payload_data_t outgoingData{ENDT_LED, ENPT_STATE};
|
esp_now_payload_data_t outgoingData{ENDT_LED, ENPT_STATE};
|
||||||
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
|
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
|
||||||
json["state"] = ledStatus ? "ON" : "OFF";
|
json["state"] = ledStatus ? payloadOn : payloadOff;
|
||||||
json["brightness"] = brightness;
|
json["brightness"] = brightness;
|
||||||
json["temperature"] = temperature;
|
json["temperature"] = temperature;
|
||||||
json["rgb"] = String(red) + "," + String(green) + "," + String(blue);
|
json["rgb"] = String(red) + "," + String(green) + "," + String(blue);
|
||||||
@ -471,7 +476,7 @@ void gatewayAvailabilityCheckTimerCallback()
|
|||||||
|
|
||||||
void apModeHideTimerCallback()
|
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();
|
webServer.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user