Compare commits

..

No commits in common. "00576355ffe339b2d85792350fd042149e70fdbe" and "3347c4d097440b503bbaebbe83627d4ef8937d76" have entirely different histories.

2 changed files with 13 additions and 16 deletions

View File

@ -2,7 +2,6 @@
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.filesystem = littlefs
board_build.ldscript = eagle.flash.4m1m.ld board_build.ldscript = eagle.flash.4m1m.ld
lib_deps = lib_deps =
@ -15,7 +14,6 @@ lib_deps =
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.filesystem = littlefs
board_build.ldscript = eagle.flash.4m1m.ld board_build.ldscript = eagle.flash.4m1m.ld
upload_port = 192.168.4.1 upload_port = 192.168.4.1

View File

@ -31,20 +31,20 @@ typedef struct
std::vector<espnow_message_t> espnowMessage; std::vector<espnow_message_t> espnowMessage;
const String firmware{"1.2"}; const String firmware{"1.15"};
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};
@ -55,6 +55,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);
@ -170,7 +173,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"] == "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"])
@ -214,7 +217,6 @@ void onConfirmReceiving(const uint8_t *target, const uint16_t id, const bool sta
void loadConfig() void loadConfig()
{ {
ETS_GPIO_INTR_DISABLE();
if (!LittleFS.exists("/config.json")) if (!LittleFS.exists("/config.json"))
saveConfig(); saveConfig();
File file = LittleFS.open("/config.json", "r"); File file = LittleFS.open("/config.json", "r");
@ -236,13 +238,10 @@ 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;
@ -263,8 +262,6 @@ void saveConfig()
File file = LittleFS.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()
@ -347,10 +344,12 @@ 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[MCMT_DEVICE_NAME] = deviceName; json["name"] = deviceName;
json[MCMT_DEVICE_UNIT] = 1; json["unit"] = 1;
json[MCMT_COMPONENT_TYPE] = HACT_LIGHT; json["type"] = HACT_LIGHT;
json[MCMT_DEVICE_CLASS] = ledType; json["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);
@ -366,7 +365,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 ? "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);