Compare commits
No commits in common. "651ade7334276a4e5b6147fd5c2306c836830a77" and "1aa5465687cbb3196f4f69bb3fc04eea263a92bb" have entirely different histories.
651ade7334
...
1aa5465687
@ -2,7 +2,6 @@
|
||||
platform = espressif8266
|
||||
board = esp12e
|
||||
framework = arduino
|
||||
build_flags = -D PIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK305
|
||||
board_build.filesystem = littlefs
|
||||
board_build.ldscript = eagle.flash.4m1m.ld
|
||||
lib_deps =
|
||||
@ -17,7 +16,6 @@ lib_deps =
|
||||
platform = espressif8266
|
||||
board = esp12e
|
||||
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
|
||||
@ -34,7 +32,6 @@ lib_deps =
|
||||
platform = espressif8266
|
||||
board = esp8285
|
||||
framework = arduino
|
||||
build_flags = -D PIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK305
|
||||
board_build.filesystem = littlefs
|
||||
board_build.ldscript = eagle.flash.2m64.ld
|
||||
lib_deps =
|
||||
@ -49,7 +46,6 @@ lib_deps =
|
||||
platform = espressif8266
|
||||
board = esp8285
|
||||
framework = arduino
|
||||
build_flags = -D PIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK305
|
||||
board_build.filesystem = littlefs
|
||||
board_build.ldscript = eagle.flash.2m64.ld
|
||||
upload_port = 192.168.4.1
|
||||
@ -66,7 +62,6 @@ lib_deps =
|
||||
platform = espressif8266
|
||||
board = esp8285
|
||||
framework = arduino
|
||||
build_flags = -D PIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK305
|
||||
board_build.filesystem = littlefs
|
||||
board_build.ldscript = eagle.flash.1m64.ld
|
||||
lib_deps =
|
||||
|
60
src/main.cpp
60
src/main.cpp
@ -32,7 +32,7 @@ typedef struct
|
||||
|
||||
std::vector<espnow_message_t> espnowMessage;
|
||||
|
||||
const String firmware{"1.4"};
|
||||
const String firmware{"1.32"};
|
||||
|
||||
String espnowNetName{"DEFAULT"};
|
||||
|
||||
@ -40,6 +40,7 @@ uint8_t workMode{0};
|
||||
|
||||
String deviceName = "ESP-NOW switch " + String(ESP.getChipId(), HEX);
|
||||
|
||||
bool relayStatus{false};
|
||||
uint8_t relayPin{0};
|
||||
uint8_t relayPinType{1};
|
||||
uint8_t buttonPin{0};
|
||||
@ -52,12 +53,13 @@ uint8_t ledPinType{0};
|
||||
uint8_t sensorPin{0};
|
||||
uint8_t sensorType{0};
|
||||
|
||||
bool relayStatus{false};
|
||||
|
||||
bool wasMqttAvailable{false};
|
||||
|
||||
uint8_t gatewayMAC[6]{0};
|
||||
|
||||
const String payloadOn{"ON"};
|
||||
const String payloadOff{"OFF"};
|
||||
|
||||
ZHNetwork myNet;
|
||||
AsyncWebServer webServer(80);
|
||||
|
||||
@ -203,7 +205,7 @@ void onUnicastReceiving(const char *data, const uint8_t *sender)
|
||||
if (incomingData.payloadsType == ENPT_SET)
|
||||
{
|
||||
deserializeJson(json, incomingData.message);
|
||||
relayStatus = json["set"] == "ON" ? true : false;
|
||||
relayStatus = json["set"] == payloadOn ? true : false;
|
||||
if (relayPin)
|
||||
{
|
||||
if (workMode)
|
||||
@ -251,7 +253,6 @@ void onConfirmReceiving(const uint8_t *target, const uint16_t id, const bool sta
|
||||
|
||||
void loadConfig()
|
||||
{
|
||||
ETS_GPIO_INTR_DISABLE();
|
||||
if (!LittleFS.exists("/config.json"))
|
||||
saveConfig();
|
||||
File file = LittleFS.open("/config.json", "r");
|
||||
@ -273,13 +274,10 @@ void loadConfig()
|
||||
sensorType = json["sensorType"];
|
||||
workMode = json["workMode"];
|
||||
file.close();
|
||||
delay(50);
|
||||
ETS_GPIO_INTR_ENABLE();
|
||||
}
|
||||
|
||||
void saveConfig()
|
||||
{
|
||||
ETS_GPIO_INTR_DISABLE();
|
||||
StaticJsonDocument<512> json;
|
||||
json["firmware"] = firmware;
|
||||
json["espnowNetName"] = espnowNetName;
|
||||
@ -300,8 +298,6 @@ void saveConfig()
|
||||
File file = LittleFS.open("/config.json", "w");
|
||||
serializeJsonPretty(json, file);
|
||||
file.close();
|
||||
delay(50);
|
||||
ETS_GPIO_INTR_ENABLE();
|
||||
}
|
||||
|
||||
void setupWebServer()
|
||||
@ -352,7 +348,6 @@ void IRAM_ATTR buttonInterrupt()
|
||||
|
||||
void switchingRelay()
|
||||
{
|
||||
ETS_GPIO_INTR_ENABLE();
|
||||
relayStatus = !relayStatus;
|
||||
if (relayPin)
|
||||
{
|
||||
@ -370,6 +365,7 @@ void switchingRelay()
|
||||
}
|
||||
saveConfig();
|
||||
sendStatusMessage();
|
||||
ETS_GPIO_INTR_ENABLE();
|
||||
}
|
||||
|
||||
void sendAttributesMessage(const uint8_t type)
|
||||
@ -425,22 +421,24 @@ void sendConfigMessage(const uint8_t type)
|
||||
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
|
||||
if (type == ENST_NONE)
|
||||
{
|
||||
json[MCMT_DEVICE_NAME] = deviceName;
|
||||
json[MCMT_DEVICE_UNIT] = 1;
|
||||
json[MCMT_COMPONENT_TYPE] = HACT_SWITCH;
|
||||
json[MCMT_DEVICE_CLASS] = HASWDC_SWITCH;
|
||||
json[MCMT_VALUE_TEMPLATE] = "state";
|
||||
json["name"] = deviceName;
|
||||
json["unit"] = 1;
|
||||
json["type"] = HACT_SWITCH; // ha_component_type_t
|
||||
json["class"] = HASWDC_SWITCH; // ha_switch_device_class_t
|
||||
json["template"] = "state"; // value_template
|
||||
json["payload_on"] = payloadOn;
|
||||
json["payload_off"] = payloadOff;
|
||||
}
|
||||
if (type == ENST_DS18B20 || type == ENST_DHT11 || type == ENST_DHT22)
|
||||
{
|
||||
outgoingData.deviceType = ENDT_SENSOR;
|
||||
json[MCMT_DEVICE_NAME] = deviceName + " temperature";
|
||||
json[MCMT_DEVICE_UNIT] = 2;
|
||||
json[MCMT_COMPONENT_TYPE] = HACT_SENSOR;
|
||||
json[MCMT_DEVICE_CLASS] = HASDC_TEMPERATURE;
|
||||
json[MCMT_VALUE_TEMPLATE] = "temperature";
|
||||
json[MCMT_UNIT_OF_MEASUREMENT] = "°C";
|
||||
json[MCMT_EXPIRE_AFTER] = 900;
|
||||
json["name"] = deviceName + " temperature";
|
||||
json["unit"] = 2;
|
||||
json["type"] = HACT_SENSOR; // ha_component_type_t
|
||||
json["class"] = HASDC_TEMPERATURE; // ha_sensor_device_class_t
|
||||
json["template"] = "temperature"; // value_template
|
||||
json["meas"] = "°C"; // unit_of_measurement
|
||||
json["time"] = 900; // expire_after
|
||||
}
|
||||
serializeJsonPretty(json, outgoingData.message);
|
||||
memcpy(&message.message, &outgoingData, sizeof(esp_now_payload_data_t));
|
||||
@ -451,13 +449,13 @@ void sendConfigMessage(const uint8_t type)
|
||||
if (type == ENST_DHT11 || type == ENST_DHT22)
|
||||
{
|
||||
outgoingData.deviceType = ENDT_SENSOR;
|
||||
json[MCMT_DEVICE_NAME] = deviceName + " humidity";
|
||||
json[MCMT_DEVICE_UNIT] = 3;
|
||||
json[MCMT_COMPONENT_TYPE] = HACT_SENSOR;
|
||||
json[MCMT_DEVICE_CLASS] = HASDC_HUMIDITY;
|
||||
json[MCMT_VALUE_TEMPLATE] = "humidity";
|
||||
json[MCMT_UNIT_OF_MEASUREMENT] = "%";
|
||||
json[MCMT_EXPIRE_AFTER] = 900;
|
||||
json["name"] = deviceName + " humidity";
|
||||
json["unit"] = 3;
|
||||
json["type"] = HACT_SENSOR; // ha_component_type_t
|
||||
json["class"] = HASDC_HUMIDITY; // ha_sensor_device_class_t
|
||||
json["template"] = "humidity"; // value_template
|
||||
json["meas"] = "%"; // unit_of_measurement
|
||||
json["time"] = 900; // expire_after
|
||||
|
||||
serializeJsonPretty(json, outgoingData.message);
|
||||
memcpy(&message.message, &outgoingData, sizeof(esp_now_payload_data_t));
|
||||
@ -476,7 +474,7 @@ void sendStatusMessage(const uint8_t type)
|
||||
espnow_message_t message;
|
||||
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
|
||||
if (type == ENST_NONE)
|
||||
json["state"] = relayStatus ? "ON" : "OFF";
|
||||
json["state"] = relayStatus ? payloadOn : payloadOff;
|
||||
if (type == ENST_DS18B20)
|
||||
{
|
||||
outgoingData.deviceType = ENDT_SENSOR;
|
||||
|
Loading…
x
Reference in New Issue
Block a user