Issue with ESP32 cam after renaming

I have an issue with an ESP32 cam board failing to initialise the camera after I renamed it. I changed exactly 3 things (see below). If I compile and upload the original YAML config, the device works; i.e. the camera initialises successfully and I am able to access both the camera stream and the snapshot stream. If I compile and upload the new YAML config, the camera fails to initialise and I am unable to access either the camera or the snapshot stream. What I changed was:

  1. The name of the YAML config file
  2. The name of the device (in the device_name: tag in the substitutions: section)
  3. The the “friendly name” of the device (in the friendly_name: tag in the substitutions: section)

Of course, Items 2 and 3 will flow down in to the rest of the config as their values are expanded out where ever they are used.

The following shows the differences in the 2 YAML config files:

paul@growler:~/data/Home Assistant/ESPhome$ diff freenoveesp32testcam.yaml hallcam.yaml 
3c3
<   device_name: freenoveesp32testcam
---
>   device_name: hallcam
5c5
<   friendly_name: "Freenove ESP32 Test Camera"
---
>   friendly_name: "Hallway Internal Camera"
132d131
< 

I will upload the new YAML config below.

Given that I think what I’m doing relies on mDNS, I have rebooted both my Wi-Fi access points and router, and ensured that a static IP address is not being reserved for the host in either of it’s guises.

YAML code to follow…

Newer of the 2 Configs:

###############################################################################
substitutions:
  device_name: hallcam
  camera_name: ${device_name}
  friendly_name: "Hallway Internal Camera"
  device_description: "Freenove ESP32 CAM and OV2640 based CCTV Camera with motion detection from a HC-SR501 PIR "

esphome:
  name: ${device_name}
  comment: '${device_description}'
  platform: ESP32
  board: node32s

wifi:
  ssid: !secret iot_wifi_ssid
  password: !secret iot_wifi_pass

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "${friendly_name}"
    password: !secret esphome_admin_pass

captive_portal:

# Enable logging
logger:
  level: DEBUG   # VERY_VERBOSE for more

# Enable Home Assistant API
api:
  reboot_timeout: 15min
  password: !secret esphome_admin_pass
  encryption:
    key: !secret esphome_noise_key

ota:
  password: !secret esphome_admin_pass

time:
  - platform: homeassistant

######################

# the web_server & sensor components can be removed without affecting core
# functionaility.

web_server:
  port: 80
  auth:
    username: !secret esphome_admin_user
    password: !secret esphome_admin_pass

sensor:
  - platform: wifi_signal
    name: "${device_name} - Wifi Signal Strength"
    update_interval: 60s
  - platform: uptime
    name: "${device_name} - Uptime"

text_sensor:
  - platform: version
    hide_timestamp: true
    name: "${device_name} - ESPHome Version"
  - platform: wifi_info
    ip_address:
      name: "${device_name} - IP Address"
    ssid:
      name: "${device_name} - Connected SSID"
    bssid:
      name: "${device_name} - Connected BSSID"
    mac_address:
      name: "${device_name} - Mac Wifi Address"

# Configuration for Wrover Camera
# https://esphome.io/components/esp32_camera.html#configuration-for-wrover-kit-boards

esp32_camera:
  name: "${camera_name}"
  internal: true         # Marked as internal because we're going to be using
                         # MotionEye, and ESP32 Cams can only support one web
                         # stream at a time.
  external_clock:
    pin: GPIO21
    frequency: 20MHz
  i2c_pins:
    sda: GPIO26
    scl: GPIO27
  data_pins: [GPIO4, GPIO5, GPIO18, GPIO19, GPIO36, GPIO39, GPIO34, GPIO35]
  vsync_pin: GPIO25
  href_pin: GPIO23
  pixel_clock_pin: GPIO22
  # Image settings
  max_framerate: 10 fps   # default: 10 fps, max 60
  idle_framerate: 0.2 fps # default: 0.1 fps - framerate for 'picture'
                          # in HA dashboard
  resolution: 800x600     # default: 640x480 (VGA) - higher res requires
                          # more memory
  jpeg_quality: 10        # 10 (best) to 63 (worst)
  wb_mode: auto           # auto, sunny, cloudy, office or home

esp32_camera_web_server:
  - port: 8080
    mode: stream
  - port: 8081
    mode: snapshot

binary_sensor:

  - platform: gpio
    pin: GPIO14
    name: "${friendly_name} PIR"
    device_class: motion
    on_press:                         # Closed
      then:
        - light.turn_on: green_led
    on_release:                       # Open
      then:
        - light.turn_off: green_led

output:
  - platform: gpio
    id: led
    pin: GPIO12
    inverted: False

light:
 - platform: binary
   id: green_led
   name: "${device_name} - Indicator LED"
   output: led
   internal: true

Oh yes; error messages in the failure case:

[19:20:11][E][camera.c:1113] camera_probe(): Detected camera not supported.
[19:20:11][E][camera.c:1379] esp_camera_init(): Camera probe failed with error 0x20004
[19:20:11][E][esp32_camera:024]: esp_camera_init failed: ERROR
[19:20:11][E][component:112]: Component esp32_camera was marked as failed.
[19:20:11][C][wifi:037]: Setting up WiFi...

and then a bit later:

[19:20:14][E][component:112]: Component esp32_camera_web_server was marked as failed.
[19:20:14][E][component:112]: Component esp32_camera_web_server was marked as failed.

…and:

[19:20:15][C][esp32_camera:079]:   Resolution: 800x600 (SVGA)
[19:20:15][E][esp32_camera:095]:   Setup Failed: ERROR
[19:20:15][C][psram:020]: PSRAM:

and:

[19:20:15][C][esp32_camera_web_server:088]: ESP32 Camera Web Server:
[19:20:15][C][esp32_camera_web_server:089]:   Port: 8080
[19:20:15][C][esp32_camera_web_server:091]:   Mode: stream
[19:20:15][E][esp32_camera_web_server:097]:   Setup Failed
[19:20:15][C][esp32_camera_web_server:088]: ESP32 Camera Web Server:
[19:20:15][C][esp32_camera_web_server:089]:   Port: 8081
[19:20:15][C][esp32_camera_web_server:093]:   Mode: snapshot
[19:20:15][E][esp32_camera_web_server:097]:   Setup Failed

TBH, I think all but the first blocks are beacuse of the first???

OK, so I did a bit of digging through the code. I thought to use the external_components feature to compile my own version of the esp_camera component, adding (more) statements to potentially log more stuff and figure out what’s going on…

Best-laid plans of mice and men, and all that.

It seems like whatever is going on is happening in Espressif’s stuff; specifically in esp32_camera_init() and then within camera_probe() inside that. (Of course, the logs I posted above tell me this, however… I had assumed that these were functions/methods within ESPHome.) If I’ve understood things correctly, these are in Espressif’s libraries. So what to do next? All suggestions gratefully received…

OK, a further addition: Upping log level to VERY_VERBOSE gives me a more explicit error message that I missed before:

“Camera probe failed with error 0x20004”.

The above is logged by camera_probe(). Googling suggest all sorts of unlikely things, most of them hardware-related. This does not add up with what I’m seeing, because reverting to the original device name causes the board to work again. The only solution I seem to have at this point is to keep the original device/host name, which seems unsatisfactory at best.

As before, all suggestions welcome…