Hello!
My question is maybe very basic, but I have really not found out how to proceed despite reading the docs and other forum posts. I hope that somebody can provide me with some hints.
I want my ESP32 to be able to connect to 1 of 2 WiFi networks, which are on different subnets (gateways on 192.168.11.1 and 192.168.178.1, respectively). The ESP32 should have a static IP that matches to the corresponding subnet when connected:
- If the ESP32 cannot connect to WiFi #1, then it should connect to WiFi #2.
- If the ESP32 cannot connect to WiFi #2, then it should connect to WiFi #1.
- If the ESP32 cannot connect to WiFi #1 and not to WiFi #2, then it should start an access point (also with a static IP; it should match the subnet of WiFi #1, even if it cannot connect to it).
- If the ESP32 could connect to WiFi #1 and to WiFi #2 (i.e. both are availble), then it should connect to WiFi #1 (let’s call it primary WiFi). The signal strength of WiFi #1 is always better than that of WiFi #2, if both are available.
Below is my YAML code, but I suspect that use_address
is not correctly used, because it does not seem to work. Sometimes, the ESP32 connects to #1, sometimes to #2; however, not as I described above but it seems rather “erratic”.
Thanks a lot for your help!
wifi: # WiFi Component (https://esphome.io/components/wifi.html)
use_address: 192.168.11.5
ap: # Set up a WiFi access point
ap_timeout: 5min # Enable AP fallback hotspot after defined time
ssid: ${friendly_name}
password: !secret esp32-ap_password
manual_ip:
static_ip: 192.168.11.5
gateway: 192.168.11.1
subnet: 255.255.255.0
dns1: 192.168.11.1
dns2: 192.168.11.1
networks:
- ssid: !secret wifi1_ssid
password: !secret wifi1_password
manual_ip:
static_ip: 192.168.11.5
gateway: 192.168.11.1
subnet: 255.255.255.0
dns1: 192.168.11.1
dns2: 192.168.11.1
- ssid: !secret wifi2_ssid
password: !secret wifi2_password
manual_ip:
static_ip: 192.168.178.155
gateway: 192.168.178.1
subnet: 255.255.255.0
dns1: 192.168.178.1
dns2: 192.168.178.1
captive_portal: # Captive Portal (https://esphome.io/components/captive_portal.html)