[SOLVED] ESPHome DHCP client problems, temporary solution with manual fixed IP

thanks for you suggestion but it is a orbi mesh network so i have no control of channels etc…dhcp works just fine but i can not force a static ip crazy weird i have no other problems on my system with other devices

@robertw, you could set up your own DHCP server (on e.g. a RPI) if you can disable your out-of-the-box DHCP server/settings in order to set up reserved IPs (“static”).

Hello, this topic is marked as solved, but I do not understand what the solution is …
I have an ESP WROOM32 that was running quite ok for a few months, unfortunately the VM where I used to generate the firmware crashed, so I reflashed it from EspHome addon in HA, and then in a new esphome installation in a old VM, as the EspHome compilation is crashing on the RPi4.
Anyway, I used the fixed ip from the start and I had no problems, but now with the new compilation the Wifi is very unstable and always giving the mentioned errors.

Found multiple options, please choose one:
  [1] /dev/ttyUSB0 (CP2102 USB to UART Bridge Controller)
  [2] Over The Air (192.168.0.106)
  [3] MQTT (192.168.0.113)
(number): 2
INFO Starting log output from 192.168.0.106 using esphome API
INFO Connecting to 192.168.0.106:6053 (192.168.0.106)
INFO Successfully connected to 192.168.0.106
ERROR Error while reading incoming messages: Error while receiving data: [Errno 104] Connection reset by peer
WARNING Disconnected from API: Error while receiving data: [Errno 104] Connection reset by peer
INFO Connecting to 192.168.0.106:6053 (192.168.0.106)
WARNING Couldn't connect to API (Error connecting to 192.168.0.106: [Errno 111] Connection refused). Trying to reconnect in 1 seconds
INFO Connecting to 192.168.0.106:6053 (192.168.0.106)
WARNING Couldn't connect to API (Error connecting to 192.168.0.106: [Errno 111] Connection refused). Trying to reconnect in 1 seconds
INFO Connecting to 192.168.0.106:6053 (192.168.0.106)
WARNING Couldn't connect to API (Error connecting to 192.168.0.106: [Errno 9] Bad file descriptor). Trying to reconnect in 2 seconds
INFO Connecting to 192.168.0.106:6053 (192.168.0.106)
WARNING Couldn't connect to API (Error connecting to 192.168.0.106: [Errno 111] Connection refused). Trying to reconnect in 3 seconds
INFO Connecting to 192.168.0.106:6053 (192.168.0.106)
WARNING Couldn't connect to API (Error connecting to 192.168.0.106: [Errno 111] Connection refused). Trying to reconnect in 5 seconds
INFO Connecting to 192.168.0.106:6053 (192.168.0.106)
WARNING Couldn't connect to API (Error connecting to 192.168.0.106: [Errno 111] Connection refused). Trying to reconnect in 7 seconds
INFO Connecting to 192.168.0.106:6053 (192.168.0.106)
WARNING Couldn't connect to API (Error connecting to 192.168.0.106: [Errno 111] Connection refused). Trying to reconnect in 11 seconds

And some logs via USB:

esp32@esp32:~/Projects/esphome$ esphome living.yaml logs
WARNING You're using ESPHome with python 3.5. Support for python 3.5 is deprecated and will be removed in 1.15.0. Please reinstall ESPHome with python 3.6 or higher.
INFO Reading configuration living.yaml...
Found multiple options, please choose one:
  [1] /dev/ttyUSB0 (CP2102 USB to UART Bridge Controller)
  [2] Over The Air (192.168.0.106)
  [3] MQTT (192.168.0.113)
