4 Commits
v1.1 ... v1.12

Author SHA1 Message Date
7f51f05eb8 Version 1.12
Main code refactoring.
2023-01-14 10:57:25 +03:00
dfabdd080a Version 1.11
Web interface minor redesign.
Main code minor changes.
2023-01-12 12:27:38 +03:00
e551dfa0fa Minor changes 2023-01-10 10:07:37 +03:00
1231650fb8 Updated "Tested on" 2023-01-09 18:56:08 +03:00
15 changed files with 95 additions and 105 deletions

View File

@ -19,7 +19,7 @@ ESP-NOW based light/led strip controller for ESP8266. Alternate firmware for Tuy
## Tested on
Coming soon.
See [here](https://github.com/aZholtikov/ESP-NOW-Light-Led-Strip/tree/main/hardware).
## Attention

View File

@ -5,12 +5,12 @@
<meta name="viewport" content="width=device-width, initial-scale=0.9">
<link rel="stylesheet" href="style.css">
<script type="text/javascript" src="function.js"></script>
<title>ESP-NOW Led/Light Strip</title>
<title>ESP-NOW Light</title>
</head>
<body onload="load();">
<form class="box">
<h1>ESP-NOW Led/Light Strip </h1>
<h1>ESP-NOW Light </h1>
<div class="wrapper">
<p class="text">Firmware:</p>
<p class="text" id="version"></p>

View File

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

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 MiB

13
hardware/README.md Normal file
View File

@ -0,0 +1,13 @@
# Tested on
1. AP-FUTURE RGB Led controller. Built on Tuya WiFi module WB3S (BK7231N chip). Replacement required. Performed replacement with ESP-12E. [Photo](https://github.com/aZholtikov/ESP-NOW-Light-Led-Strip/tree/main/hardware/AP-FUTURE_RGB). A connect EN to VCC is required. A pull-up to GND of GPIO15 is required (i used a 0805 10K SMD resistor on top of the module pins).
```text
Device type RGB
Red GPIO GPIO04
Green GPIO GPIO12
Blue GPIO GPIO14
```
2. FLYIDEA RGBW Light E27 15W (Coming soon)
3. FLYIDEA RGBWW Light E14 7W (Coming soon)

View File

@ -1,4 +1,4 @@
[env:esp8266]
[env:ESP-12E]
platform = espressif8266
board = esp12e
framework = arduino
@ -8,7 +8,7 @@ lib_deps =
bblanchon/ArduinoJson@^6.19.4
me-no-dev/ESP Async WebServer@^1.2.3
[env:esp8266-ota]
[env:ESP-12E-OTA]
platform = espressif8266
board = esp12e
framework = arduino
@ -18,26 +18,4 @@ 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]
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
me-no-dev/ESP Async WebServer@^1.2.3

View File

@ -7,7 +7,7 @@
void onBroadcastReceiving(const char *data, const uint8_t *sender);
void onUnicastReceiving(const char *data, const uint8_t *sender);
void onConfirmReceiving(const uint8_t *target, const bool status);
void onConfirmReceiving(const uint8_t *target, const uint16_t id, const bool status);
void loadConfig(void);
void saveConfig(void);
@ -18,15 +18,23 @@ void sendKeepAliveMessage(void);
void sendConfigMessage(void);
void sendStatusMessage(void);
String getValue(String data, char separator, byte index);
String getValue(String data, char separator, uint8_t index);
void changeLedState(void);
const String firmware{"1.1"};
typedef struct
{
uint16_t id{0};
char message[200]{0};
} espnow_message_t;
std::vector<espnow_message_t> espnowMessage;
const String firmware{"1.12"};
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 +54,9 @@ bool wasMqttAvailable{false};
uint8_t gatewayMAC[6]{0};
const String payloadOn{"ON"};
const String payloadOff{"OFF"};
ZHNetwork myNet;
AsyncWebServer webServer(80);
@ -59,23 +70,14 @@ void apModeHideTimerCallback(void);
Ticker attributesMessageTimer;
bool attributesMessageTimerSemaphore{true};
void attributesMessageTimerCallback(void);
Ticker attributesMessageResendTimer;
bool attributesMessageResendTimerSemaphore{false};
Ticker keepAliveMessageTimer;
bool keepAliveMessageTimerSemaphore{true};
void keepAliveMessageTimerCallback(void);
Ticker keepAliveMessageResendTimer;
bool keepAliveMessageResendTimerSemaphore{false};
Ticker configMessageResendTimer;
bool configMessageResendTimerSemaphore{false};
Ticker statusMessageTimer;
bool statusMessageTimerSemaphore{true};
void statusMessageTimerCallback(void);
Ticker statusMessageResendTimer;
bool statusMessageResendTimerSemaphore{false};
void setup()
{
@ -106,7 +108,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();
@ -130,14 +132,14 @@ void loop()
ArduinoOTA.handle();
}
void onBroadcastReceiving(const char *data, const byte *sender)
void onBroadcastReceiving(const char *data, const uint8_t *sender)
{
esp_now_payload_data_t incomingData;
memcpy(&incomingData, data, sizeof(esp_now_payload_data_t));
if (incomingData.deviceType != ENDT_GATEWAY)
return;
if (myNet.macToString(gatewayMAC) != myNet.macToString(sender) && incomingData.payloadsType == ENPT_KEEP_ALIVE)
memcpy(gatewayMAC, sender, 6);
memcpy(&gatewayMAC, sender, 6);
if (myNet.macToString(gatewayMAC) == myNet.macToString(sender) && incomingData.payloadsType == ENPT_KEEP_ALIVE)
{
isGatewayAvailable = true;
@ -154,7 +156,7 @@ void onBroadcastReceiving(const char *data, const byte *sender)
}
}
void onUnicastReceiving(const char *data, const byte *sender)
void onUnicastReceiving(const char *data, const uint8_t *sender)
{
esp_now_payload_data_t incomingData;
memcpy(&incomingData, data, sizeof(esp_now_payload_data_t));
@ -165,7 +167,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,37 +183,27 @@ 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);
}
if (incomingData.payloadsType == ENPT_RESTART)
ESP.restart();
}
void onConfirmReceiving(const uint8_t *target, const bool status)
void onConfirmReceiving(const uint8_t *target, const uint16_t id, const bool status)
{
if (status)
for (uint16_t i{0}; i < espnowMessage.size(); ++i)
{
if (attributesMessageResendTimerSemaphore)
{
attributesMessageResendTimerSemaphore = false;
attributesMessageResendTimer.detach();
}
if (keepAliveMessageResendTimerSemaphore)
{
keepAliveMessageResendTimerSemaphore = false;
keepAliveMessageResendTimer.detach();
}
if (configMessageResendTimerSemaphore)
{
configMessageResendTimerSemaphore = false;
configMessageResendTimer.detach();
}
if (statusMessageResendTimerSemaphore)
{
statusMessageResendTimerSemaphore = false;
statusMessageResendTimer.detach();
}
espnow_message_t message = espnowMessage[i];
if (message.id == id)
if (status)
espnowMessage.erase(espnowMessage.begin() + i);
else
{
message.id = myNet.sendUnicastMessage(message.message, gatewayMAC, true);
espnowMessage.at(i) = message;
}
}
}
@ -309,22 +301,19 @@ void sendAttributesMessage()
uint32_t hours = mins / 60;
uint32_t days = hours / 24;
esp_now_payload_data_t outgoingData{ENDT_LED, ENPT_ATTRIBUTES};
espnow_message_t message;
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;
json["Library"] = myNet.getFirmwareVersion();
json["Uptime"] = "Days:" + String(days) + " Hours:" + String(hours - (days * 24)) + " Mins:" + String(mins - (hours * 60));
char buffer[sizeof(esp_now_payload_data_t::message)]{0};
serializeJsonPretty(json, buffer);
memcpy(outgoingData.message, buffer, sizeof(esp_now_payload_data_t::message));
char temp[sizeof(esp_now_payload_data_t)]{0};
memcpy(&temp, &outgoingData, sizeof(esp_now_payload_data_t));
myNet.sendUnicastMessage(temp, gatewayMAC, true);
serializeJsonPretty(json, outgoingData.message);
memcpy(&message.message, &outgoingData, sizeof(esp_now_payload_data_t));
message.id = myNet.sendUnicastMessage(message.message, gatewayMAC, true);
attributesMessageResendTimerSemaphore = true;
attributesMessageResendTimer.once(1, sendAttributesMessage);
espnowMessage.push_back(message);
}
void sendKeepAliveMessage()
@ -333,12 +322,11 @@ void sendKeepAliveMessage()
return;
keepAliveMessageTimerSemaphore = false;
esp_now_payload_data_t outgoingData{ENDT_LED, ENPT_KEEP_ALIVE};
char temp[sizeof(esp_now_payload_data_t)]{0};
memcpy(&temp, &outgoingData, sizeof(esp_now_payload_data_t));
myNet.sendUnicastMessage(temp, gatewayMAC, true);
espnow_message_t message;
memcpy(&message.message, &outgoingData, sizeof(esp_now_payload_data_t));
message.id = myNet.sendUnicastMessage(message.message, gatewayMAC, true);
keepAliveMessageResendTimerSemaphore = true;
keepAliveMessageResendTimer.once(1, sendKeepAliveMessage);
espnowMessage.push_back(message);
}
void sendConfigMessage()
@ -346,20 +334,19 @@ void sendConfigMessage()
if (!isGatewayAvailable)
return;
esp_now_payload_data_t outgoingData{ENDT_LED, ENPT_CONFIG};
espnow_message_t message;
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
json["name"] = deviceName;
json["unit"] = 1;
json["type"] = HACT_LIGHT;
json["class"] = ledType;
char buffer[sizeof(esp_now_payload_data_t::message)]{0};
serializeJsonPretty(json, buffer);
memcpy(outgoingData.message, buffer, sizeof(esp_now_payload_data_t::message));
char temp[sizeof(esp_now_payload_data_t)]{0};
memcpy(&temp, &outgoingData, sizeof(esp_now_payload_data_t));
myNet.sendUnicastMessage(temp, gatewayMAC, true);
json["payload_on"] = payloadOn;
json["payload_off"] = payloadOff;
serializeJsonPretty(json, outgoingData.message);
memcpy(&message.message, &outgoingData, sizeof(esp_now_payload_data_t));
message.id = myNet.sendUnicastMessage(message.message, gatewayMAC, true);
configMessageResendTimerSemaphore = true;
configMessageResendTimer.once(5, sendConfigMessage);
espnowMessage.push_back(message);
}
void sendStatusMessage()
@ -368,28 +355,25 @@ void sendStatusMessage()
return;
statusMessageTimerSemaphore = false;
esp_now_payload_data_t outgoingData{ENDT_LED, ENPT_STATE};
espnow_message_t message;
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);
char buffer[sizeof(esp_now_payload_data_t::message)]{0};
serializeJsonPretty(json, buffer);
memcpy(&outgoingData.message, &buffer, sizeof(esp_now_payload_data_t::message));
char temp[sizeof(esp_now_payload_data_t)]{0};
memcpy(&temp, &outgoingData, sizeof(esp_now_payload_data_t));
myNet.sendUnicastMessage(temp, gatewayMAC, true);
serializeJsonPretty(json, outgoingData.message);
memcpy(&message.message, &outgoingData, sizeof(esp_now_payload_data_t));
message.id = myNet.sendUnicastMessage(message.message, gatewayMAC, true);
statusMessageResendTimerSemaphore = true;
statusMessageResendTimer.once(1, sendStatusMessage);
espnowMessage.push_back(message);
}
String getValue(String data, char separator, byte index)
String getValue(String data, char separator, uint8_t index)
{
byte found{0};
uint8_t found{0};
int strIndex[]{0, -1};
int maxIndex = data.length() - 1;
for (byte i{0}; i <= maxIndex && found <= index; i++)
for (uint8_t i{0}; i <= maxIndex && found <= index; i++)
if (data.charAt(i) == separator || i == maxIndex)
{
found++;
@ -465,12 +449,14 @@ void changeLedState(void)
void gatewayAvailabilityCheckTimerCallback()
{
isGatewayAvailable = false;
memset(gatewayMAC, 0, 6);
memset(&gatewayMAC, 0, 6);
espnowMessage.clear();
}
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();
}
void attributesMessageTimerCallback()