Fix ESPWifiManualSetup / Move MQTT variables (#704)

* Move MQTT configs to main.ino

Co-authored-by: Jonathan Wells <jonathan-wells@oist.jp>
This commit is contained in:
JonandJonathan Wells authored and GitHub committed 2020-07-24 18:34:54 -05:00
1 parent 1ae4903af1
commit f9787312a3
3 files changed
+48 -23

No files matched your search

+17 -7
View File
@@ -76,9 +76,13 @@ const byte mac[] = {0xDE, 0xED, 0xBA, 0xFE, 0x54, 0x95}; //W5100 ethernet shield
#endif #endif
#if defined(ESPWifiManualSetup) // for nodemcu, weemos and esp8266 #if defined(ESPWifiManualSetup) // for nodemcu, weemos and esp8266
# ifndef wifi_ssid
# define wifi_ssid "wifi ssid" # define wifi_ssid "wifi ssid"
# endif
# ifndef wifi_password
# define wifi_password "wifi password" # define wifi_password "wifi password"
# endif # endif
#endif
#define WifiManager_password "your_password" //this is going to be the WPA2-PSK password for the initial setup access point #define WifiManager_password "your_password" //this is going to be the WPA2-PSK password for the initial setup access point
#define WifiManager_ssid Gateway_Name //this is the network name of the initial setup access point #define WifiManager_ssid Gateway_Name //this is the network name of the initial setup access point
@@ -95,7 +99,6 @@ const byte mac[] = {0xDE, 0xED, 0xBA, 0xFE, 0x54, 0x95}; //W5100 ethernet shield
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/ /*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
//MQTT Parameters definition //MQTT Parameters definition
//#define mqtt_server_name "www.mqtt_broker.com" // instead of defining the server by its IP you can define it by its name, uncomment this line and set the correct MQTT server host name
#if defined(ESP8266) || defined(ESP32) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__) #if defined(ESP8266) || defined(ESP32) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)
# define parameters_size 20 # define parameters_size 20
# define mqtt_topic_max_size 100 # define mqtt_topic_max_size 100
@@ -105,12 +108,19 @@ const byte mac[] = {0xDE, 0xED, 0xBA, 0xFE, 0x54, 0x95}; //W5100 ethernet shield
# define mqtt_topic_max_size 50 # define mqtt_topic_max_size 50
# define mqtt_max_packet_size 128 # define mqtt_max_packet_size 128
#endif #endif
char mqtt_user[parameters_size] = "your_username"; // not compulsory only if your broker needs authentication
char mqtt_pass[parameters_size] = "your_password"; // not compulsory only if your broker needs authentication #ifndef MQTT_USER
char mqtt_server[parameters_size] = "192.168.1.17"; # define MQTT_USER "your_username"
char mqtt_port[6] = "1883"; #endif
char mqtt_topic[mqtt_topic_max_size] = Base_Topic; #ifndef MQTT_PASS
char gateway_name[parameters_size * 2] = Gateway_Name; # define MQTT_PASS "your_password"
#endif
#ifndef MQTT_SERVER
# define MQTT_SERVER "192.168.1.17"
#endif
#ifndef MQTT_PORT
# define MQTT_PORT "1883"
#endif
#if defined(ESP8266) || defined(ESP32) #if defined(ESP8266) || defined(ESP32)
# define ATTEMPTS_BEFORE_BG 10 // Number of wifi connection attempts before going to BG protocol # define ATTEMPTS_BEFORE_BG 10 // Number of wifi connection attempts before going to BG protocol
+14 -9
View File
@@ -133,6 +133,13 @@ unsigned long timer_sys_measures = 0;
//adding this to bypass the problem of the arduino builder issue 50 //adding this to bypass the problem of the arduino builder issue 50
void callback(char* topic, byte* payload, unsigned int length); void callback(char* topic, byte* payload, unsigned int length);
char mqtt_user[parameters_size] = MQTT_USER; // not compulsory only if your broker needs authentication
char mqtt_pass[parameters_size] = MQTT_PASS; // not compulsory only if your broker needs authentication
char mqtt_server[parameters_size] = MQTT_SERVER;
char mqtt_port[6] = MQTT_PORT;
char mqtt_topic[mqtt_topic_max_size] = Base_Topic;
char gateway_name[parameters_size * 2] = Gateway_Name;
bool connectedOnce = false; //indicate if we have been connected once to MQTT bool connectedOnce = false; //indicate if we have been connected once to MQTT
int failure_number_ntwk = 0; // number of failure connecting to network int failure_number_ntwk = 0; // number of failure connecting to network
int failure_number_mqtt = 0; // number of failure connecting to MQTT int failure_number_mqtt = 0; // number of failure connecting to MQTT
@@ -539,13 +546,8 @@ void setup() {
long port; long port;
port = strtol(mqtt_port, NULL, 10); port = strtol(mqtt_port, NULL, 10);
Log.trace(F("Port: %l" CR), port); Log.trace(F("Port: %l" CR), port);
# ifdef mqtt_server_name // if name is defined we define the mqtt server by its name
client.setServer(mqtt_server_name, port);
Log.trace(F("Mqtt server connection by host name: %s" CR), mqtt_server_name);
# else // if not by its IP adress
client.setServer(mqtt_server, port); client.setServer(mqtt_server, port);
Log.trace(F("Mqtt server connection by IP: %s" CR), mqtt_server); Log.trace(F("Mqtt server: %s" CR), mqtt_server);
# endif
#endif #endif
setup_parameters(); setup_parameters();
@@ -764,12 +766,15 @@ void setOTA() {
#if defined(ESPWifiManualSetup) #if defined(ESPWifiManualSetup)
void setup_wifi() { void setup_wifi() {
char manual_wifi_ssid[] = wifi_ssid;
char manual_wifi_password[] = wifi_password;
delay(10); delay(10);
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
if (wifiProtocol) forceWifiProtocol(); if (wifiProtocol) forceWifiProtocol();
// We start by connecting to a WiFi network // We start by connecting to a WiFi network
Log.trace(F("Connecting to %s" CR), wifi_ssid); Log.trace(F("Connecting to %s" CR), manual_wifi_ssid);
# ifdef ESPWifiAdvancedSetup # ifdef ESPWifiAdvancedSetup
IPAddress ip_adress(ip); IPAddress ip_adress(ip);
IPAddress gateway_adress(gateway); IPAddress gateway_adress(gateway);
@@ -778,9 +783,9 @@ void setup_wifi() {
if (!WiFi.config(ip_adress, gateway_adress, subnet_adress, dns_adress)) { if (!WiFi.config(ip_adress, gateway_adress, subnet_adress, dns_adress)) {
Log.error(F("Wifi STA Failed to configure" CR)); Log.error(F("Wifi STA Failed to configure" CR));
} }
WiFi.begin(wifi_ssid, wifi_password); WiFi.begin(manual_wifi_ssid, manual_wifi_password);
# else # else
WiFi.begin(wifi_ssid, wifi_password); WiFi.begin(manual_wifi_ssid, manual_wifi_password);
# endif # endif
if (wifi_reconnect_bypass()) if (wifi_reconnect_bypass())
+17 -7
View File
@@ -74,9 +74,13 @@ const byte mac[] = {0xDE, 0xED, 0xBA, 0xFE, 0x54, 0x95}; //W5100 ethernet shield
#endif #endif
#if defined(ESPWifiManualSetup) // for nodemcu, weemos and esp8266 #if defined(ESPWifiManualSetup) // for nodemcu, weemos and esp8266
# ifndef wifi_ssid
# define wifi_ssid "wifi ssid" # define wifi_ssid "wifi ssid"
# endif
# ifndef wifi_password
# define wifi_password "wifi password" # define wifi_password "wifi password"
# endif # endif
#endif
#define WifiManager_password "your_password" //this is going to be the WPA2-PSK password for the initial setup access point #define WifiManager_password "your_password" //this is going to be the WPA2-PSK password for the initial setup access point
#define WifiManager_ssid Gateway_Name //this is the network name of the initial setup access point #define WifiManager_ssid Gateway_Name //this is the network name of the initial setup access point
@@ -90,16 +94,22 @@ const byte mac[] = {0xDE, 0xED, 0xBA, 0xFE, 0x54, 0x95}; //W5100 ethernet shield
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/ /*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
//MQTT Parameters definition //MQTT Parameters definition
//#define mqtt_server_name "www.mqtt_broker.com" // instead of defining the server by its IP you can define it by its name, uncomment this line and set the correct MQTT server host name
#define parameters_size 20 #define parameters_size 20
#define mqtt_topic_max_size 100 #define mqtt_topic_max_size 100
#define mqtt_max_packet_size 128 #define mqtt_max_packet_size 128
char mqtt_user[parameters_size] = "your_username"; // not compulsory only if your broker needs authentication
char mqtt_pass[parameters_size] = "your_password"; // not compulsory only if your broker needs authentication #ifndef MQTT_USER
char mqtt_server[parameters_size] = "192.168.1.17"; # define MQTT_USER "your_username"
char mqtt_port[6] = "1883"; #endif
char mqtt_topic[mqtt_topic_max_size] = Base_Topic; #ifndef MQTT_PASS
char gateway_name[parameters_size * 2] = Gateway_Name; # define MQTT_PASS "your_password"
#endif
#ifndef MQTT_SERVER
# define MQTT_SERVER "192.168.1.17"
#endif
#ifndef MQTT_PORT
# define MQTT_PORT "1883"
#endif
#define version_Topic "/version" #define version_Topic "/version"
#define will_Topic "/LWT" #define will_Topic "/LWT"