Wireguard and ESPhome Connecting to xxx.xx.xx.x:3232 failed: timed out

Hello,

I have problems to connect my ESP32 device via Wireguard to ESPHome.

I am using following code for the ESP32 device.

esphome:
  name: bmp180testi2
  friendly_name: BMP180testi2

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "xxxx="

ota:
  - platform: esphome
    password: "xxxxxx"

  
wifi:
  ssid: ext_wifi
  password: xxxxxxx
  use_address: 172.27.66.3
  

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


captive_portal:

# Example configuration entry
time:
- platform: homeassistant
  id: homeassistant_time
  on_time_sync: 
    then:
      - logger.log: "Synchronized sntp clock"
- platform: sntp
  timezone: Europe/Helsinki
  servers:
    - 0.pool.ntp.org
    - 1.pool.ntp.org
    - 2.pool.ntp.org
  update_interval: 60s

# Example configuration entry
wireguard:
  address: 172.27.66.6
  private_key: xxxxxxxxx=
  peer_endpoint: domain.com
  peer_public_key: xxxx=
  peer_allowed_ips: 0.0.0.0
  peer_port: 1600
# netmask: 0.0.0.0
  peer_persistent_keepalive: 15s


i2c:
  sda: GPIO21
  scl: GPIO22
  scan: true

sensor:
- platform: bmp085
  temperature:
    name: "Outside Temperature"
  pressure:
    name: "Outside Pressure"
  update_interval: 60s

The log is following:

INFO ESPHome 2024.10.3
INFO Reading configuration /config/esphome/bmp180testi2.yaml...
INFO Detected timezone 'Europe/Helsinki'
INFO Generating C++ source...
INFO Compiling app...
Processing bmp180testi2 (board: esp32dev; framework: arduino; platform: platformio/[email protected])
--------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
Dependency Graph
|-- AsyncTCP-esphome @ 2.1.4
|-- WiFi @ 2.0.0
|-- FS @ 2.0.0
|-- Update @ 2.0.0
|-- ESPAsyncWebServer-esphome @ 3.2.2
|-- DNSServer @ 2.0.0
|-- ESPmDNS @ 2.0.0
|-- noise-c @ 0.1.6
|-- Wire @ 2.0.0
|-- esp_wireguard @ 0.4.2
RAM:   [=         ]  13.3% (used 43696 bytes from 327680 bytes)
Flash: [=====     ]  53.6% (used 983909 bytes from 1835008 bytes)
========================= [SUCCESS] Took 21.21 seconds =========================
INFO Successfully compiled program.
INFO Connecting to 172.27.66.3
ERROR Connecting to 172.27.66.3:3232 failed: timed out

The wireguard works just fine, I have tested the configuration with my Iphone.

I have now fought couple of days with the error without finding a solution.

Can anyone advise me forward. Any tips?

Is the device connecting and alive at the IP?

Wiregaurd show show it in logs and if failing connection why.

I change my wg settings, I was able to get a bit forward.
Now I am receiving following log message:

INFO ESPHome 2024.10.3
INFO Reading configuration /config/esphome/180testibackup.yaml...
INFO Detected timezone 'Europe/Helsinki'
INFO Starting log output from 172.27.66.3 using esphome API
WARNING Can't connect to ESPHome API for bmp180testi @ 172.27.66.3: Timeout while connecting to [AddrInfo(family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>, proto=6, sockaddr=IPv4Sockaddr(address='172.27.66.3', port=6053))] (TimeoutAPIError)
INFO Trying to connect to bmp180testi @ 172.27.66.3 in the background

When I try add device manually under Devices and Services → ESPHome I received following error:

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

According to my understanding it is connecting fine.

The WG log shows following:

  allowed ips: 172.27.66.3/32
  latest handshake: 42 seconds ago
  transfer: 892 B received, 340 B sent
  persistent keepalive: every 25 seconds

Originally I was thinking maybe you were using an incorrect api key. I belive this even more.

If the api key is correct. The port or traffic used to communicate is blocked

It could be the device is fully functioning but assuming it is working I would suspect api key wrong

Thank you.

I made a clean install with clean install with brand new API key. The same problem occurs.

How do I check potential blocked port in home assistant?

It will be to wiregaurd and it will Show in log

I would test connection outside wiregaurd to be sure all is ok