[SYS] User friendly manual network configuration (#1715)

* User friendly manual network configuration

* Add manual network config to the docs

* Add manual network config to the test env

Co-authored-by: DigiH <github@digih.net>
This commit is contained in:
Vitaliy DandDigiH authored and GitHub committed 2023-08-05 13:41:57 -05:00
1 parent fac602e457
commit 2aa4368538
4 files changed
+65 -13

No files matched your search

+12
View File
@@ -114,6 +114,18 @@ Adding manual WiFi and MQTT credentials to an environment also requires to defin
for the credetials to be registered correctly. for the credetials to be registered correctly.
::: :::
::: warning Note
Manual network configuration (IP, netmask, gateway, DNS) requires to define
`'-DNetworkAdvancedSetup=true'`
and related network parameters, e.g.:
```
'-DNET_IP="192.168.1.99"'
'-DNET_MASK="255.255.255.0"'
'-DNET_GW="192.168.1.1"'
'-DNET_DNS="1.1.1.1"'
```
:::
The first new environment we create, `nodemcuv2-pilight-bme280`, inherits the default `nodemcuv2-pilight` environment in `platformio.ini` with the `extends = env:nodemcuv2-pilight` line. In the `lib_deps` section, it imports all the `lib_deps` of `nodemcuv2-pilight` with the `${env:nodemcuv2-pilight.lib_deps}` line, and adds BME280 on top of it. (Since the environment we're extending already has this `lib_deps` attribute, specifying it again would normally replace it completely with our new attribute; instead, to keep its value but simply append to it, we import the original in the beginning of our `lib_deps` attribute.) In the `build_flags` section, it again imports all the `build_flags` of `nodemcuv2-pilight` and many of its own overrides, e.g. changing `Base_Topic` found in `User_config.h` from the default to "rf/" by using the `'-DBase_Topic="rf/"'` line. It also unsets previously set configurations (i.e. `mqttDiscovery`) by using `'-UZmqttDiscovery'`. This environment will work over serial upload. The first new environment we create, `nodemcuv2-pilight-bme280`, inherits the default `nodemcuv2-pilight` environment in `platformio.ini` with the `extends = env:nodemcuv2-pilight` line. In the `lib_deps` section, it imports all the `lib_deps` of `nodemcuv2-pilight` with the `${env:nodemcuv2-pilight.lib_deps}` line, and adds BME280 on top of it. (Since the environment we're extending already has this `lib_deps` attribute, specifying it again would normally replace it completely with our new attribute; instead, to keep its value but simply append to it, we import the original in the beginning of our `lib_deps` attribute.) In the `build_flags` section, it again imports all the `build_flags` of `nodemcuv2-pilight` and many of its own overrides, e.g. changing `Base_Topic` found in `User_config.h` from the default to "rf/" by using the `'-DBase_Topic="rf/"'` line. It also unsets previously set configurations (i.e. `mqttDiscovery`) by using `'-UZmqttDiscovery'`. This environment will work over serial upload.
The second new environment, `nodemcuv2-pilight-bme280-ota`, inherits everything we specified in the first environment (with the line `extends = env:nodemcuv2-pilight-bme280`), but modifies it to upload over OTA (Wi-Fi). We also specified this as the `default_env` in the beginning of the file, so PlatformIO will choose this environment to build and upload if we don't specify otherwise. The second new environment, `nodemcuv2-pilight-bme280-ota`, inherits everything we specified in the first environment (with the line `extends = env:nodemcuv2-pilight-bme280`), but modifies it to upload over OTA (Wi-Fi). We also specified this as the `default_env` in the beginning of the file, so PlatformIO will choose this environment to build and upload if we don't specify otherwise.
+6
View File
@@ -118,6 +118,12 @@ build_flags =
'-DESP32_EXT0_WAKE_PIN=GPIO_NUM_14' ;Should a water leak be detected immediatly wake the ESP32 and report the problem '-DESP32_EXT0_WAKE_PIN=GPIO_NUM_14' ;Should a water leak be detected immediatly wake the ESP32 and report the problem
'-DESP32_EXT0_WAKE_PIN_STATE=0' ;Should a water leak be detected immediatly wake the ESP32 and report the problem, sensor state to look for wakeup '-DESP32_EXT0_WAKE_PIN_STATE=0' ;Should a water leak be detected immediatly wake the ESP32 and report the problem, sensor state to look for wakeup
'-UMQTT_HTTPS_FW_UPDATE' ;disable HTTPS firmware updating '-UMQTT_HTTPS_FW_UPDATE' ;disable HTTPS firmware updating
'-DNetworkAdvancedSetup=true'
'-DNET_IP="192.168.1.99"'
'-DNET_MASK="255.255.255.0"'
'-DNET_GW="192.168.1.1"'
'-DNET_DNS="1.1.1.1"'
[env:esp32dev-rf] [env:esp32dev-rf]
platform = ${com.esp32_platform} platform = ${com.esp32_platform}
board = esp32dev board = esp32dev
+11 -5
View File
@@ -68,12 +68,18 @@
//#define NetworkAdvancedSetup true //uncomment if you want to set advanced network parameters, not uncommented you can set the IP and MAC only //#define NetworkAdvancedSetup true //uncomment if you want to set advanced network parameters, not uncommented you can set the IP and MAC only
#ifdef NetworkAdvancedSetup #ifdef NetworkAdvancedSetup
# if defined(ESP8266) || defined(ESP32) # ifndef NET_IP
const byte ip[] = {192, 168, 1, 99}; //IP address of the gateway, already defined for arduino below # define NET_IP "192.168.1.99"
# endif
# ifndef NET_MASK
# define NET_MASK "255.255.255.0"
# endif
# ifndef NET_GW
# define NET_GW "192.168.1.1"
# endif
# ifndef NET_DNS
# define NET_DNS "192.168.1.1"
# endif # endif
const byte gateway[] = {0, 0, 0, 0};
const byte Dns[] = {0, 0, 0, 0};
const byte subnet[] = {255, 255, 255, 0};
#endif #endif
#if defined(ESP8266) || defined(ESP32) // for nodemcu, weemos and esp8266 #if defined(ESP8266) || defined(ESP32) // for nodemcu, weemos and esp8266
+36 -8
View File
@@ -1348,10 +1348,15 @@ void setup_wifi() {
// We start by connecting to a WiFi network // We start by connecting to a WiFi network
# ifdef NetworkAdvancedSetup # ifdef NetworkAdvancedSetup
IPAddress ip_adress(ip); IPAddress ip_adress;
IPAddress gateway_adress(gateway); IPAddress gateway_adress;
IPAddress subnet_adress(subnet); IPAddress subnet_adress;
IPAddress dns_adress(Dns); IPAddress dns_adress;
ip_adress.fromString(NET_IP);
gateway_adress.fromString(NET_GW);
subnet_adress.fromString(NET_MASK);
dns_adress.fromString(NET_DNS);
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));
} }
@@ -1589,10 +1594,15 @@ void setup_wifimanager(bool reset_settings) {
//set static IP //set static IP
# ifdef NetworkAdvancedSetup # ifdef NetworkAdvancedSetup
Log.trace(F("Adv wifi cfg" CR)); Log.trace(F("Adv wifi cfg" CR));
IPAddress gateway_adress(gateway); IPAddress ip_adress;
IPAddress subnet_adress(subnet); IPAddress gateway_adress;
IPAddress ip_adress(ip); IPAddress subnet_adress;
wifiManager.setSTAStaticIPConfig(ip_adress, gateway_adress, subnet_adress); IPAddress dns_adress;
ip_adress.fromString(NET_IP);
gateway_adress.fromString(NET_GW);
subnet_adress.fromString(NET_MASK);
dns_adress.fromString(NET_DNS);
wifiManager.setSTAStaticIPConfig(ip_adress, gateway_adress, subnet_adress, dns_adress);
# endif # endif
# ifndef WIFIMNG_HIDE_MQTT_CONFIG # ifndef WIFIMNG_HIDE_MQTT_CONFIG
@@ -1691,6 +1701,15 @@ void setup_ethernet_esp32() {
bool ethBeginSuccess = false; bool ethBeginSuccess = false;
WiFi.onEvent(WiFiEvent); WiFi.onEvent(WiFiEvent);
# ifdef NetworkAdvancedSetup # ifdef NetworkAdvancedSetup
IPAddress ip_adress;
IPAddress gateway_adress;
IPAddress subnet_adress;
IPAddress dns_adress;
ip.fromString(NET_IP);
gateway.fromString(NET_GW);
subnet.fromString(NET_MASK);
Dns.fromString(NET_DNS);
Log.trace(F("Adv eth cfg" CR)); Log.trace(F("Adv eth cfg" CR));
ETH.config(ip, gateway, subnet, Dns); ETH.config(ip, gateway, subnet, Dns);
ethBeginSuccess = ETH.begin(); ethBeginSuccess = ETH.begin();
@@ -1736,6 +1755,15 @@ void WiFiEvent(WiFiEvent_t event) {
#else // Arduino case #else // Arduino case
void setup_ethernet() { void setup_ethernet() {
# ifdef NetworkAdvancedSetup # ifdef NetworkAdvancedSetup
IPAddress ip_adress;
IPAddress gateway_adress;
IPAddress subnet_adress;
IPAddress dns_adress;
ip.fromString(NET_IP);
gateway.fromString(NET_GW);
subnet.fromString(NET_MASK);
Dns.fromString(NET_DNS);
Log.trace(F("Adv eth cfg" CR)); Log.trace(F("Adv eth cfg" CR));
Ethernet.begin(mac, ip, Dns, gateway, subnet); Ethernet.begin(mac, ip, Dns, gateway, subnet);
# else # else