Compare commits
	
		
			5 Commits
		
	
	
		
			v1.41
			...
			69cb07f721
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 69cb07f721 | |||
| 5fafe9a538 | |||
| cf32071ee0 | |||
| e4572cc31a | |||
| 57d0bc6481 | 
@@ -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.");
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										50
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										50
									
								
								src/main.cpp
									
									
									
									
									
								
							@@ -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.41"};
 | 
			
		||||
typedef enum : uint8_t
 | 
			
		||||
{
 | 
			
		||||
    ESP_NOW,
 | 
			
		||||
    ESP_NOW_WIFI,
 | 
			
		||||
    ESP_NOW_LAN
 | 
			
		||||
} work_mode_t;
 | 
			
		||||
 | 
			
		||||
const String firmware{"1.42"};
 | 
			
		||||
 | 
			
		||||
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)
 | 
			
		||||
@@ -405,8 +405,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 +435,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 +628,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 +679,8 @@ void checkMqttAvailability()
 | 
			
		||||
                    mqttWifiClient.subscribe((topicPrefix + "/espnow_led/#").c_str());
 | 
			
		||||
 | 
			
		||||
                    sendConfigMessage();
 | 
			
		||||
                    sendAttributesMessage();
 | 
			
		||||
                    sendKeepAliveMessage();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
@@ -700,6 +698,8 @@ void checkMqttAvailability()
 | 
			
		||||
                    mqttEthClient.subscribe((topicPrefix + "/espnow_led/#").c_str());
 | 
			
		||||
 | 
			
		||||
                    sendConfigMessage();
 | 
			
		||||
                    sendAttributesMessage();
 | 
			
		||||
                    sendKeepAliveMessage();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user