Curious wifi problems ESP8266

I implemented this esphome smart meter.
Hardware and code itself are working flawlessly. I did a test run, and the device was online for 3 days without problems. This was a few weeks ago. I now implemented a more permanent solution, but other than changing the battery pack to a power supply, nothing changed.
Since then, the ESP (ESP-01 because it’s smaller) almost never connects to my Wi-Fi. ESPHome states it’s online, but I can’t connect to it, and my router also doesn’t show it. As the device sits two floors below my router, I thought about range issues and tried this antenna mod - nothing changed.

And now my main curious problem: It now almost never connects in my rooms next to the router as well. Sometimes, after a few restarts, it connects but is offline a few seconds/minutes later. I tried using different ESPs and Wemos D1 Minis instead, but the same problem occurs.

ESPHome version: 2024.12.2

wemos code:

external_components:
  - source: github://mampfes/esphome_obis_d0
  
esphome:
  name: smart-meter
  friendly_name: smart_meter

esp8266:
  board: d1_mini

# Enable logging
logger:
  level: DEBUG
  baud_rate: 0 # disables uart logger, needed to use rx pin
      # for initial setup: VERY_VERBOSE
  logs:
    sml: DEBUG
    text_sensor: DEBUG

# Enable Home Assistant API
api:
  encryption:
    key: "*****"

ota:
  - platform: esphome
    password: "*****"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  
  manual_ip:
    # Set this to the IP of the ESP
    static_ip: 192.168.178.103
    # Set this to the IP address of the router. Often ends with .1
    gateway: 192.168.178.1
    # The subnet of the network. 255.255.255.0 works for most home networks.
    subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Smart-Meter Fallback Hotspot"
    password: !secret wifi_password

captive_portal:

uart:
  id: my_uart
  rx_pin: 
  #D7 @ wemos D1 rx
    number: D7
    inverted: false
  baud_rate: 9600
  data_bits: 7
  parity: EVEN
  stop_bits: 1
  debug:

obis_d0:
  id: my_sm
  uart_id: my_uart
  optimize_size: true


sensor:
  - platform: uptime 
    name: Uptime 
    entity_category: DIAGNOSTIC

  - platform: wifi_signal
    name: WiFi Signal
    update_interval: 60s
    entity_category: DIAGNOSTIC

  - platform: obis_d0
    name: "Consumed Energy"
    obis_d0_id: my_sm
    obis_code: "1-0:1.8.0*255"
    unit_of_measurement: kWh
    accuracy_decimals: 4
    state_class: total_increasing
    device_class: energy
    value_regex: "\\d{6}\\.\\d{8}\\*kWh"

  - platform: obis_d0
    name: "Provided Energy"
    obis_d0_id: my_sm
    obis_code: "1-0:2.8.0*255"
    unit_of_measurement: kWh
    accuracy_decimals: 4
    state_class: total_increasing
    device_class: energy
    value_regex: "\\d{6}\\.\\d{8}\\*kWh"

  - platform: obis_d0
    name: "Power"
    obis_d0_id: my_sm
    obis_code: "1-0:16.7.0*255"
    unit_of_measurement: W
    accuracy_decimals: 2
    state_class: measurement
    device_class: power
    value_regex: "-?\\d{6}\\.\\d{2}\\*W"

ESP-01 code:

external_components:
  - source: github://mampfes/esphome_obis_d0

esphome:
  name: smart-meter
  friendly_name: smart_meter

esp8266:
  board: esp01_1m

# Enable logging
logger:
  level: DEBUG
  baud_rate: 0 # disables uart logger, needed to use rx pin
      # for initial setup: VERY_VERBOSE
  logs:
    sml: DEBUG
    text_sensor: DEBUG

# Enable Home Assistant API
api:

ota:
  - platform: esphome

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
      # Set this to the IP of the ESP
      static_ip: 192.168.178.105
      # Set this to the IP address of the router. Often ends with .1
      gateway: 192.168.178.1
      # The subnet of the network. 255.255.255.0 works for most home networks.
      subnet: 255.255.255.0

 

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Smart-Meter Fallback Hotspot"
    password: !secret wifi_password

