lemariva / uPyCam

Take a photo with an ESP32-CAM running MicroPython
https://lemariva.com/blog/2019/09/micropython-how-about-taking-photo-esp32
Apache License 2.0
140 stars 42 forks source link

MicroWebSrv handler exception: [Errno 2] ENOENT #13

Open tiwanacote opened 3 years ago

tiwanacote commented 3 years ago

Hi , I'm trying to make running uPyCam over ESP32CAM but I getting this error when trying to connect via browser with http://<>

MicroWebSrv handler exception: In route GET / [Errno 2] ENOENT

I'm not an experimented user, maybe you can help me... It is an exception into def _processRequest(self) : function

'except Exception as ex : print('MicroWebSrv handler exception:\r\n - In route %s %s\r\n - %s' % (self._method, self._resPath, ex)) raise ex`'

Thank you!

lemariva commented 3 years ago

Try to erase the flash, flash the firmware again and upload the code. Keep me updated!

TizioMaurizio commented 3 years ago

Hello, i get the same error as above and I already tried erasing and flashing again, is there any other solution? Also with http://<<board-ip>>/?stream=true will I get a stream fast enough to reach something like at least 10fps for robot control or it's just gonna be enough for time lapses?

a message I always get when initializing the camera is E (49289) gpio: gpio_install_isr_service(411): GPIO isr service already installed (in red) but it doesn't seem to stop the camera from taking pictures, with a script of mine and using camera.capture(1) (without argument it throws an exception) I get to save one picture every 500ms in different jpgs

maurera commented 3 years ago

Thanks @lemariva for this project. I'm hoping to be able to have a camera webserver running with micropython using a basic ESP32 Cam.

My setup was the following:

Then when I run main.py, I get the same error as @tiwanacote and @TizioMaurizio

Any advice would be appreciated!

TizioMaurizio commented 3 years ago

Thanks @lemariva for this project. I'm hoping to be able to have a camera webserver running with micropython using a basic ESP32 Cam.

My setup was the following:

  • Erased flash, then flashed with lemariva/micropython-camera-driver/firmware/micropython_b7883ce_esp32_idf4.x_ble_camera.bin
  • Setup webrepl and connected to wifi network
  • Edited config.py.sample and renamed to config.py
  • Used webrepl file transfer to manually copy each file over

Then when I run main.py, I get the same error as @tiwanacote and @TizioMaurizio

Any advice would be appreciated!

Since I just needed a video stream for first person view on Lan I managed to get it to work by using UDP socket and gave up on the webserver, if you need the same I'll send you some scripts, still up for getting the webserver to work since I also could use it in the future :D

maurera commented 3 years ago

Sure, that would be great if you have something working. You're using the esp 32 cam or a different module?

I was close to abandoning using micropython on the esp32 cam and just reverting to an Arduino sketch

TizioMaurizio commented 3 years ago

@maurera Yes I use esp32 cam, once I found out how quick it is to program with micropython I couldn't go back to the sketches, I managed to stream the video at like 15fps with QVGA resolution and by upscaling the image it's acceptable. I have a script on ESP32 that goes like:

import camera
import socket
import _thread
import utime

host = ''
port = 5555
RECEIVER = socket.getaddrinfo('RECEIVING_DEVICE', 80)[0][-1][0] #resolve pc hostname
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((host, port))

def stream():
    begin = utime.ticks_ms()
    time = utime.ticks_ms()
    prev = time
    while True:
        time = utime.ticks_ms()
        if (time-prev>=50):
            s.sendto(camera.capture(), (RECEIVER, 5555))
            prev = utime.ticks_ms()

camera.init(1)
camera.framesize(camera.FRAME_QVGA)
# The options are the following:
# FRAME_96X96 FRAME_QQVGA FRAME_QCIF FRAME_HQVGA FRAME_240X240
# FRAME_QVGA FRAME_CIF FRAME_HVGA FRAME_VGA FRAME_SVGA
# FRAME_XGA FRAME_HD FRAME_SXGA FRAME_UXGA FRAME_FHD
# FRAME_P_HD FRAME_P_3MP FRAME_QXGA FRAME_QHD FRAME_WQXGA
# FRAME_P_FHD FRAME_QSXGA
# Check this link for more information: https://bit.ly/2YOzizz
camera.quality(10)
_thread.start_new_thread(stream, ())

camera.capture() inside stream is what gets one frame from the camera, i suggest avoiding the use of threads and putting it inside the for loop of what you are doing in order to speed up everything

Then there is the code on my pc that uses opencv-python to show the stream:

import cv2
import numpy as np
import time
import socket
import traceback

host = ''
port = 5555
RECTIME = 20
RECSIZE = 32768 #images are bigger than default udp packet size
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((host, port))
#start udp camera stream on ESP32 Camera and this script will show the camera stream
def receive():
  global message
  message2, address = s.recvfrom(RECSIZE)
  message = bytearray(message2)
  nparr = np.frombuffer(message, np.uint8)
  img = cv2.imdecode(nparr, cv2.IMREAD_UNCHANGED)
  return img

def show():
  prevTime = time.time()
  i = 0
  while True:
    try:
      image = receive()
      scale_percent = 200  # percent of original size
      width = int(image.shape[1] * scale_percent / 100)
      height = int(image.shape[0] * scale_percent / 100)
      dim = (width, height)
      # resize image
      resized = cv2.resize(image, dim, interpolation=cv2.INTER_AREA)
      cv2.imshow("Res", resized)
      cv2.waitKey(1)
    except:
      traceback.print_exc()

show()

It's very raw but for now it works :D

PS remember that esp32 camera consumes a lot with wifi and camera enabled and can easily brownout if not powered enough PPS i suggest this buggy but very useful gui to use the terminal and send files to esp32 through wifi https://github.com/BetaRavener/uPyLoader

e135193 commented 3 years ago

@lemariva I have downloaded your project and flashed the ESP32. However I get the error below. I have even tried stream mode. Nothing changed. Is there any further improvement in the project ?

MicroWebSrv handler exception:

idiotstone commented 2 years ago

you should copy files under www to the board

e135193 commented 2 years ago

I have flashed the latest firmware however the module restarts itself with the error below @lemariva

connecting to network...
network config: ('192.168.0.26', '255.255.255.0', '192.168.0.1', 'X.X.X.X')
E (17435) gpio: gpio_install_isr_service(460): GPIO isr service already installed
MicroPython v1.14-122-g9fef1c0bd-dirty on 2021-03-30; Camera Module (i2s) with ESP32
Type "help()" for more information.
e135193 commented 2 years ago

and when I run main.py I get error below

Traceback (most recent call last):
  File "<stdin>", line 12, in <module>
  File "webserver.py", line 48, in run
OSError: Camera Init Failed
wildernessfamily commented 1 year ago

I've tried several different ways of initializing the camera and nothing seems to work. I also continue to receive OSError: Camera Init Failed. The last post has been over a half a year a go. Has there been any solution to this problem?

TizioMaurizio commented 1 year ago

I don't use the webserver in question but my camera successfully starts by excecuting these instructions, mind that there could be some exposed pins that will be used by the camera so you can't connect anything to such pins (like for the sd card, but I don't remember which they are) a quick check of the schematics anyway will clear the doubt

import camera  
[...]
camera.init(0, format=camera.JPEG, fb_location=camera.PSRAM)  
[...]
camera.capture()  
wildernessfamily commented 1 year ago

Hi @TizioMaurizio, Thanks for taking the time to respond. I'm away for a few days. I'm going to give that a try next weekend. Thank you again!