(number): 1
INFO Starting log output from /dev/ttyUSB0 with baud rate 115200
[13:41:42][W][AsyncTCP.cpp:950] _poll(): pcb is NULL
[13:41:42][D][dht:048]: Got Temperature=24.4°C Humidity=66.2%
[13:41:42][V][sensor:013]: 'Living Room Temperature': Received new state 24.400000
[13:41:42][D][sensor:092]: 'Living Room Temperature': Sending state 24.40000 °C with 1 decimals of accuracy
[13:41:42][V][sensor:013]: 'Living Room Humidity': Received new state 66.200005
[13:41:42][D][sensor:092]: 'Living Room Humidity': Sending state 66.20000 % with 0 decimals of accuracy
[13:41:43][W][AsyncTCP.cpp:950] _poll(): pcb is NULL
[13:41:43][D][adc:056]: 'Soil Moisture Level': Got voltage=0.00V
[13:41:43][V][sensor:013]: 'Soil Moisture Level': Received new state 0.000000
[13:41:43][D][sensor:092]: 'Soil Moisture Level': Sending state 100.00000 % with 2 decimals of accuracy
[13:41:43][W][AsyncTCP.cpp:950] _poll(): pcb is NULL
[13:41:44][W][AsyncTCP.cpp:950] _poll(): pcb is NULL
[13:41:44][W][AsyncTCP.cpp:950] _poll(): pcb is NULL
[13:41:45][W][AsyncTCP.cpp:950] _poll(): pcb is NULL
[13:41:45][W][AsyncTCP.cpp:950] _poll(): pcb is NULL
[13:41:46][W][AsyncTCP.cpp:950] _poll(): pcb is NULL
[13:41:46][W][AsyncTCP.cpp:950] _poll(): pcb is NULL
[13:41:47][W][AsyncTCP.cpp:950] _poll(): pcb is NULL
[13:41:47][W][AsyncTCP.cpp:950] _poll(): pcb is NULL
[13:41:48][W][AsyncTCP.cpp:950] _poll(): pcb is NULL
[13:41:48][W][AsyncTCP.cpp:950] _poll(): pcb is NULL
[13:41:48][W][AsyncTCP.cpp:963] _poll(): ack timeout 4
[13:41:48][V][api.connection:672]: Error: Disconnecting Home Assistant 0.112.4 (192.168.0.113)
[13:41:48][D][api:067]: Disconnecting Home Assistant 0.112.4 (192.168.0.113)
[13:41:49][W][AsyncTCP.cpp:950] _poll(): pcb is NULL
[13:41:49][W][AsyncTCP.cpp:950] _poll(): pcb is NULL
[13:41:50][W][AsyncTCP.cpp:950] _poll(): pcb is NULL
[13:41:50][W][AsyncTCP.cpp:950] _poll(): pcb is NULL
[13:41:51][W][AsyncTCP.cpp:950] _poll(): pcb is NULL
[13:41:51][W][AsyncTCP.cpp:950] _poll(): pcb is NULL
[13:41:52][W][AsyncTCP.cpp:950] _poll(): pcb is NULL
[13:41:52][W][AsyncTCP.cpp:950] _poll(): pcb is NULL
[13:41:52][D][dht:048]: Got Temperature=24.4°C Humidity=66.2%
[13:41:52][V][sensor:013]: 'Living Room Temperature': Received new state 24.400000
[13:41:52][D][sensor:092]: 'Living Room Temperature': Sending state 24.40000 °C with 1 decimals of accuracy
[13:41:52][V][sensor:013]: 'Living Room Humidity': Received new state 66.200005
[13:41:52][D][sensor:092]: 'Living Room Humidity': Sending state 66.20000 % with 0 decimals of accuracy
[13:41:53][W][AsyncTCP.cpp:950] _poll(): pcb is NULL
[13:41:53][D][adc:056]: 'Soil Moisture Level': Got voltage=0.00V
[13:41:53][V][sensor:013]: 'Soil Moisture Level': Received new state 0.000000
[13:41:53][D][sensor:092]: 'Soil Moisture Level': Sending state 100.00000 % with 2 decimals of accuracy
[13:41:53][W][mqtt:247]: MQTT Disconnected: TCP disconnected.
[13:41:53][I][mqtt:162]: Connecting to MQTT...

@robertw did you ever solve. Having same issue on Orbi WiFi.

After changing to fast_connect and reboot_timeout, did it fix your wifi issue? I am having wifi dropping issue as well. Just added the fast_connect and reboot_timeout and adding the manual ip. Let’s see if this will fix it.

Before you read on:

The fix that is discussed below has become a lot easier with the release of ESPHome v1.18.0. The required fix is now included by default. So instead of following the below recipe, you can also upgrade to the latest ESPHome, rebuild the firmware and flash your device.

Also, if you are already using the below fix, then it might still be a good idea to upgrade. The fix has been developed further since I posted it, and it has become better over time. On my test device, I can now run a Home Assistant API connection, alongside mulitple OTA logging sessions, without skipping a beat.

Thanks to all who have helped testing the patch!

Okay, here’s the original message …

I am currently working on an ESPHome project to make a Yeelight Bedside Lamp v2 work. In this project I saw a lot of these “ack timeout 4” messages and accompanying disconects. All the usual tips did not work (fixed ip, fast connect, power management changes). Chaning the log level had some effect it seemed, but that was very unsatisfying and not a perfect solution.

After a debugging slurry, I think I might have found a race condition cause for these disconnects in the AsyncTCP library. I created an issue for my findings. Maybe this can help the people in this thread, who are running into the same issue.

Update:

I created a patch for the AsyncTCP-esphome lib as used for ESPHome.
It can be found on my github account:

If you want to try out this change, then create a library directory for your esphome instance, and checkout the repository to that directory. Then add lib_extra_dirs to your device yaml file to point to that library directory.
E.g., on my system, I use /config/libs for this, and I do:

# cd /config/libs
# git clone https://github.com/mmakaay/AsyncTCP.git

The relevant part of my device config looks like:

esphome:
  platformio_options:
    lib_extra_dirs: /config/libs

This way, the repository version of the library will override the esphome version of the library.
Build the device firmware and flash the device like you would normally do.

My own device has been stable for hours now, while before it would disconnect Home Assistant every few minutes. I’m not sure this is a final fix (it still feels like a foreign code base), but I’m happy with these results so far.

5 Likes

@mmakaay Good catch and explanations!
Hope your finding will help to solve those pesky apparently random problems.
Piero

