11 Commits
v1.12 ... v1.2

Author SHA1 Message Date
00576355ff Fixed one bug 2023-02-26 14:20:48 +03:00
17db726612 Changed SDK version for 3.0.5 2023-02-26 09:33:13 +03:00
6fffb45489 Version 1.2
Minimized of config message size.
2023-02-25 14:40:32 +03:00
3347c4d097 Minor changes 2023-02-19 09:25:22 +03:00
ed42021c9b Version 1.15
Minor changes.
2023-02-12 18:42:57 +03:00
02b8326b80 Minor changes 2023-02-11 08:42:57 +03:00
0795911f7a Minor changes 2023-02-09 21:28:56 +03:00
dc9f08e82c Version 1.14
Changed FS from SPIFFS to LittleFS.
2023-02-04 10:57:34 +03:00
4d8146e64b Changed FS from SPIFFS to LittleFS 2023-02-02 20:31:16 +03:00
39a13599c3 Minor changes 2023-01-28 14:52:38 +03:00
bcda1c9ea5 Version 1.13
Added encrypting messages.
2023-01-22 12:38:53 +03:00
3 changed files with 46 additions and 28 deletions

View File

@ -4,7 +4,7 @@ ESP-NOW based light/led strip controller for ESP8266. Alternate firmware for Tuy
## Features ## Features
1. After turn on (or after rebooting) creates an access point named "ESP-NOW Light XXXXXXXXXXXX" with password "12345678" (IP 192.168.4.1). Access point will be shown during 5 minutes. The rest of the time access point is a hidden. 1. After turn on (or after rebooting) creates an access point named "ESP-NOW light XXXXXXXXXXXX" with password "12345678" (IP 192.168.4.1). Access point will be shown during 5 minutes. The rest of the time access point is a hidden.
2. Periodically transmission of system information (every 60 seconds), availability status (every 10 seconds) and state status (every 300 seconds) to the gateway. 2. Periodically transmission of system information (every 60 seconds), availability status (every 10 seconds) and state status (every 300 seconds) to the gateway.
3. Saves the last state when the power is turned off. Goes to the last state when the power is turned on. 3. Saves the last state when the power is turned off. Goes to the last state when the power is turned on.
4. Automatically adds light/led strip configuration to Home Assistan via MQTT discovery as a light. 4. Automatically adds light/led strip configuration to Home Assistan via MQTT discovery as a light.
@ -25,5 +25,8 @@ See [here](https://github.com/aZholtikov/ESP-NOW-Light-Led-Strip/tree/main/hardw
1. A gateway is required. For details see [ESP-NOW Gateway](https://github.com/aZholtikov/ESP-NOW-Gateway). 1. A gateway is required. For details see [ESP-NOW Gateway](https://github.com/aZholtikov/ESP-NOW-Gateway).
2. ESP-NOW network name must be set same of all another ESP-NOW devices in network. 2. ESP-NOW network name must be set same of all another ESP-NOW devices in network.
3. Upload the "data" folder (with web interface) into the filesystem before flashing. 3. If encryption is used, the key must be set same of all another ESP-NOW devices in network.
4. For using this firmware on Tuya/SmartLife WiFi light/led strip controllers, the WiFi module must be replaced with an ESP8266 compatible module (if necessary). 4. Upload the "data" folder (with web interface) into the filesystem before flashing.
5. For using this firmware on Tuya/SmartLife WiFi light/led strip controllers, the WiFi module must be replaced with an ESP8266 compatible module (if necessary).
Any feedback via [e-mail](mailto:github@zh.com.ru) would be appreciated. Or... [Buy me a coffee](https://paypal.me/aZholtikov).

View File

@ -2,20 +2,26 @@
platform = espressif8266 platform = espressif8266
board = esp12e board = esp12e
framework = arduino framework = arduino
build_flags = -D PIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK305
board_build.filesystem = littlefs
board_build.ldscript = eagle.flash.4m1m.ld
lib_deps = 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 https://github.com/aZholtikov/Async-Web-Server
me-no-dev/ESP Async WebServer@^1.2.3 https://github.com/bblanchon/ArduinoJson
[env:ESP-12E-OTA] [env:ESP-12E-OTA]
platform = espressif8266 platform = espressif8266
board = esp12e board = esp12e
framework = arduino framework = arduino
build_flags = -D PIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK305
board_build.filesystem = littlefs
board_build.ldscript = eagle.flash.4m1m.ld
upload_port = 192.168.4.1 upload_port = 192.168.4.1
upload_protocol = espota upload_protocol = espota
lib_deps = 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 https://github.com/aZholtikov/Async-Web-Server
me-no-dev/ESP Async WebServer@^1.2.3 https://github.com/bblanchon/ArduinoJson

View File

@ -1,6 +1,7 @@
#include "ArduinoJson.h" #include "ArduinoJson.h"
#include "ArduinoOTA.h" #include "ArduinoOTA.h"
#include "ESPAsyncWebServer.h" #include "ESPAsyncWebServer.h" // https://github.com/aZholtikov/Async-Web-Server
#include "LittleFS.h"
#include "Ticker.h" #include "Ticker.h"
#include "ZHNetwork.h" #include "ZHNetwork.h"
#include "ZHConfig.h" #include "ZHConfig.h"
@ -30,20 +31,20 @@ typedef struct
std::vector<espnow_message_t> espnowMessage; std::vector<espnow_message_t> espnowMessage;
const String firmware{"1.12"}; const String firmware{"1.2"};
String espnowNetName{"DEFAULT"}; String espnowNetName{"DEFAULT"};
String deviceName = "ESP-NOW light " + String(ESP.getChipId(), HEX); String deviceName = "ESP-NOW light " + String(ESP.getChipId(), HEX);
uint8_t ledType{ENLT_NONE}; uint8_t ledType{ENLT_NONE};
bool ledStatus{false};
uint8_t coldWhitePin{0}; uint8_t coldWhitePin{0};
uint8_t warmWhitePin{0}; uint8_t warmWhitePin{0};
uint8_t redPin{0}; uint8_t redPin{0};
uint8_t greenPin{0}; uint8_t greenPin{0};
uint8_t bluePin{0}; uint8_t bluePin{0};
bool ledStatus{false};
uint8_t brightness{255}; uint8_t brightness{255};
uint16_t temperature{255}; uint16_t temperature{255};
uint8_t red{255}; uint8_t red{255};
@ -54,9 +55,6 @@ 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);
@ -83,7 +81,7 @@ void setup()
{ {
analogWriteRange(255); analogWriteRange(255);
SPIFFS.begin(); LittleFS.begin();
loadConfig(); loadConfig();
@ -102,6 +100,7 @@ void setup()
WiFi.setSleepMode(WIFI_NONE_SLEEP); WiFi.setSleepMode(WIFI_NONE_SLEEP);
myNet.begin(espnowNetName.c_str()); myNet.begin(espnowNetName.c_str());
// myNet.setCryptKey("VERY_LONG_CRYPT_KEY"); // If encryption is used, the key must be set same of all another ESP-NOW devices in network.
myNet.setOnBroadcastReceivingCallback(onBroadcastReceiving); myNet.setOnBroadcastReceivingCallback(onBroadcastReceiving);
myNet.setOnUnicastReceivingCallback(onUnicastReceiving); myNet.setOnUnicastReceivingCallback(onUnicastReceiving);
@ -150,7 +149,11 @@ void onBroadcastReceiving(const char *data, const uint8_t *sender)
{ {
wasMqttAvailable = temp; wasMqttAvailable = temp;
if (temp) if (temp)
{
sendConfigMessage(); sendConfigMessage();
sendAttributesMessage();
sendStatusMessage();
}
} }
gatewayAvailabilityCheckTimer.once(15, gatewayAvailabilityCheckTimerCallback); gatewayAvailabilityCheckTimer.once(15, gatewayAvailabilityCheckTimerCallback);
} }
@ -167,7 +170,7 @@ void onUnicastReceiving(const char *data, const uint8_t *sender)
{ {
deserializeJson(json, incomingData.message); deserializeJson(json, incomingData.message);
if (json["set"]) if (json["set"])
ledStatus = json["set"] == payloadOn ? true : false; ledStatus = json["set"] == "ON" ? true : false;
if (json["brightness"]) if (json["brightness"])
brightness = json["brightness"]; brightness = json["brightness"];
if (json["temperature"]) if (json["temperature"])
@ -197,6 +200,7 @@ void onConfirmReceiving(const uint8_t *target, const uint16_t id, const bool sta
{ {
espnow_message_t message = espnowMessage[i]; espnow_message_t message = espnowMessage[i];
if (message.id == id) if (message.id == id)
{
if (status) if (status)
espnowMessage.erase(espnowMessage.begin() + i); espnowMessage.erase(espnowMessage.begin() + i);
else else
@ -205,13 +209,15 @@ void onConfirmReceiving(const uint8_t *target, const uint16_t id, const bool sta
espnowMessage.at(i) = message; espnowMessage.at(i) = message;
} }
} }
}
} }
void loadConfig() void loadConfig()
{ {
if (!SPIFFS.exists("/config.json")) ETS_GPIO_INTR_DISABLE();
if (!LittleFS.exists("/config.json"))
saveConfig(); saveConfig();
File file = SPIFFS.open("/config.json", "r"); File file = LittleFS.open("/config.json", "r");
String jsonFile = file.readString(); String jsonFile = file.readString();
StaticJsonDocument<512> json; StaticJsonDocument<512> json;
deserializeJson(json, jsonFile); deserializeJson(json, jsonFile);
@ -230,10 +236,13 @@ void loadConfig()
green = json["green"]; green = json["green"];
blue = json["blue"]; blue = json["blue"];
file.close(); file.close();
delay(50);
ETS_GPIO_INTR_ENABLE();
} }
void saveConfig() void saveConfig()
{ {
ETS_GPIO_INTR_DISABLE();
StaticJsonDocument<512> json; StaticJsonDocument<512> json;
json["firmware"] = firmware; json["firmware"] = firmware;
json["espnowNetName"] = espnowNetName; json["espnowNetName"] = espnowNetName;
@ -251,15 +260,17 @@ void saveConfig()
json["green"] = green; json["green"] = green;
json["blue"] = blue; json["blue"] = blue;
json["system"] = "empty"; json["system"] = "empty";
File file = SPIFFS.open("/config.json", "w"); File file = LittleFS.open("/config.json", "w");
serializeJsonPretty(json, file); serializeJsonPretty(json, file);
file.close(); file.close();
delay(50);
ETS_GPIO_INTR_ENABLE();
} }
void setupWebServer() void setupWebServer()
{ {
webServer.on("/", HTTP_GET, [](AsyncWebServerRequest *request) webServer.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
{ request->send(SPIFFS, "/index.htm"); }); { request->send(LittleFS, "/index.htm"); });
webServer.on("/setting", HTTP_GET, [](AsyncWebServerRequest *request) webServer.on("/setting", HTTP_GET, [](AsyncWebServerRequest *request)
{ {
@ -281,8 +292,8 @@ void setupWebServer()
webServer.onNotFound([](AsyncWebServerRequest *request) webServer.onNotFound([](AsyncWebServerRequest *request)
{ {
if (SPIFFS.exists(request->url())) if (LittleFS.exists(request->url()))
request->send(SPIFFS, request->url()); request->send(LittleFS, request->url());
else else
{ {
request->send(404, "text/plain", "File Not Found"); request->send(404, "text/plain", "File Not Found");
@ -336,12 +347,10 @@ void sendConfigMessage()
esp_now_payload_data_t outgoingData{ENDT_LED, ENPT_CONFIG}; esp_now_payload_data_t outgoingData{ENDT_LED, ENPT_CONFIG};
espnow_message_t message; espnow_message_t message;
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json; StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
json["name"] = deviceName; json[MCMT_DEVICE_NAME] = deviceName;
json["unit"] = 1; json[MCMT_DEVICE_UNIT] = 1;
json["type"] = HACT_LIGHT; json[MCMT_COMPONENT_TYPE] = HACT_LIGHT;
json["class"] = ledType; json[MCMT_DEVICE_CLASS] = ledType;
json["payload_on"] = payloadOn;
json["payload_off"] = payloadOff;
serializeJsonPretty(json, outgoingData.message); serializeJsonPretty(json, outgoingData.message);
memcpy(&message.message, &outgoingData, sizeof(esp_now_payload_data_t)); memcpy(&message.message, &outgoingData, sizeof(esp_now_payload_data_t));
message.id = myNet.sendUnicastMessage(message.message, gatewayMAC, true); message.id = myNet.sendUnicastMessage(message.message, gatewayMAC, true);
@ -357,7 +366,7 @@ void sendStatusMessage()
esp_now_payload_data_t outgoingData{ENDT_LED, ENPT_STATE}; esp_now_payload_data_t outgoingData{ENDT_LED, ENPT_STATE};
espnow_message_t message; espnow_message_t message;
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json; StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
json["state"] = ledStatus ? payloadOn : payloadOff; json["state"] = ledStatus ? "ON" : "OFF";
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);