captive_portal:
    
uart:
  id: my_uart
  rx_pin: 
  #D7 GPIO3 @ esp01 rx
    number: GPIO3
    inverted: false
  baud_rate: 9600
  data_bits: 7
  parity: EVEN
  stop_bits: 1
  debug:

obis_d0:
  id: my_sm
  uart_id: my_uart
  optimize_size: true


sensor:
  - platform: uptime 
    name: Uptime 
    entity_category: DIAGNOSTIC

  - platform: wifi_signal
    name: WiFi Signal
    update_interval: 60s
    entity_category: DIAGNOSTIC

  - platform: obis_d0
    name: "Consumed Energy"
    obis_d0_id: my_sm
    obis_code: "1-0:1.8.0*255"
    unit_of_measurement: kWh
    accuracy_decimals: 4
    state_class: total_increasing
    device_class: energy
    value_regex: "\\d{6}\\.\\d{8}\\*kWh"

  - platform: obis_d0
    name: "Provided Energy"
    obis_d0_id: my_sm
    obis_code: "1-0:2.8.0*255"
    unit_of_measurement: kWh
    accuracy_decimals: 4
    state_class: total_increasing
    device_class: energy
    value_regex: "\\d{6}\\.\\d{8}\\*kWh"

  - platform: obis_d0
    name: "Power"
    obis_d0_id: my_sm
    obis_code: "1-0:16.7.0*255"
    unit_of_measurement: W
    accuracy_decimals: 2
    state_class: measurement
    device_class: power
    value_regex: "-?\\d{6}\\.\\d{2}\\*W"

I implemented the uptime and Wi-Fi strength components later, so unfortunately I don’t have any data from my successful test.

One idea where the problem may come from is that I installed a Wi-Fi mesh repeater, and maybe the ESPs have problems with it. However, I tried unplugging it temporarily, but nothing changed. I use a router and mesh repeater by AVM FRITZ!Box.

I also tried the following Wi-Fi settings:

    - ssid: !secret wifi_ssid
      password: !secret wifi_password 
      bssid: "0C:72:74:A4:9A:9A"   # Mac adress of router
  power_save_mode: none
  fast_connect: True

Again, no solution.

I don’t have any ideas left, and what really bogs me is that I have a few other ESPHome devices running without problems.

I appreciate any input!
Thank you, guys!

Two things you could try. Start over with your configuation that was working. If it is still working, then change only one thing at a time until you get to the point where it stops working. Then work on why that change buggered things up. This is long and tedious … I’ve been there many times, so I empathize.

It could be the ESP-01 has gone bad. Try a different one.

For debugging of this nature, I use a USB to Serial device and a laptop that runs PuTTY. I connect RX to TX, TX to RX and GND to GND on the ESP-01. Then I can watch the boot process of the ESP-01.

There is another possiblity that drove me nuts for months! I have an Asus Router. What I discovered is that my router can only handle 20-25 WiFi connections at a time. There are no warnings, just random devices get disconnected, then later reconnected. Now that I’m using more and more ESP deivices I got a Unifi AP that can handle 300 WiFi devices, the router now seeing them a LAN devices. (Please note that I’m not a big fan of the AP because logging in is cloud based and it is difficult to manage)

I hope this helps

OSD

Does it connect again when you go back to battery pack?
What happens when you use a different power supply?

3 Likes

What @tmo said. This definitely sounds like a power issue.

Also for IOT devices, and this worked for my ESP8266’s and my ESP32-CAMs - for the SSID they use, get rid of 5GHZ use 2.4GHZ only, turn off 802.11r, get rid of WPA3 and only use WPA2…

BSSID address might not be the same as the MAC address on the LAN side of the AP.
Check the BSSID with a scanner, like the WiFi Analyzer for Android.
If you have an i Phone, then get an Android.

1 Like

Does it connect again when you go back to battery pack?

No, when I test in my other room I use a dedicated power supply or the usb power and the problem occurs as well.

