My ESP32 Cam is not working as a webcam

Hello everybody! I hope you're all doing well.

I recently set up octoprint on my Raspberry Pi 2 B+ so I can use it on my Creality Ender 3 V2. Everything is working fine, except for the webcam.

I want to use the ESP32 camera module as the web cam however it just doesn't seem to work. The time-lapse works fine, its just the stream.

Note: When I try to open the stream directly from the browser, it works.

I really hope i could get your input to solve the issue. Thank you in advance!

What URL do you test in your browser, and what url do you have configured in the OctoPrint settings as the stream URL?

1 Like

Also see this thread: Octoprint with ESP32 with camera

1 Like

As info, many ESP32CAM firmwares are limited by being able to stream to a single client only. i.e. If you are testing and watching the stream in your browser, then other clients connecting to the camera will possibly be unable to get the stream. Just throwing it out there, in case this limitation might be affecting you.

http://192.168.1.63:81/stream

This is the URL configured and the same one I use in the browser. It works as a browser but not when configured.

Thanks for telling me, but I already knew that and I was testing them separately :slight_smile:

What address are you using to access OctoPrint?

You can also check the browser's error console to find out why it's not loading.

Octopi.local

Try using the IP address to access OctoPrint to see if that works.

Is that a direct link to an mjpeg stream, or is that a link to an HTML page that includes an <img> pointing to an mjpeg stream?

Thank you so much, I accessed Octoprint using its IP and it worked. The webcam is completely functional. Thanks again <3

Then the issue is confirmed - it's a browser security feature that blocks accessing local IP addresses from what it perceives as 'public' sites. It can't tell if octopi.local is private or public. You can only access the camera with a local IP if OctoPrint is accessed from a local IP. Hope that's clear enough...

1 Like

So another solution would be to find out the hostname of the esp32, and use that in the stream url instead of the ip address.

1 Like

Hi all.

I have the same problem, but i tried with both IP and hostname as the address. They both work on the snapshot:

But they both not work on the stream.
I'm using an esp32 cam with the following configuration on esphome:

substitutions:
  esphome_name: espcam_octoprint
  camera_name: espcam_octoprint

esphome:
  name: "${esphome_name}"
  friendly_name: espcam_octoprint

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

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

ota:
  password: ""

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

  manual_ip:
      static_ip: 192.168.1.188
      gateway: 192.168.1.1
      subnet: 255.255.255.0
      
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Espcam Fallback Hotspot"
    password: ""

esp32_camera:
  name: "${camera_name}"
  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
  # Image settings
  max_framerate: 5 fps
  idle_framerate: 0.1 fps
  resolution: 800x600
  jpeg_quality: 10

# http server setting
esp32_camera_web_server:
  - port: 8080
    mode: stream
  - port: 8081
    mode: snapshot

# Flash
switch:
  - platform: gpio
    name: "${camera_name} flash"
    pin: 4
    #inverted: True
  - platform: restart
    name: "${esphome_name} - Restart"
    id: restart_switch
    
captive_portal:

I also tested that there is a stream on http://192.168.1.188:8080 through the MJPG integration of home assistant, and i can see the video from it.

What could be wrong? The espcam is streaming into an home assistan dashboard, throuh the esphome integration.
I read My ESP32 Cam is not working as a webcam - #4 by MegaHurtz but it should not matter as long as i don't have a browser open on that page, right? Also, i even tried to remove the card showing the camera stream but nothing changed

( I would have embedded other images but i can only have one as new user )

Thanks in advance

Try to open the stream with vlx player and check if that works.

No idea whether the ha integration is keeping the stream occupied or not - but that's a way to check it.

I noticed that when i went home it started to work, both from octoprint web and octopod app.. also integrated octoprint in cura and i'm able to see the stream simultaneously with home assistant.

I thought it was suddenly fixed but now that i'm outside of my network i noticed that nothing works again on "octoprint" side: the camera is up, i can see it from home assistant, but both octoprint web and octopod are not, like before.
I guess it's some kind of security thing? I tried to open octoprint from different browser.. maybe it's also due to the fact that my octoprint is exposed to the outside word through a port-forwarding on my router?

Aaaah. K this makes sense now.

No it's not a security feature - you just didn't forward the cam image to the internet.

What did you do to be able to connect to the OctoPrint webinterface outside your network?
Just port forwarding?

If yes then you also have to foward your cam and use the forwarded URL in your app.

I personally would advise against port forwarding and would use a VPN to my home network instead.

Wireguard for example.

1 Like

Oooh okay. I thought that as long as the video was available into octoprint, that is then available to the internet, this would have worked.
So i guess octoprint camera is just a view into that ip camera, it's not taking the video and then streaming it again itself (makes sense)

yup it's more or less just a viewer. it's pretty much the same as typing the url directly into the browser.

@sciorty

I got my esp32cam working wiht home assitant.

My solution was to exclude the home assistant api:

# api:
#   encryption:
#     key: "adfafadsf..."

so only include the webserver component.
You just use esphome to host a webserver.
My feeling it that the link to homeassitant take priority or something?
using

esp32_camera_web_server:
  - port: 8080
    mode: STREAM
  - port: 8081
    mode: SNAPSHOT

Then allows for accessing <name>.local:8080, or <ip>:8080 in Octoprint