From e44717bac7ace9a8a4ef3671231c648a6b56b5ec Mon Sep 17 00:00:00 2001 From: Florian <1technophile@users.noreply.github.com> Date: Sat, 14 Dec 2019 18:18:30 +0100 Subject: [PATCH] add wifi advanced setup into user_config.h (#506) * add wifi advanced setup into user_config.h #496 * add advanced network config for wifi --- main/User_config.h | 35 +++++++++++++++++++-------------- main/main.ino | 8 +++++++- test/Test_config.h | 49 +++++++++++++++++++++++++--------------------- 3 files changed, 54 insertions(+), 38 deletions(-) diff --git a/main/User_config.h b/main/User_config.h index 02dabba..ea807d0 100644 --- a/main/User_config.h +++ b/main/User_config.h @@ -50,18 +50,29 @@ #ifndef Gateway_Name #define Gateway_Name "OpenMQTTGateway" #endif + #define Base_Topic "home/" /*-------------DEFINE YOUR NETWORK PARAMETERS BELOW----------------*/ +//#define NetworkAdvancedSetup true //uncomment if you want to set advanced network parameters for arduino boards, not uncommented you can set the IP and mac only +#ifdef NetworkAdvancedSetup // for arduino boards advanced config + // these values are only used if no dhcp configuration is available + const byte ip[] = { 192, 168, 1, 99 }; //ip adress + const byte gateway[] = { 0, 0, 0, 0 }; //ip adress, if first value is different from 0 advanced config network will be used and you should fill gateway & dns + const byte Dns[] = { 0, 0, 0, 0 }; //ip adress, if first value is different from 0 advanced config network will be used and you should fill gateway & dns + const byte subnet[] = { 255, 255, 255, 0 }; //ip adress +#endif + #if defined(ESP8266)||defined(ESP32) // for nodemcu, weemos and esp8266 //#define ESPWifiManualSetup true //uncomment you don't want to use wifimanager for your credential settings on ESP +#else // for arduino boards + const byte ip[] = { 192, 168, 1, 99 }; //ip adress + const byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0x54, 0x95 }; //W5100 ethernet shield mac adress #endif #if defined(ESPWifiManualSetup) // for nodemcu, weemos and esp8266 #define wifi_ssid "wifi ssid" #define wifi_password "wifi password" -#else // for arduino + W5100 - const byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0x54, 0x95 }; //W5100 ethernet shield mac adress #endif #define WifiManager_password "your_password" //this is going to be the WPA2-PSK password for the initial setup access point @@ -69,6 +80,13 @@ #define WifiManager_ConfigPortalTimeOut 120 #define WifiManager_TimeOut 5 +/*-------------DEFINE YOUR ADVANCED NETWORK PARAMETERS BELOW----------------*/ +//#define MDNS_SD //uncomment if you want to use mdns for discovering automatically your ip server, please note that MDNS with ESP32 can cause the BLE to not work +#define maxMQTTretry 10 //maximum MQTT connection attempts before going to wifimanager setup if never connected once + +//set minimum quality of signal so it ignores AP's under that quality +#define MinimumWifiSignalQuality 8 + /*-------------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 @@ -109,19 +127,6 @@ char gateway_name[parameters_size * 2] = Gateway_Name; //#define ZmqttDiscovery "HADiscovery"//ESP8266, Arduino, ESP32, Sonoff RF Bridge //#define ZactuatorFASTLED "FASTLED" //ESP8266, Arduino, ESP32, Sonoff RF Bridge -/*-------------DEFINE YOUR ADVANCED NETWORK PARAMETERS BELOW----------------*/ -//#define MDNS_SD //uncomment if you want to use mdns for discovering automatically your ip server, please note that MDNS with ESP32 can cause the BLE to not work -#define maxMQTTretry 10 //maximum MQTT connection attempts before going to wifimanager setup if never connected once - -//set minimum quality of signal so it ignores AP's under that quality -#define MinimumWifiSignalQuality 8 - -// these values are only used if no dhcp configuration is available -const byte ip[] = { 192, 168, 1, 99 }; //ip adress -const byte gateway[] = { 0, 0, 0, 0 }; //ip adress, if first value is different from 0 advanced config network will be used and you should fill gateway & dns -const byte Dns[] = { 0, 0, 0, 0 }; //ip adress, if first value is different from 0 advanced config network will be used and you should fill gateway & dns -const byte subnet[] = { 255, 255, 255, 0 }; //ip adress - /*-------------DEFINE YOUR MQTT ADVANCED PARAMETERS BELOW----------------*/ #define version_Topic "/version" #define will_Topic "/LWT" diff --git a/main/main.ino b/main/main.ino index cefebc7..6b51c2f 100644 --- a/main/main.ino +++ b/main/main.ino @@ -922,7 +922,13 @@ void setup_wifimanager(bool reset_settings) wifiManager.setSaveConfigCallback(saveConfigCallback); //set static ip - //wifiManager.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); + #ifdef NetworkAdvancedSetup + trc(F("Adv wifi cfg")); + IPAddress gateway_adress(gateway); + IPAddress subnet_adress(subnet); + IPAddress ip_adress(ip); + wifiManager.setSTAStaticIPConfig(ip_adress, gateway_adress,subnet_adress); + #endif //add all your parameters here wifiManager.addParameter(&custom_mqtt_server); diff --git a/test/Test_config.h b/test/Test_config.h index 150fe6c..6840491 100644 --- a/test/Test_config.h +++ b/test/Test_config.h @@ -49,20 +49,45 @@ * Otherwise you can provide these credentials on the web interface after connecting * to the access point with your password (SSID: WifiManager_ssid, password: WifiManager_password) */ +/*-------------DEFINE GATEWAY NAME BELOW IT CAN ALSO BE DEFINED IN platformio.ini----------------*/ #ifndef Gateway_Name #define Gateway_Name "OpenMQTTGateway" #endif + #define Base_Topic "home/" -#if defined(ESP8266) // for nodemcu, weemos and esp8266 +/*-------------DEFINE YOUR NETWORK PARAMETERS BELOW----------------*/ +//#define NetworkAdvancedSetup true //uncomment if you want to set advanced network parameters for arduino boards, not uncommented you can set the IP and mac only +#ifdef NetworkAdvancedSetup // for arduino boards advanced config + // these values are only used if no dhcp configuration is available + const byte ip[] = { 192, 168, 1, 99 }; //ip adress + const byte gateway[] = { 0, 0, 0, 0 }; //ip adress, if first value is different from 0 advanced config network will be used and you should fill gateway & dns + const byte Dns[] = { 0, 0, 0, 0 }; //ip adress, if first value is different from 0 advanced config network will be used and you should fill gateway & dns + const byte subnet[] = { 255, 255, 255, 0 }; //ip adress +#endif + +#if defined(ESP8266)||defined(ESP32) // for nodemcu, weemos and esp8266 //#define ESPWifiManualSetup true //uncomment you don't want to use wifimanager for your credential settings on ESP +#else // for arduino boards + const byte ip[] = { 192, 168, 1, 99 }; //ip adress + const byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0x54, 0x95 }; //W5100 ethernet shield mac adress +#endif + +#if defined(ESPWifiManualSetup) // for nodemcu, weemos and esp8266 + #define wifi_ssid "wifi ssid" + #define wifi_password "wifi password" #endif #define WifiManager_password "your_password" //this is going to be the WPA2-PSK password for the initial setup access point -#define WifiManager_ssid "OpenMQTTGateway" //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 #define WifiManager_ConfigPortalTimeOut 120 #define WifiManager_TimeOut 5 +//#define MDNS_SD //uncomment if you want to use mdns for discovering automatically your ip server, please note that MDNS with ESP32 can cause the BLE to not work + +//set minimum quality of signal so it ignores AP's under that quality +#define MinimumWifiSignalQuality 8 + /*-------------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 @@ -82,28 +107,8 @@ char gateway_name[parameters_size * 2] = Gateway_Name; #define will_Message "Offline" #define Gateway_AnnouncementMsg "Online" -/*-------------DEFINE YOUR NETWORK PARAMETERS BELOW----------------*/ -//#define MDNS_SD //uncomment if you want to use mdns for discovering automatically your ip server, please note that MDNS with ESP32 can cause the BLE to not work #define maxMQTTretry 4 //maximum MQTT connection attempts before going to wifi setup -//set minimum quality of signal so it ignores AP's under that quality -#define MinimumWifiSignalQuality 8 - -// Update these with values suitable for your network. -#if defined(ESP32) || defined(ESPWifiManualSetup) // for nodemcu, weemos and esp8266 - #define wifi_ssid "wifi ssid" - #define wifi_password "wifi password" -#else // for arduino + W5100 - const byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0x54, 0x95 }; //W5100 ethernet shield mac adress -#endif - -// these values are only used if no dhcp configuration is available -const byte ip[] = { 192, 168, 1, 99 }; //ip adress -// Advanced network config (optional) if you want to use these parameters uncomment line 158, 172 and comment line 171 of OpenMQTTGateway.ino -const byte gateway[] = { 192, 168, 1, 1 }; //ip adress -const byte Dns[] = { 192, 168, 1, 1 }; //ip adress -const byte subnet[] = { 255, 255, 255, 0 }; //ip adress - /*-------------DEFINE YOUR OTA PARAMETERS BELOW----------------*/ #define ota_hostname "OTAHOSTNAME" #define ota_password "OTAPASSWORD"