Compare commits
	
		
			6 Commits
		
	
	
		
			v1.4
			...
			69cb07f721
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 69cb07f721 | |||
| 5fafe9a538 | |||
| cf32071ee0 | |||
| e4572cc31a | |||
| 57d0bc6481 | |||
| 1e745724e4 | 
@@ -52,14 +52,14 @@ function sendRequest(submit, server) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
function saveSetting(submit) {
 | 
					function saveSetting(submit) {
 | 
				
			||||||
    server = "/setting?ssid=" + getValue('ssid') + "&password=" + encodeURIComponent(getValue('password'))
 | 
					    server = "/setting?ssid=" + getValue('ssid') + "&password=" + encodeURIComponent(getValue('password'))
 | 
				
			||||||
        + "&host=" + getValue('mqttHostName') + "&port=" + getValue('mqttHostPort')
 | 
					        + "&mqttHostName=" + getValue('mqttHostName') + "&mqttHostPort=" + getValue('mqttHostPort')
 | 
				
			||||||
        + "&login=" + getValue('mqttUserLogin') + "&pass=" + encodeURIComponent(getValue('mqttUserPassword'))
 | 
					        + "&mqttUserLogin=" + getValue('mqttUserLogin') + "&mqttUserPassword=" + encodeURIComponent(getValue('mqttUserPassword'))
 | 
				
			||||||
        + "&prefix=" + getValue('topicPrefix')
 | 
					        + "&topicPrefix=" + getValue('topicPrefix')
 | 
				
			||||||
        + "&name=" + getValue('deviceName')
 | 
					        + "&deviceName=" + getValue('deviceName')
 | 
				
			||||||
        + "&net=" + getValue('espnowNetName')
 | 
					        + "&espnowNetName=" + getValue('espnowNetName')
 | 
				
			||||||
        + "&mode=" + getSelectValue('workModeSelect')
 | 
					        + "&workMode=" + getSelectValue('workModeSelect')
 | 
				
			||||||
        + "&ntp=" + getValue('ntpHostName')
 | 
					        + "&ntpHostName=" + getValue('ntpHostName')
 | 
				
			||||||
        + "&zone=" + getValue('gmtOffset');
 | 
					        + "&gmtOffset=" + getValue('gmtOffset');
 | 
				
			||||||
    sendRequest(submit, server);
 | 
					    sendRequest(submit, server);
 | 
				
			||||||
    alert("Please restart device for changes apply.");
 | 
					    alert("Please restart device for changes apply.");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										50
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										50
									
								
								src/main.cpp
									
									
									
									
									
								
							@@ -15,13 +15,6 @@
 | 
				
			|||||||
#include "ESP32SSDP.h"
 | 
					#include "ESP32SSDP.h"
 | 
				
			||||||
#endif
 | 
					#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 onEspnowMessage(const char *data, const uint8_t *sender);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void onMqttMessage(char *topic, byte *payload, unsigned int length);
 | 
					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);
 | 
					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.42"};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
String espnowNetName{"DEFAULT"};
 | 
					String espnowNetName{"DEFAULT"};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -193,12 +193,12 @@ void setup()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void loop()
 | 
					void loop()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if (mqttAvailabilityCheckTimerSemaphore)
 | 
					 | 
				
			||||||
        checkMqttAvailability();
 | 
					 | 
				
			||||||
    if (keepAliveMessageTimerSemaphore)
 | 
					    if (keepAliveMessageTimerSemaphore)
 | 
				
			||||||
        sendKeepAliveMessage();
 | 
					        sendKeepAliveMessage();
 | 
				
			||||||
    if (attributesMessageTimerSemaphore)
 | 
					    if (attributesMessageTimerSemaphore)
 | 
				
			||||||
        sendAttributesMessage();
 | 
					        sendAttributesMessage();
 | 
				
			||||||
 | 
					    if (mqttAvailabilityCheckTimerSemaphore)
 | 
				
			||||||
 | 
					        checkMqttAvailability();
 | 
				
			||||||
    if (workMode == ESP_NOW_WIFI)
 | 
					    if (workMode == ESP_NOW_WIFI)
 | 
				
			||||||
        mqttWifiClient.loop();
 | 
					        mqttWifiClient.loop();
 | 
				
			||||||
    if (workMode == ESP_NOW_LAN)
 | 
					    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;
 | 
					    StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
 | 
				
			||||||
    if (message == "update" || message == "restart")
 | 
					    if (message == "update" || message == "restart")
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        mqttPublish(topic, "", true);
 | 
					 | 
				
			||||||
        mqttPublish((String(topic) + "/status").c_str(), "offline", true);
 | 
					 | 
				
			||||||
        if (mac == myNet.getNodeMac() && message == "restart")
 | 
					        if (mac == myNet.getNodeMac() && message == "restart")
 | 
				
			||||||
            ESP.restart();
 | 
					            ESP.restart();
 | 
				
			||||||
        flag = true;
 | 
					        flag = true;
 | 
				
			||||||
@@ -437,9 +435,7 @@ void onMqttMessage(char *topic, byte *payload, unsigned int length)
 | 
				
			|||||||
            outgoingData.payloadsType = ENPT_RESTART;
 | 
					            outgoingData.payloadsType = ENPT_RESTART;
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
            outgoingData.payloadsType = message == "update" ? ENPT_UPDATE : ENPT_SET;
 | 
					            outgoingData.payloadsType = message == "update" ? ENPT_UPDATE : ENPT_SET;
 | 
				
			||||||
        char buffer[sizeof(esp_now_payload_data_t::message)]{0};
 | 
					        serializeJsonPretty(json, outgoingData.message);
 | 
				
			||||||
        serializeJsonPretty(json, buffer);
 | 
					 | 
				
			||||||
        memcpy(&outgoingData.message, &buffer, sizeof(esp_now_payload_data_t::message));
 | 
					 | 
				
			||||||
        char temp[sizeof(esp_now_payload_data_t)]{0};
 | 
					        char temp[sizeof(esp_now_payload_data_t)]{0};
 | 
				
			||||||
        memcpy(&temp, &outgoingData, sizeof(esp_now_payload_data_t));
 | 
					        memcpy(&temp, &outgoingData, sizeof(esp_now_payload_data_t));
 | 
				
			||||||
        uint8_t target[6];
 | 
					        uint8_t target[6];
 | 
				
			||||||
@@ -632,16 +628,16 @@ void setupWebServer()
 | 
				
			|||||||
                 {
 | 
					                 {
 | 
				
			||||||
        ssid = request->getParam("ssid")->value();
 | 
					        ssid = request->getParam("ssid")->value();
 | 
				
			||||||
        password = request->getParam("password")->value();
 | 
					        password = request->getParam("password")->value();
 | 
				
			||||||
        mqttHostName = request->getParam("host")->value();
 | 
					        mqttHostName = request->getParam("mqttHostName")->value();
 | 
				
			||||||
        mqttHostPort = request->getParam("port")->value().toInt();
 | 
					        mqttHostPort = request->getParam("mqttHostPor")->value().toInt();
 | 
				
			||||||
        mqttUserLogin = request->getParam("login")->value();
 | 
					        mqttUserLogin = request->getParam("mqttUserLogin")->value();
 | 
				
			||||||
        mqttUserPassword = request->getParam("pass")->value();
 | 
					        mqttUserPassword = request->getParam("mqttUserPassword")->value();
 | 
				
			||||||
        topicPrefix = request->getParam("prefix")->value();
 | 
					        topicPrefix = request->getParam("topicPrefix")->value();
 | 
				
			||||||
        deviceName = request->getParam("name")->value();
 | 
					        deviceName = request->getParam("deviceName")->value();
 | 
				
			||||||
        espnowNetName = request->getParam("net")->value();
 | 
					        espnowNetName = request->getParam("espnowNetName")->value();
 | 
				
			||||||
        workMode = request->getParam("mode")->value().toInt();
 | 
					        workMode = request->getParam("workMode")->value().toInt();
 | 
				
			||||||
        ntpHostName = request->getParam("ntp")->value();
 | 
					        ntpHostName = request->getParam("ntpHostName")->value();
 | 
				
			||||||
        gmtOffset = request->getParam("zone")->value().toInt();
 | 
					        gmtOffset = request->getParam("gmtOffset")->value().toInt();
 | 
				
			||||||
        request->send(200);
 | 
					        request->send(200);
 | 
				
			||||||
        saveConfig(); });
 | 
					        saveConfig(); });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -683,6 +679,8 @@ void checkMqttAvailability()
 | 
				
			|||||||
                    mqttWifiClient.subscribe((topicPrefix + "/espnow_led/#").c_str());
 | 
					                    mqttWifiClient.subscribe((topicPrefix + "/espnow_led/#").c_str());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    sendConfigMessage();
 | 
					                    sendConfigMessage();
 | 
				
			||||||
 | 
					                    sendAttributesMessage();
 | 
				
			||||||
 | 
					                    sendKeepAliveMessage();
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -700,6 +698,8 @@ void checkMqttAvailability()
 | 
				
			|||||||
                    mqttEthClient.subscribe((topicPrefix + "/espnow_led/#").c_str());
 | 
					                    mqttEthClient.subscribe((topicPrefix + "/espnow_led/#").c_str());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    sendConfigMessage();
 | 
					                    sendConfigMessage();
 | 
				
			||||||
 | 
					                    sendAttributesMessage();
 | 
				
			||||||
 | 
					                    sendKeepAliveMessage();
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user