Compare commits
3 Commits
3347c4d097
...
00576355ff
Author | SHA1 | Date | |
---|---|---|---|
00576355ff | |||
17db726612 | |||
6fffb45489 |
@ -2,6 +2,7 @@
|
|||||||
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 =
|
||||||
@ -14,6 +15,7 @@ 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
|
||||||
|
27
src/main.cpp
27
src/main.cpp
@ -31,20 +31,20 @@ typedef struct
|
|||||||
|
|
||||||
std::vector<espnow_message_t> espnowMessage;
|
std::vector<espnow_message_t> espnowMessage;
|
||||||
|
|
||||||
const String firmware{"1.15"};
|
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};
|
||||||
@ -55,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);
|
||||||
|
|
||||||
@ -173,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"])
|
||||||
@ -217,6 +214,7 @@ 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");
|
||||||
@ -238,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;
|
||||||
@ -262,6 +263,8 @@ 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()
|
||||||
@ -344,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);
|
||||||
@ -365,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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user