Cant connect to ESP over Wifi

I am having trouble connecting my ESP device to Homeassitant.

I am using an ESP32_DevkitC_V4 with an ESP32-WROOM-32D Chip.

The Board is connected to a Ubiquity DreamRouter using a fixed IP and fixed AP.

Im using the following code for my board.

esphome:
  name: esp-vitrine-v6
  friendly_name: ESP_Vitrine_V6

esp32:
  board: nodemcu-32s
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "9am/TrVuWl2oWkrUviRDukY0oQpRpALcgS9tnN5hiFU="

ota:
  password: "081907e3bbe2d034cd86d62bf9c5018b"

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

  manual_ip:
      # Set this to the IP of the ESP
      static_ip: 192.168.1.86
      # Set this to the IP address of the router. Often ends with .1
      gateway: 255.255.255.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: "Esp-Vitrine-V6 Fallback Hotspot"
    password: "MUVeObp6LcAq"

captive_portal:
    
light:
  - platform: neopixelbus
    type: RBG
    variant: WS2811
    pin: GPIO23
    num_leds: 30
    name: "Arbeitszimmer_Board_V4_D10"
    
  - platform: neopixelbus
    type: RBG
    variant: WS2811
    pin: GPIO22
    num_leds: 30
    name: "Arbeitszimmer_Board_V4_D9"
    
  - platform: neopixelbus
    type: RBG
    variant: WS2811
    pin: GPIO21
    num_leds: 30
    name: "Arbeitszimmer_Board_V4_D8"
    
  - platform: neopixelbus
    type: RBG
    variant: WS2811
    pin: GPIO19
    num_leds: 30
    name: "Arbeitszimmer_Board_V4_D7"
   
  - platform: neopixelbus
    type: RBG
    variant: WS2811
    pin: GPIO18
    num_leds: 30
    name: "Arbeitszimmer_Board_V4_D6"
    
  - platform: neopixelbus
    type: RBG
    variant: WS2811
    pin: GPIO5
    num_leds: 30
    name: "Arbeitszimmer_Board_V4_D5"
 
  - platform: neopixelbus
    type: RBG
    variant: WS2811
    pin: GPIO17
    num_leds: 30
    name: "Arbeitszimmer_Board_V4_D4"
    
  - platform: neopixelbus
    type: RBG
    variant: WS2811
    pin: GPIO16
    num_leds: 30
    name: "Arbeitszimmer_Board_V4_D3"
    
  - platform: neopixelbus
    type: RBG
    variant: WS2811
    pin: GPIO4
    num_leds: 30
    name: "Arbeitszimmer_Board_V4_D2"
    

  - platform: neopixelbus
    type: RBG
    variant: WS2811
    pin: GPIO2
    num_leds: 30
    name: "Arbeitszimmer_Board_V4_D1"
    

Loading of the code via USB is possible and the device shows up in my unify dasboard (connected to wifi). Im also able to ping the device via cmd and read the latency in the unify dashboard.

But when trying to update the firmware or revice the logs via WiFi I always get the following Error:

ERROR Connecting to 192.168.1.86:3232 failed: [Errno 113] No route to host

Furhermore the HA auto dicovers the device, but is unable to connect to it, resulting in the following error:

Can’t connect to ESP. Please make sure your YAML file contains an ‘api:’ line.

I already tried to connect to it with and without any devices connected to the gpio pin, thinking that maybe im using a wrong pin, but the result keeps being the same.

I have ‘a feeling’ that gateway should read 192.168.1.1 :blush:

That gateway looka very wrong and theres really no reason to be using static IP’s unless you are having problems to begin with.

theres really no reason to be using static IP’s unless you are having problems to begin with.

As you guys already said, router address is very wrong, agreed…
But, as far as static IP goes, i’d say that it’s pretty much “extremly good idea”, if not “a must”. mdns can be unreliable (at least from my experience), as a result it FW update will fail occasionally, moduels will go offline for a while…
If/when you will have many of these modules it’s nice to have them sorted, otherwise you’ll get “lost in space” pretty soon. Actually, each and every device in my HA network has either static IP od reservation in router (if static is not possible in device itself). Not to mention that HA /esp devices are all in it’s own segment.
DHCP is, apart from “casual” devices nothing but trouble in installations like this. Another example would be IP cameras with NVR recorder: you set all up, all is running - but only until first power outage. After power restore cameras get a different IP’s and nothing works anymore (tested more than once). Similar can happen with esp modules…