Also for IOT devices, and this worked for my ESP8266’s and my ESP32-CAMs - for the SSID they use, get rid of 5GHZ use 2.4GHZ only, turn off 802.11r, get rid of WPA3 and only use WPA2…

I heared that in the past but I never had problems (and don’t have any with three other esphome devices) and also for normal wifi devices these things are faster and useful.

BSSID address might not be the same as the MAC address on the LAN side of the AP.

My router states the MACS of both 5Ghz and 2,4Ghz ports.

You need to go back to ground zero as has already been said. There is something about your environment that is difficult. I am not surprised you are having issues 2 floors away. It is highly unusual to have good connectivity 2 floors away.

Start with the most basic program to make sure you can get the HW to work. Do not set the IP address, let the router provide it. Look at the logs via serial to see what the esp is saying is happening.

1 Like

I started from scratch with this basic yaml:

esphome:
  name: test
  friendly_name: test

esp8266:
  board: d1_mini



# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "***"

ota:
  - platform: esphome
    password: "***"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Test Fallback Hotspot"
    password: !secret wifi_password

captive_portal:
    
sensor:
  - platform: uptime 
    name: Uptime 
    entity_category: DIAGNOSTIC

  - platform: wifi_signal
    name: WiFi Signal
    update_interval: 60s
    entity_category: DIAGNOSTIC

And get this log output:

[11:01:03][I][wifi:313]: WiFi Connecting to 'wifi_ssid'... 
[11:01:08][W][wifi_esp8266:513]: Event: Disconnected ssid='wifi_ssid' bssid=[redacted] reason='Auth Expired' 
[11:01:08][W][wifi:653]: Error while connecting to network. [11:01:13][I][wifi:313]: WiFi Connecting to 'wifi_ssid'... 
[11:01:13][W][wifi_esp8266:513]: Event: Disconnected ssid='wifi_ssid' bssid=[redacted] reason='Authentication Failed' 
[11:01:13][W][wifi:653]: Error while connecting to network.

After a restart I get the following:

[logger:034]: Log initialized
[11:03:57][C][safe_mode:079]: There have been 0 suspected unsuccessful boot attempts
[11:03:57][I][app:029]: Running through setup()...
[11:03:57][C][wifi:048]: Setting up WiFi...
[11:03:57][C][wifi:061]: Starting WiFi...
[11:03:57][C][wifi:062]:   Local MAC: 48:3F:DA:40:A8:DD
[11:03:57][D][wifi:482]: Starting scan...
[11:03:57][D][sensor:093]: 'Uptime': Sending state 0.11000 s with 0 decimals of accuracy
[11:03:57][W][component:157]: Component wifi set Warning flag: scanning for networks
[11:04:03][D][wifi:497]: Found networks:
[11:04:03][I][wifi:540]: - 'wifi_ssid' [redacted]▂▄▆█
[11:04:03][D][wifi:542]:     Channel: 11
[11:04:03][D][wifi:543]:     RSSI: -65 dB
[11:04:03][I][wifi:540]: - 'wifi_ssid' [redacted]▂▄▆█
[11:04:03][D][wifi:542]:     Channel: 11
[11:04:03][D][wifi:543]:     RSSI: -73 dB

So both networks (router and mesh repeater) are found with there individual bssids.

After unplugging the repeater again error while connecting to network but with a few different reasons:

reason='Mic Failure'
reason='Authentication Failed'
reason='Association Leave'
reason='Handshake Failed'

Afterwards I simply copied an existing config (with other ip) and suddenly everything works again.

I only started using the !secret data a few weeks back and actually had a typo in my password.

So in conclusion a number of bad coincidences:

  1. WiFi range not sufficient enough which made me try other things.
  2. Typo in password (Expected a better error message for that).
  3. Partly forgot the EN-Pin at ESP-01 as I have some ESP-01 and ESP-01S.

Now everthing works. The antenna mod seems to solve the range issue.

I keep this post detailed as it maybe helps others in the future.

2 Likes