Skip to content

Commit 2744510

Browse files
NorthernMan54Northern Man
andauthored
Usability Improvements for esp32 platform (#934)
* 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 <sgracey@Heisenberg.local>
1 parent 4d49f5b commit 2744510

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

main/User_config.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,9 @@ int lowpowermode = DEFAULT_LOW_POWER_MODE;
327327
#ifdef ZgatewaySRFB
328328
# define SERIAL_BAUD 19200
329329
#else
330-
# define SERIAL_BAUD 115200
330+
# ifndef SERIAL_BAUD
331+
# define SERIAL_BAUD 115200
332+
# endif
331333
#endif
332334
/*--------------MQTT general topics-----------------*/
333335
// global MQTT subject listened by the gateway to execute commands (send RF, IR or others)

main/main.ino

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ static bool esp32EthConnected = false;
191191
WiFiClientSecure eClient;
192192
# else
193193
# include <WiFi.h>
194+
# include <WiFiMulti.h>
195+
WiFiMulti wifiMulti;
194196
WiFiClient eClient;
195197
# endif
196198
# include <Preferences.h>
@@ -204,13 +206,15 @@ Preferences preferences;
204206
# include <DNSServer.h>
205207
# include <ESP8266WebServer.h>
206208
# include <ESP8266WiFi.h>
209+
# include <ESP8266WiFiMulti.h>
207210
# include <FS.h>
208211
# include <WiFiManager.h>
209212
# ifdef SECURE_CONNECTION
210213
WiFiClientSecure eClient;
211214
X509List caCert(certificate);
212215
# else
213216
WiFiClient eClient;
217+
ESP8266WiFiMulti wifiMulti;
214218
# endif
215219
# ifdef MDNS_SD
216220
# include <ESP8266mDNS.h>
@@ -598,7 +602,7 @@ void setup() {
598602
digitalWrite(LED_SEND, !LED_SEND_ON);
599603
digitalWrite(LED_INFO, !LED_INFO_ON);
600604

601-
#if defined(MDNS_SD) && defined(ESP8266)
605+
#if defined(MDNS_SD) && (defined(ESP8266) || defined(ESP32))
602606
Log.trace(F("Connecting to MQTT by mDNS without mqtt hostname" CR));
603607
connectMQTTmdns();
604608
#else
@@ -826,13 +830,17 @@ void setupTLS() {
826830

827831
#if defined(ESPWifiManualSetup)
828832
void setup_wifi() {
829-
char manual_wifi_ssid[] = wifi_ssid;
830-
char manual_wifi_password[] = wifi_password;
831-
delay(10);
832833
WiFi.mode(WIFI_STA);
834+
wifiMulti.addAP(wifi_ssid, wifi_password);
835+
Log.trace(F("Connecting to %s" CR), wifi_ssid);
836+
# ifdef wifi_ssid1
837+
wifiMulti.addAP(wifi_ssid1, wifi_password1);
838+
Log.trace(F("Connecting to %s" CR), wifi_ssid1);
839+
# endif
840+
delay(10);
833841

834842
// We start by connecting to a WiFi network
835-
Log.trace(F("Connecting to %s" CR), manual_wifi_ssid);
843+
836844
# ifdef NetworkAdvancedSetup
837845
IPAddress ip_adress(ip);
838846
IPAddress gateway_adress(gateway);
@@ -841,12 +849,10 @@ void setup_wifi() {
841849
if (!WiFi.config(ip_adress, gateway_adress, subnet_adress, dns_adress)) {
842850
Log.error(F("Wifi STA Failed to configure" CR));
843851
}
844-
WiFi.begin(manual_wifi_ssid, manual_wifi_password);
845-
# else
846-
WiFi.begin(manual_wifi_ssid, manual_wifi_password);
852+
847853
# endif
848854

849-
while (WiFi.status() != WL_CONNECTED) {
855+
while (wifiMulti.run() != WL_CONNECTED) {
850856
delay(500);
851857
Log.trace(F("." CR));
852858
failure_number_ntwk++;
@@ -1137,14 +1143,8 @@ void setup_ethernet() {
11371143
}
11381144
#endif
11391145

1140-
#if defined(MDNS_SD) && defined(ESP8266)
1146+
#if defined(MDNS_SD) && (defined(ESP8266) || defined(ESP32))
11411147
void connectMQTTmdns() {
1142-
if (!MDNS.begin("ESP_MQTT")) {
1143-
Log.error(F("Error setting up MDNS responder!" CR));
1144-
while (1) {
1145-
delay(1000);
1146-
}
1147-
}
11481148
Log.trace(F("Browsing for MQTT service" CR));
11491149
int n = MDNS.queryService("mqtt", "tcp");
11501150
if (n == 0) {

0 commit comments

Comments
 (0)