1 Like

The docs recommend you do. I always do.

“It’s recommended to provide a static IP for your node, as it can dramatically improve connection times.”

2 Likes

Yes, the GateWay address is wrong, but since it is only addressed when the device is trying to reach IP’s outside your subnet (f.e. the internet), it should not prevent it from connecting to the local network.

When an ESPHome device doesn’t connect to a wifi network within a certain time, it will activate it’s fallback hotspot.

So, can you see/connect to that ssid ??

Thanks for the answers so far guys.

The gateway was already fixed when i posted this topic, but i must have copied the old code here.

In the end I didnt get it to work with my esp32, so i went back to the esp8266 (D1 mini) and had the same problem.

What i did in the end to make it work was to get rid of the static IP code in the ESP firmware

manual_ip:
      # Set this to the IP of the ESP
      static_ip: 192.168.1.86
      # Set this to the IP address of the router. Often ends with .1
      gateway: 255.255.255.1
      # The subnet of the network. 255.255.255.0 works for most home networks.
      subnet: 255.255.255.0

and instead assigned a static IP directly in unify.

I dont know what exactly changed since i am using other esp8266 on other parts of my smarthome and i never had any trouble with the static IP code.

1 Like

Good to know. I provide static IPs to most of my smarthome devices anyways since I find it convinient and easy to keep an overview of everything that in my wifi.

1 Like

I tend to assign fixed IP’s to my stuff, but it is normally done in the dhcp server not on the esp. I always let the dhcp assign the ip then fix it, this saves any conflicts which may arise.

That being said I have set static IP’s on a few of my esp’s but only the same as the dhcp. It has helped with connection issues.

2 Likes

I do it in both.

Although I suck at networking so couldn’t explain if/why this is good practice. DHCP server level was mainly to manage centrally and make it easy to ping devices and see what is on my network. And then on my esp too for reasons lost which may or may not make sense. Maybe for faster connection or because the docs recommend it.

Something I picked up along the way when I was debugging things and reading the forum I think.

1 Like

I used to reserve IP’s in DHCP server, too. Until router died on me and i lost all my fixed IP’s. From there on i rather set static IP on devices. It can also happen (although rare) that router crashes and looses it’s settings, or something “doesn’t work right”, so best solution is factory reset or the router… so, not very safe solution, and if anything goes wrong there’s a lot of work (again).
If you keep notes and if you’re organized there’s no worry of IP conflict. Just set dhcp server range from, say 10 to 150 (or 200) and have static IP’s from 201 to 254 . I used to have that, until my devices count went up, so i ended up with /22 subnet, so now static IP’s are at 0.x, dhcp server runs at 1.x, HA devices are at 3.x (2.x is some sort of reserve, so to speak…)

Note that some routers may have problems if you set static IP in it’s dhcp range, so don’t forget to shrink this range.

And write all down, say in excel sheet.

2 Likes

I regularly make a backup of my routers configuration.
And that includes an overview of my DHCP reservations :wink:

1 Like

Yeah, well… me, too. But, when my router died i bought another (better) model and backup was useless…

I can probably still buy the same one (as it is still available), nevertheless, the DHCP table in the backup is human readable :stuck_out_tongue:

It’s not that i didn’t have data, it’s that I’ve had to input aaaaalll that data manually once again… and if you have 50+ devices it’s not a small amount of work.
And, sure, old model is still available, but since i’ve had a chance i decided to upgrade to a better (more powerful) model.

The changing routers stuff is why I run DHCP on pihole rather than on a router. Easy backup and restore. I run it on a seperate container under Proxmox.

1 Like

Aaa… you have pihole… i have AdGuard directly on my Asus (RT-AX88U pro, merlin FW). But now i have addon installed on my Asus which is basically an enhanced DHCP, so i can export/import backup only dhcp part and it’s independent of router model. But i still prefer static IP on devices.

1 Like

I run the home assistant Ad Guard add-on and it does my DHCP. Works great.

So my +50 reservations get backed up as part of my HA back-ups.

1 Like

Openwrt and don’t use sh*tty stock firmware which always comes with limitations (like doesn’t allow me to restore tha backup on a new router)

I would run openwrt if I happened to have router it would run on. I believe you can run it as it’s own server but could not really see an advantage to that.