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
+52 -27

No files matched your search

+19 -9
View File
@@ -76,8 +76,12 @@ const byte mac[] = {0xDE, 0xED, 0xBA, 0xFE, 0x54, 0x95}; //W5100 ethernet shield
#endif
#if defined(ESPWifiManualSetup) // for nodemcu, weemos and esp8266
# define wifi_ssid "wifi ssid"
# define wifi_password "wifi password"
# ifndef wifi_ssid
# define wifi_ssid "wifi ssid"
# endif
# ifndef wifi_password
# define wifi_password "wifi password"
# endif
#endif
#define WifiManager_password "your_password" //this is going to be the WPA2-PSK password for 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----------------*/
//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__)
# define parameters_size 20
# 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_max_packet_size 128
#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
char mqtt_server[parameters_size] = "192.168.1.17";
char mqtt_port[6] = "1883";
char mqtt_topic[mqtt_topic_max_size] = Base_Topic;
char gateway_name[parameters_size * 2] = Gateway_Name;
#ifndef MQTT_USER
# define MQTT_USER "your_username"
#endif
#ifndef MQTT_PASS
# 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)
# 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
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
int failure_number_ntwk = 0; // number of failure connecting to network
int failure_number_mqtt = 0; // number of failure connecting to MQTT
@@ -539,13 +546,8 @@ void setup() {
long port;
port = strtol(mqtt_port, NULL, 10);
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);
Log.trace(F("Mqtt server connection by IP: %s" CR), mqtt_server);
# endif
Log.trace(F("Mqtt server: %s" CR), mqtt_server);
#endif
setup_parameters();
@@ -764,12 +766,15 @@ void setOTA() {
#if defined(ESPWifiManualSetup)
void setup_wifi() {
char manual_wifi_ssid[] = wifi_ssid;
char manual_wifi_password[] = wifi_password;
delay(10);
WiFi.mode(WIFI_STA);
if (wifiProtocol) forceWifiProtocol();
// 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
IPAddress ip_adress(ip);
IPAddress gateway_adress(gateway);
@@ -778,9 +783,9 @@ 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(wifi_ssid, wifi_password);
WiFi.begin(manual_wifi_ssid, manual_wifi_password);
# else
WiFi.begin(wifi_ssid, wifi_password);
WiFi.begin(manual_wifi_ssid, manual_wifi_password);
# endif
if (wifi_reconnect_bypass())
+19 -9
View File
@@ -74,8 +74,12 @@ const byte mac[] = {0xDE, 0xED, 0xBA, 0xFE, 0x54, 0x95}; //W5100 ethernet shield
#endif
#if defined(ESPWifiManualSetup) // for nodemcu, weemos and esp8266
# define wifi_ssid "wifi ssid"
# define wifi_password "wifi password"
# ifndef wifi_ssid
# define wifi_ssid "wifi ssid"
# endif
# ifndef wifi_password
# define wifi_password "wifi password"
# endif
#endif
#define WifiManager_password "your_password" //this is going to be the WPA2-PSK password for 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----------------*/
//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 mqtt_topic_max_size 100
#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
char mqtt_server[parameters_size] = "192.168.1.17";
char mqtt_port[6] = "1883";
char mqtt_topic[mqtt_topic_max_size] = Base_Topic;
char gateway_name[parameters_size * 2] = Gateway_Name;
#ifndef MQTT_USER
# define MQTT_USER "your_username"
#endif
#ifndef MQTT_PASS
# 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 will_Topic "/LWT"