Err No 111 connection refused with esp32

I have tried a Wemos D1 mini in Esphome, and now I am trying a ESP32 , both of which say they have wifi. I have set a static ip address in a com_led.yaml file together with the wifi ssid and password, and they are both enclosed in double inverted commas. I have also set a static ip in my routers’ dhcp setting, and turned off my routers’ firewall
When I run the log it says that the ESP might not be connected to wifi yet (error connecting to 192.168.0.35: [Errno 111] Connection refused.

What else do I have to do to get the connection, as I am at a loss now.
Thanks

Post your esp configuration or we’ll just be guessing.

Do mean this:

esphome:
name: comp_led
platform: ESP32
board: esp32doit-devkit-v1

wifi:
ssid: “unifi”
password: “mypass”

Optional manual IP

manual_ip:
static_ip: 192.168.0.35
gateway: 192.168.0.1
subnet: 255.255.255.0
dns1: 194.168.4.100
dns2: 194.168.8.100

When the device is simply not connected to the network I get a different error - “no route to host”. I would keep on looking down the path of firewalls and blocked ports.

Also - when you post a config make sure to embed with “code” tags. they look like </> in the menu bar when you are posting, and if you use them your result will look like this:

esphome:
  name: ble_tracker
  platform: ESP32
  board: esp32doit-devkit-v1

wifi:
  ssid: "WLAN"
  password: "password"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Ble Tracker Fallback Hotspot"
    password: "mq5Qce9CucxL"

  manual_ip:
    static_ip: 192.168.0.44
    gateway: 192.168.0.1
    subnet: 255.255.255.0

This lets us read the code more easily and also lets us check indenting, although esphome is pretty good about not letting yaml errors slip through.

`Ok, sorry about not using code tags before. Done now:
The firewall on my TP_Link router is disabled, and when I look in the logs ,router, there are no messages about failing to connect nor anything for or with the ip address of the ESP32. I have allowed Internet access control, but that didin’t make any difference.
AFAIK, there are no blocked ports, but what port does the ESP32 use.
Also there are 5 instances of the ESP in my routers’ DHCP client list.
I can ping the ESP and receive no errors.

esphome:
  name: comp_led
  platform: ESP32
  board: esp32doit-devkit-v1

wifi:
  ssid: "unifi"
  password: "mypass"
  
  manual_ip:
    static_ip: 192.168.0.35
    gateway: 192.168.0.1
    subnet: 255.255.255.0
    dns1: 194.168.4.100
    dns2: 194.168.8.100

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Comp Led Fallback Hotspot"
    password: "AoaGw4LaHdzK"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

Ok - if it is indeed failing in the connect to wifi, then you should be able to see the fallback access point you have configured (and connect to it).

But looking at your code, everything looks fine.

Since this is WROOM 32 or similar, I assume it has a USB port. I would connect it to your PC, connect ESPHome to the serial port that should appear, and then capture the logs that way.

Yes the ESP has a usb port, so do you meant to connect by usb cable to my computer. This is how I have it connected now. How does a serial port appear when the esp32 is connected by usb.
Which logs, the ones in the router or the log in HA for esphome, either way, there is nothing I can see that helps me.

If makes any difference, I have noticed that connecting by usb, the ESP32 device does not light up, ie no sign of it actually alive or working. But if I connect it by a USB to TTL adaptor to my computer, then a small led does light up . It still doesn’t connect to wifi tho’
How do I actually connect to the fallback hotspot??
Thanks

Ok, I assume you are running the ESPHome HA add-on? You must have flashed it somehow.

If so when the device is plugged in to the PC or Pi or whatever is running the add on it should be recognised and you can connect to see the ESP log over the USB connection.

Do you have a mobile phone? You should be able to see the fallback hotspot advertised in the available wifi networks. If you can’t odds are it’s connected and you have other issues.

Yes , running the ESPhome addon, and uploaded the required files to the ESP32, then added the network details. The yaml file validates fine, but no connection. I’ve tried a couple of other things earlier and the bottom line is that no flashing tool can connect to the esp32 chip to flash it with anything. I have also tried to upload an Arduino sketch to it but even tho’ the serial port is recognised as com6, and the board gives back some information, during the upload process it errors out saying board not connected.
I think the said board is ready for the bin.
On my mobile in wifi networks, the fallback hotspot is not showing, and when I try to add it manually, it can’t connect…
I’m waiting for a ESP32-DevKitC NodeMCU WiFi WLAN CP2102 ESP32-WROOM-32D IoT 2-In-1 Microcontroller Bluetooth Module Development Board from Amazon . So I’ll try that and see how it goes.

Thanks

Ok, I now have my ESP32 DevKitC NodeMCU board, which I have added into esphome in HA. I then uploaded a Arduino wifi sketch to the said board and in a serial monitor to give me an IP address of the board. I entered this in the yaml file:

esphome:
  name: comp_led
  platform: ESP32
  board: nodemcu-32s

wifi:
  ssid: "unifi"
  password: "33810492"
  
  # Optional manual IP
  manual_ip:
    static_ip: 192.168.0.21
    gateway: 192.168.0.1
    subnet: 255.255.255.0
    dns1: 194.168.4.100
    dns2: 194.168.8.100
     # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Comp Led Fallback Hotspot"
    password: "dSOAxFnGLCWd"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

When open a log file for the said board , it returns the same error message as the other one about ESP might not be connected to wifi.
The ESP32 board is showing up in my routers dhcp client list, and I can see the wifi connection on my phone in the list of wifi networks.

But, since I uploaded a esp file, there is no connection, aaargh!

Sorry - I am a bit confused. I thought you already have an ESPHome config loaded on your board?

If not, you will need to load the first time via USB. You will need to enable flashing by pressing the FLASH button on the board.

Only once you have an ESPHome config loaded on the board will you be able to do OTA updates.

I suppose if you are having issues flashing from the ESPHome add-on you could always flash on OTA script onto the unit first using whatever method you have that works.

https://www.google.com/search?client=safari&rls=en&q=esp+code+to+enable+an+ota+update&ie=UTF-8&oe=UTF-8

Thanks,but this is a new board, or a different one. It’s a Nodemcu board.
Aah, I didn’t realise you had to flash the board the first time with the binary file.
From what I can see there is no FLASH button, but there are BOOT and RST buttons.

I have flashed the board now using NodeMCU PyFlasher and it was a success.
I then plugged the board back in to HA and according to the log file the board is not connected to wifi. Again, aaargh!

This is the validation readout of the comp_led.yaml file, if it makes any difference:

NFO Reading configuration /config/esphome/comp_led.yaml...
INFO Configuration is valid!
esphome:
  name: comp_led
  platform: ESP32
  board: nodemcu-32s
  arduino_version: [email protected]
  build_path: comp_led
  platformio_options: {}
  includes: []
  libraries: []
wifi:
  manual_ip:
    static_ip: 192.168.0.21
    gateway: 192.168.0.1
    subnet: 255.255.255.0
    dns1: 194.168.4.100
    dns2: 194.168.8.100
  ap:
    ssid: Comp Led Fallback Hotspot
    password: sU3459VAgZ9P
    ap_timeout: 1min
  domain: .local
  reboot_timeout: 15min
  power_save_mode: LIGHT
  fast_connect: false
  networks:
  - ssid: unifi
    password: 'mypass'
    priority: 0.0
  use_address: 192.168.0.21
captive_portal: {}
logger:
  baud_rate: 115200
  tx_buffer_size: 512
  hardware_uart: UART0
  level: DEBUG
  logs: {}
api:
  port: 6053
  password: ''
  reboot_timeout: 15min
ota:
  safe_mode: true
  port: 3232
  password: ''


Ok, a bit more info:
When, in the log file, it says connection refused, I see now that the connection it is trying is the fixed ip address and the port number:
192.168.0.35:6053

There are 4 instances of the ESP in my routers dhcp client, and I can ping all of them. But when I try each ip address for the ESP connection, it still fails.
Ignore the ip address of 192.168.0.21 in the above post, as it no longer exists.

I have enabled port 6053 in my router as well as in my desktop, but it doesn’t make any difference, still no connection.
I must be doing something wrong , or something I have missed!!

Your config is quite complex. Personally I would start with the most basic config, the one that ESPHome add-on creates when you add a new device. Compile and upload that config to your ESP. Let the ESP connect via DHCP and move on from there.

If that still doesn’t work, I am unable to offer much more.

Rob, were you ever able to get this figured out?

did you get this working?
i have the exact same issue!

but the unit is definitely on my network:
image

Hi, and yes I did eventually as it has been working fine for some time now.

Thanks anyway.

Would you be so kind as to let us know how you fixed this issue?

Thanks