Esp32-cam always disconnected from HA (its not WiFi problem)

Hi
I used esp32 cam. The connection always disconnected. you can see that from the log
How I fix it?

The esphome code

substitutions:
  # Modify variables based on your settings
  hostname: 'livingroomcam'
  ssid: '***'
  password: '***'
  
esphome:
  name: $hostname
  platform: ESP32
  board: esp32dev
wifi:
  ssid: $ssid
  password: $password
  fast_connect: True
api:
#  reboot_timeout: 0s
ota:
logger:

# ESP32-CAM
esp32_camera:
  external_clock:
    pin: GPIO0
    frequency: 20MHz
  i2c_pins:
    sda: GPIO26
    scl: GPIO27
  data_pins: [GPIO5, GPIO18, GPIO19, GPIO21, GPIO36, GPIO39, GPIO34, GPIO35]
  vsync_pin: GPIO25
  href_pin: GPIO23
  pixel_clock_pin: GPIO22
  power_down_pin: GPIO32

  name: livingroomcam
 

The log

[01:03:50][C][esp32_camera:051]:   External Clock: Pin:0 Frequency:20000000
[01:03:50][C][esp32_camera:052]:   I2C Pins: SDA:26 SCL:27
[01:03:50][C][esp32_camera:053]:   Reset Pin: -1
[01:03:50][C][esp32_camera:074]:   Resolution: 640x480 (VGA)
[01:03:50][C][esp32_camera:097]:   JPEG Quality: 10
[01:03:50][C][esp32_camera:099]:   Contrast: 0
[01:03:50][C][esp32_camera:100]:   Brightness: 0
[01:03:50][C][esp32_camera:101]:   Saturation: 0
[01:03:50][C][esp32_camera:102]:   Vertical Flip: ON
[01:03:50][C][esp32_camera:103]:   Horizontal Mirror: ON
[01:03:50][C][esp32_camera:120]:   Test Pattern: NO
[01:03:50][C][api:095]: API Server:
[01:03:50][C][api:096]:   Address: livingroomcam.local:6053
[01:03:51][D][esp32_camera:157]: Got Image: len=21349
[01:04:01][D][esp32_camera:157]: Got Image: len=21268
[01:04:11][D][esp32_camera:157]: Got Image: len=21760
[01:04:23][D][esp32_camera:157]: Got Image: len=21076
[01:04:31][D][esp32_camera:157]: Got Image: len=21354
[01:04:41][D][esp32_camera:157]: Got Image: len=21309
[01:04:55][D][esp32_camera:157]: Got Image: len=21411
[01:05:01][D][esp32_camera:157]: Got Image: len=21548
[01:05:11][D][esp32_camera:157]: Got Image: len=21224
[01:05:22][D][esp32_camera:157]: Got Image: len=21219
[01:05:31][D][esp32_camera:157]: Got Image: len=21517
[01:05:44][D][esp32_camera:157]: Got Image: len=21125
[01:05:51][D][esp32_camera:157]: Got Image: len=21079
[01:06:01][D][esp32_camera:157]: Got Image: len=21045
[01:06:12][D][esp32_camera:157]: Got Image: len=20989
[01:06:21][D][esp32_camera:157]: Got Image: len=21034
[01:06:31][D][esp32_camera:157]: Got Image: len=20876
[01:06:41][D][esp32_camera:157]: Got Image: len=20750
[01:06:51][D][esp32_camera:157]: Got Image: len=20920
[01:07:04][D][esp32_camera:157]: Got Image: len=20950
[01:07:11][D][esp32_camera:157]: Got Image: len=21005
[01:07:25][D][esp32_camera:157]: Got Image: len=20868
[01:07:25][D][api:067]: Disconnecting Home Assistant 0.102.2 (192.168.1.60)
[01:07:31][D][esp32_camera:157]: Got Image: len=21101
[01:07:37][D][api.connection:583]: Client 'Home Assistant 0.102.2 (192.168.1.60)' connected successfully!
[01:07:41][D][esp32_camera:157]: Got Image: len=21003
WARNING Disconnected from API: Timeout while waiting for message response!
INFO Connecting to livingroomcam.local:6053 (192.168.1.67)
INFO Successfully connected to livingroomcam.local
[01:08:09][D][api:067]: Disconnecting Home Assistant 0.102.2 (192.168.1.60)
[01:08:12][D][esp32_camera:157]: Got Image: len=21166
[01:08:19][D][api.connection:583]: Client 'Home Assistant 0.102.2 (192.168.1.60)' connected successfully!
[01:08:23][D][esp32_camera:157]: Got Image: len=21062
[01:08:29][D][api:067]: Disconnecting Home Assistant 0.102.2 (192.168.1.60)
[01:08:31][D][esp32_camera:157]: Got Image: len=21108
[01:08:38][D][api.connection:583]: Client 'Home Assistant 0.102.2 (192.168.1.60)' connected successfully!
[01:08:42][D][esp32_camera:157]: Got Image: len=21059
[01:08:54][D][esp32_camera:157]: Got Image: len=21018
[01:08:57][D][api:067]: Disconnecting Home Assistant 0.102.2 (192.168.1.60)
[01:09:01][D][esp32_camera:157]: Got Image: len=21067
[01:09:02][D][api.connection:583]: Client 'Home Assistant 0.102.2 (192.168.1.60)' connected successfully!

Try setting a static IP address and then if that fails use ping to locate the device. By default it uses mDNS.

Thanks you fast response
How I use ping to locate the device?

You will find it in the FAQ here;

Dig deep into the documents as ESPHome is awesome!

You think its ok use : status_use_ping + static ip - or its was problem ?

Not a problem per say just a different way of doing it. I have a few esp32 cams and from time to time they do drop connection. but at this stage it is worth looking into.

I have an esp32 cam with arduino sketch … I inserted the cam in the home assistant with the card Pictures but I only see the cam when I am under the local network in HA … While if I access HA remotely with a private IP address it does not I see nothing … How come since the flow is still local? @skutter

This thread is about esphome. Please start another thread.

On a AI-thinker ESP32 cam device the esphome code works great for everything like ble tracker, I/O ports, rgb driver and so on. I’ve used it for all those things with out any disconnects.
Also if I use Arduino cam code the AI-thinker cam works good. The camera works.

As soon as this code is added to esphome, I start getting the disconnects.

esp32_camera:
  external_clock:
    pin: GPIO0
    frequency: 20MHz
  i2c_pins:
    sda: GPIO26
    scl: GPIO27
  data_pins: [GPIO5, GPIO18, GPIO19, GPIO21, GPIO36, GPIO39, GPIO34, GPIO35]
  vsync_pin: GPIO25
  href_pin: GPIO23
  pixel_clock_pin: GPIO22
  power_down_pin: GPIO32
  name: cam1 

When the camera is not disconnected It Works in HA with esphome code.
Doesn’t that eliminate the hardware and network problem possibility’s?
Does that not point to a problem in the core of esphome’s esp32_camera: ?

Are you sure you are using an appropriate power supply? I used to have a lot of issues with esp32-cam when I had a weak power supply, but once I shifted to a better one all those problems have gone away.

1 Like

Found it for now. It’s working… For some reason a newer nighthawk router running as an access point doesn’t like esp32 devices.

Connected to a really old netgear access point and now connects quick but gives up every few minutes.

How do I find out why the new router running as a access point is not playing with the esp32s? Does this have something to do with mDNS?

Another update… Went to Ubiquiti APs and ESP32s work wonderful so far.

1 Like