1 Like

This is amazing!!! Thanks so so much… I had the same issue and this fixed it nicely. Great job! Thanks again!

That is great news! :smiley: Thanks for reporting back!

My issue report didn’t get noticed by the author of the original AsyncTCP library on github, but @OttoWinter was willing to accepte a pull request for the AsyncTCP-esphome fork. So this fix is now official.

2 Likes

This is very much appreciated. You don’t know how much it helped me! Thanks again!

Hi I think I am missing reading something, I have added to esphome:
platformio_options:
lib_extra_dirs: /config/libs

to the esphome device config file

and created a folder in config called libs but what to I put in this folder to get esphome to point to the git clone? sorry if I am a idiot and do not understand
thank in advance

Pointing ESPHome to the git clone is done by adding the lib_extra_dirs to your yaml file. That will instruct PlatformIO (which builds the code) to also look in the directory that was specified there.

The git clone itself must be in that additional lib dir.
So the path would be /config/libs/AsyncTCP/.

No additional instructions are needed. The lib_extra_dirs directory has presedence over the other library directories, so if you put the fixed AsyncTCP library in that directory, it will override the default one.

ok thanks I have put the clone in /config/libs/AsyncTCP/ its not zipped just the clone files downloaded, I have added
platformio_options:
lib_extra_dirs: /config/libs

to my esp file yaml

run the update but I don’t see any change here the start of the upload, sorry to be a pain

INFO Reading configuration /config/esphome/2_rf.yaml…
INFO Generating C++ source…
INFO Compiling app…
INFO Running: platformio run -d /config/esphome/2_rf
Processing 2_rf (board: esp01_1m; framework: arduino; platform: [email protected])

HARDWARE: ESP8266 80MHz, 80KB RAM, 1MB Flash
PACKAGES:

  • framework-arduinoespressif8266 3.20704.0 (2.7.4)
  • tool-esptool 1.413.0 (4.13)
  • tool-esptoolpy 1.20800.0 (2.8.0)
  • toolchain-xtensa 2.40802.200502 (4.8.2)
    Library Manager: Installing Update
    Library Manager: Already installed, built-in library
    Dependency Graph
    |-- 1.2.3
    | |-- 1.0
    |-- 1.0
    |-- 1.2
    | |-- 1.0
    |-- 1.2.7
    | |-- 1.2.3
    | | |-- 1.0
    | |-- 1.0
    | |-- 1.0
    | |-- 5.13.3
    |-- 5.13.3
    |-- 1.1.1
    | |-- 1.0
    Retrieving maximum program size /data/2_rf/.pioenvs/2_rf/firmware.elf
    Checking size /data/2_rf/.pioenvs/2_rf/firmware.elf
    RAM: [===== ] 47.7% (used 39052 bytes from 81920 bytes)
    Flash: [==== ] 43.1% (used 441636 bytes from 1023984 bytes)
    ========================= [SUCCESS] Took 2.06 seconds =========================

first 1.2.3 is Dependency Graph
ESPAsyncTCP-esphome 1.2.3

Ah, my fix is for the AsyncTCP-esphome library for ESP32.
You are using the ESPAsyncTCP-esphome library for ESP8266.

Do you get “ack timeout” disconnect issues on the ESP8266? In that case, the ESPAsyncTCP might require the same kind of fix. I didn’t look into that.

ok thanks yes its dropping connection thought this may have help many thanks for your help on this

If the connection drops are because of the “ack timeout” errors, then it might be worth to patch the ESPAsyncTCP code in the same way as the AsyncTCP code.
Can you connect the device using a serial to USB connector to your computer, so you can look at the console logging? If the “ack timeout” issue is the culprit here, log then you will see those logged, right before the connection is dropped.

If you can confirm if this is your actual issue, then I can cook up a patch for this library. If the disconnects have another cause, then modifying the code wouldn’t help.

BTW: one thing that I found that might cause extra disconnects, is the log level for the logger component. If you have a high log level, then try lowering it to see if that makes the connection more stable. The time that the CPU is busy with handling the logging sometimes seems to get in the way of the connection handling code. This likely won’t be a definite fix, but I’ve seen improvements when tuning down the logging.

Hello,
I also have an EPS8266.
I have multiple Wi-Fi disconnections.
Several weeks I have been looking for a solution. The best improvement is the deactivation of the logger but the connection is not stable over several hours.
I’m desperate, I spent a lot of time, I can’t do it. :tired_face:
Doing a reset or unplugging / re-plugging is the only solution for the moment.
I am thinking of automating a 220v outlet in order to do a regular reboot.

here about 20h history: image (red it’s ok, grey lost connexion).

Thank you.

Hello… I m facing the same issue mentioned in this thread. I think the solution might be the upgrade of library AsyncTCP-esphome to version 1.2.3. I have no idea how to update it…Currently, on my log, it was still in version 1.1.1 Could you please instruct me all the steps involved to upgrade the library version…

Here are the screenshots I had done so far:

esphome issue 4

esphome issue 2