Esp8266 stays in fallback hotspot mode and does not reconnect

I have an esp8266 connected to my home assistant which all works fine except for its physical range from my router. It varies from 80-90dbm and reports occasional unavailable in home assistant log. It also disconnects completely and reverts to fallback hotspot but it never returns from this. I can log into the fallback hotspot and see my wifi signal and can re-enter the wifi password and all works fine again, it just won’t do it by itself. The docs seem to suggest that it should reboot or reconnect at some interval but mine does not seem to do that.
I am running esphome on Rpi and compiling and downloading all work perfectly.

Any suggestions? Is it supposed to re-connect when it can see a signal? Does it need to be better than 80dbm to reconnect?

My file:
esphome:
name: garage
esp8266:
board: esp07s
early_pin_init: false

Enable logging

logger:
level: DEBUG

Enable Home Assistant API

api:
password: “password”
ota:
password: “password”
wifi:
ssid: “MY SSID”
password: “password”

Enable fallback hotspot (captive portal) in case wifi connection fails

ap:
ssid: “Garage Fallback Hotspot”
password: “password"
captive_portal:

And to add: it has an external antenna. I will attempt to relocate to a spot with the best reception in the coming days.

You will find it difficult to get people to reply if you don’t present your YAML in the preformatted text way using </> button, so it looks more like it does in the YAML editor.

How long did you wait until you connected to the ap? The default reboot time is 15mins but if you connect to the ap it won’t reboot.
Try setting a reboot timeout

reboot_timeout: 5min

or to give it longer to connect to wifi

ap_timeout: 15min

Your reception of wifi is too low. Consider a directional antenna.

Hey Spiro, thanks for the reply.

Sorry I’m new to forums, I didn’t figure out how to format my text, next time I will do better.

It has been in ap mode for hours, disconnecting at 9pm and me reconnecting it manually via the hotspot at 7am. It’s like it doesn’t reboot at all once in ap mode.
I will try adding the reboot_timeout setting.

Yes I think I am at the limit of Wifi range. I am using an Omni antenna and will see what directional antennas are available (or make one myself)


I’ve had good results from these antennas, but problem can be mounting them on a case with the ESP. Works better with the angle on the feed line.
If you want to have a go yourself I would recommend Andrew McNeil but you really would need to invest in something like a mini VNA to get the SWR low enough to protect the ESP when transmitting. If you can get the reception down to -80db or better it will make for a much more stable connection.

That looks like a good option thanks. I did try (along time ago) to add a parabolic mirror behind the omni and it did increase the range to allow a connection at about 100m. It was a bit ugly though.

Also i have reviewed the source code for the wifi component of esphome and it is clear to me that when you use an AP, the reboot_timeout is not used resulting in the esp to remain in AP mode.
from line192 of wifi_component.cpp

    if (!this->has_ap() && this->reboot_timeout_ != 0) {
      If (now - this->last_connected_ > this->reboot_timeout_) {
        ESP_LOGE(TAG, "Can't connect to wifi, rebooting...");
        App.reboot();
      }
    }

So it is working correctly as per source code and looks as though it will never reconnect after entering AP mode.

1 Like

So use the longer ap_timeout to allow it time to connect to your wifi before going into AP mode.
Like the formatting and the effort delving into the code. Parabolic is difficult to get right focus. I had a esp8266 out in garage running Tasmota that would get stuck in ap mode. I fitted the directional antenna on the router and improved reception significantly. I modified the router to fit the sma connector. It was an old bt hub 5a. Thats what brought me to the Andrew McNeil channel.

Just getting back to this today. I have rewired to allow me to locate with the external Omni antenna with almost direct line of site and now get around 67dBm - yah. I also have a 7dBi directional antenna on order. Unfortunately I seem to have broken one of the relay controls-must be the wiring.

It’s now been running for a few hours and still HA reports unavailable randomly - weird. Any thoughts?

I think I found something, I had 4 old ‘esphome run’ sessions running on my HA pi. (I can’t use esphome from Home Assistant as I had to use core and it doesn’t allow add-ons)
Have kill them, see how that goes.

I don’t think esphome should be a problem.

wifi:
  ssid: *******
  password: ******
  fast_connect: true
  manual_ip:
    static_ip: 192.168.1.50
    gateway: 192.168.1.1
    subnet: 255.255.255.0
    dns1: 8.8.4.4
    dns2: 8.8.8.8

I’ve found things connect better if set static IP and use fast connect.

Thanks Spiro, makes sense as there is no need for dhcp. I will change the settings in my router.
To note, since I killed the old ‘esphome run’ sessions there have been no dropouts for 12 hours. Maybe the old tasks were all trying to get logger commands.

Anyway thanks heaps for all your good advice.

Hey Spiro, I got one of those directional antennas and strangely I get about the same signal strength (about 70dbm average). The only reason I can think is that the antenna is mounted about 130mm in front of the roller door and maybe the door itself acts as a reflector which would favour the Omni antenna.

Also, now the normal door openers don’t work very well unless you are really close. The 2.4ghz wifi signal is interfering with the 318mhz normal receivers. The wifi antenna is mounted just outside the roller door about 0.5m above the normal controller antennas which are inside. Maybe I have to move the wifi antenna to the other side of the roller door.

The good news - no more dropouts or unavailable messages.

What type of antenna did you get?