7 Commits
v1.4 ... v1.43

Author SHA1 Message Date
894eed59f1 Version 1.43
Minor changes.
2023-02-19 12:19:54 +03:00
69cb07f721 Minor changes 2023-02-17 10:08:02 +03:00
5fafe9a538 Minor changes 2023-02-16 18:21:08 +03:00
cf32071ee0 Version 1.42
Fixed bug with ESP-NOW devices not getting restart or update command.
Minor main code refactoring.
2023-02-13 19:04:46 +03:00
e4572cc31a Version 1.42
Fixed bug with ESP-NOW devices not getting restart or update command.
Minor main code refactoring.
2023-02-13 18:56:39 +03:00
57d0bc6481 Version 1.42
Fixed bug with ESP-NOW devices not getting restart or update command.
Minor main code refactoring.
2023-02-13 18:53:41 +03:00
1e745724e4 Version 1.41
Minor changes.
2023-02-12 18:37:12 +03:00
2 changed files with 37 additions and 33 deletions

View File

@ -52,14 +52,14 @@ function sendRequest(submit, server) {
function saveSetting(submit) {
server = "/setting?ssid=" + getValue('ssid') + "&password=" + encodeURIComponent(getValue('password'))
+ "&host=" + getValue('mqttHostName') + "&port=" + getValue('mqttHostPort')
+ "&login=" + getValue('mqttUserLogin') + "&pass=" + encodeURIComponent(getValue('mqttUserPassword'))
+ "&prefix=" + getValue('topicPrefix')
+ "&name=" + getValue('deviceName')
+ "&net=" + getValue('espnowNetName')
+ "&mode=" + getSelectValue('workModeSelect')
+ "&ntp=" + getValue('ntpHostName')
+ "&zone=" + getValue('gmtOffset');
+ "&mqttHostName=" + getValue('mqttHostName') + "&mqttHostPort=" + getValue('mqttHostPort')
+ "&mqttUserLogin=" + getValue('mqttUserLogin') + "&mqttUserPassword=" + encodeURIComponent(getValue('mqttUserPassword'))
+ "&topicPrefix=" + getValue('topicPrefix')
+ "&deviceName=" + getValue('deviceName')
+ "&espnowNetName=" + getValue('espnowNetName')
+ "&workMode=" + getSelectValue('workModeSelect')
+ "&ntpHostName=" + getValue('ntpHostName')
+ "&gmtOffset=" + getValue('gmtOffset');
sendRequest(submit, server);
alert("Please restart device for changes apply.");
}

View File

@ -15,13 +15,6 @@
#include "ESP32SSDP.h"
#endif
typedef enum : uint8_t
{
ESP_NOW,
ESP_NOW_WIFI,
ESP_NOW_LAN
} work_mode_t;
void onEspnowMessage(const char *data, const uint8_t *sender);
void onMqttMessage(char *topic, byte *payload, unsigned int length);
@ -42,7 +35,14 @@ void checkMqttAvailability(void);
void mqttPublish(const char *topic, const char *payload, bool retained);
const String firmware{"1.4"};
typedef enum : uint8_t
{
ESP_NOW,
ESP_NOW_WIFI,
ESP_NOW_LAN
} work_mode_t;
const String firmware{"1.43"};
String espnowNetName{"DEFAULT"};
@ -193,12 +193,12 @@ void setup()
void loop()
{
if (mqttAvailabilityCheckTimerSemaphore)
checkMqttAvailability();
if (keepAliveMessageTimerSemaphore)
sendKeepAliveMessage();
if (attributesMessageTimerSemaphore)
sendAttributesMessage();
if (mqttAvailabilityCheckTimerSemaphore)
checkMqttAvailability();
if (workMode == ESP_NOW_WIFI)
mqttWifiClient.loop();
if (workMode == ESP_NOW_LAN)
@ -304,7 +304,11 @@ void onEspnowMessage(const char *data, const uint8_t *sender)
jsonConfig["force_update"] = "true";
jsonConfig["retain"] = "true";
if (type == HACT_SENSOR)
{
jsonConfig["device_class"] = getValueName(json["class"].as<ha_sensor_device_class_t>());
jsonConfig["unit_of_measurement"] = json["meas"];
jsonConfig["expire_after"] = json["time"];
}
if (type == HACT_BINARY_SENSOR)
{
ha_binary_sensor_device_class_t deviceClass = json["class"].as<ha_binary_sensor_device_class_t>();
@ -405,8 +409,6 @@ void onMqttMessage(char *topic, byte *payload, unsigned int length)
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
if (message == "update" || message == "restart")
{
mqttPublish(topic, "", true);
mqttPublish((String(topic) + "/status").c_str(), "offline", true);
if (mac == myNet.getNodeMac() && message == "restart")
ESP.restart();
flag = true;
@ -437,9 +439,7 @@ void onMqttMessage(char *topic, byte *payload, unsigned int length)
outgoingData.payloadsType = ENPT_RESTART;
else
outgoingData.payloadsType = message == "update" ? ENPT_UPDATE : ENPT_SET;
char buffer[sizeof(esp_now_payload_data_t::message)]{0};
serializeJsonPretty(json, buffer);
memcpy(&outgoingData.message, &buffer, sizeof(esp_now_payload_data_t::message));
serializeJsonPretty(json, outgoingData.message);
char temp[sizeof(esp_now_payload_data_t)]{0};
memcpy(&temp, &outgoingData, sizeof(esp_now_payload_data_t));
uint8_t target[6];
@ -632,16 +632,16 @@ void setupWebServer()
{
ssid = request->getParam("ssid")->value();
password = request->getParam("password")->value();
mqttHostName = request->getParam("host")->value();
mqttHostPort = request->getParam("port")->value().toInt();
mqttUserLogin = request->getParam("login")->value();
mqttUserPassword = request->getParam("pass")->value();
topicPrefix = request->getParam("prefix")->value();
deviceName = request->getParam("name")->value();
espnowNetName = request->getParam("net")->value();
workMode = request->getParam("mode")->value().toInt();
ntpHostName = request->getParam("ntp")->value();
gmtOffset = request->getParam("zone")->value().toInt();
mqttHostName = request->getParam("mqttHostName")->value();
mqttHostPort = request->getParam("mqttHostPor")->value().toInt();
mqttUserLogin = request->getParam("mqttUserLogin")->value();
mqttUserPassword = request->getParam("mqttUserPassword")->value();
topicPrefix = request->getParam("topicPrefix")->value();
deviceName = request->getParam("deviceName")->value();
espnowNetName = request->getParam("espnowNetName")->value();
workMode = request->getParam("workMode")->value().toInt();
ntpHostName = request->getParam("ntpHostName")->value();
gmtOffset = request->getParam("gmtOffset")->value().toInt();
request->send(200);
saveConfig(); });
@ -683,6 +683,8 @@ void checkMqttAvailability()
mqttWifiClient.subscribe((topicPrefix + "/espnow_led/#").c_str());
sendConfigMessage();
sendAttributesMessage();
sendKeepAliveMessage();
}
}
@ -700,6 +702,8 @@ void checkMqttAvailability()
mqttEthClient.subscribe((topicPrefix + "/espnow_led/#").c_str());
sendConfigMessage();
sendAttributesMessage();
sendKeepAliveMessage();
}
}
}