From 274451082252ade366954e50c3da331b2e1cc50c Mon Sep 17 00:00:00 2001 From: Northern Man Date: Wed, 28 Apr 2021 21:16:12 -0400 Subject: [PATCH] Usability Improvements for esp32 platform (#934) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Increased ESP32 base capabilities 1 - Expose SERIAL_BAUD as an optional compiler directive. 2 - Enabled mDNS based MQTT Host name lookup for ESP32 devices. 3 - Expand capability of ESPWifiManualSetup mode for multiple SSID’s. Tested with ESP32 * Regression testing of ESP8266 and ESP32 * Removal of Wifi Debuging * Fix lint issue Co-authored-by: Northern Man --- main/User_config.h | 4 +++- main/main.ino | 32 ++++++++++++++++---------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/main/User_config.h b/main/User_config.h index 2f91ff2..1ee35b1 100755 --- a/main/User_config.h +++ b/main/User_config.h @@ -327,7 +327,9 @@ int lowpowermode = DEFAULT_LOW_POWER_MODE; #ifdef ZgatewaySRFB # define SERIAL_BAUD 19200 #else -# define SERIAL_BAUD 115200 +# ifndef SERIAL_BAUD +# define SERIAL_BAUD 115200 +# endif #endif /*--------------MQTT general topics-----------------*/ // global MQTT subject listened by the gateway to execute commands (send RF, IR or others) diff --git a/main/main.ino b/main/main.ino index ffc13a1..911d5ac 100644 --- a/main/main.ino +++ b/main/main.ino @@ -191,6 +191,8 @@ static bool esp32EthConnected = false; WiFiClientSecure eClient; # else # include +# include +WiFiMulti wifiMulti; WiFiClient eClient; # endif # include @@ -204,6 +206,7 @@ Preferences preferences; # include # include # include +# include # include # include # ifdef SECURE_CONNECTION @@ -211,6 +214,7 @@ WiFiClientSecure eClient; X509List caCert(certificate); # else WiFiClient eClient; +ESP8266WiFiMulti wifiMulti; # endif # ifdef MDNS_SD # include @@ -598,7 +602,7 @@ void setup() { digitalWrite(LED_SEND, !LED_SEND_ON); digitalWrite(LED_INFO, !LED_INFO_ON); -#if defined(MDNS_SD) && defined(ESP8266) +#if defined(MDNS_SD) && (defined(ESP8266) || defined(ESP32)) Log.trace(F("Connecting to MQTT by mDNS without mqtt hostname" CR)); connectMQTTmdns(); #else @@ -826,13 +830,17 @@ void setupTLS() { #if defined(ESPWifiManualSetup) void setup_wifi() { - char manual_wifi_ssid[] = wifi_ssid; - char manual_wifi_password[] = wifi_password; - delay(10); WiFi.mode(WIFI_STA); + wifiMulti.addAP(wifi_ssid, wifi_password); + Log.trace(F("Connecting to %s" CR), wifi_ssid); +# ifdef wifi_ssid1 + wifiMulti.addAP(wifi_ssid1, wifi_password1); + Log.trace(F("Connecting to %s" CR), wifi_ssid1); +# endif + delay(10); // We start by connecting to a WiFi network - Log.trace(F("Connecting to %s" CR), manual_wifi_ssid); + # ifdef NetworkAdvancedSetup IPAddress ip_adress(ip); IPAddress gateway_adress(gateway); @@ -841,12 +849,10 @@ void setup_wifi() { if (!WiFi.config(ip_adress, gateway_adress, subnet_adress, dns_adress)) { Log.error(F("Wifi STA Failed to configure" CR)); } - WiFi.begin(manual_wifi_ssid, manual_wifi_password); -# else - WiFi.begin(manual_wifi_ssid, manual_wifi_password); + # endif - while (WiFi.status() != WL_CONNECTED) { + while (wifiMulti.run() != WL_CONNECTED) { delay(500); Log.trace(F("." CR)); failure_number_ntwk++; @@ -1137,14 +1143,8 @@ void setup_ethernet() { } #endif -#if defined(MDNS_SD) && defined(ESP8266) +#if defined(MDNS_SD) && (defined(ESP8266) || defined(ESP32)) void connectMQTTmdns() { - if (!MDNS.begin("ESP_MQTT")) { - Log.error(F("Error setting up MDNS responder!" CR)); - while (1) { - delay(1000); - } - } Log.trace(F("Browsing for MQTT service" CR)); int n = MDNS.queryService("mqtt", "tcp"); if (n == 0) {