It was three years ago. I started playing with MicroPython with camera support on an ESP32-Camera board with MicroPython version 1.11-XXX.
This time, the firmware support version 1.18-XXX. We may reach version 2.00-XXX by the end of 2022. The MicroPython team has been busy.
The build process and structure have changed since version 1.11-XXX.
This firmware is made especially for the ESP32-Camera board and was cleanly compiled with Espressif IDF version 4.4. It supports the OV2640 camera and PSRAM. To reduce size, webrepl, BLE, help modules were not included in the firmware.
I wish to reach a wider audience. So, I will try to make this as simple as possible. To join the fun, these are what you need to do:
The thonny IDE helps beginners flash new firmware and upload script files to a development board.
To flash a new MicroPython firmware, these are what you need to:
Hopefully, you will get MicroPython REPL in the thonny IDE shell window.
MicroPython v1.18-610-gcf7d962cf-kaki5 on 2022-06-10; ESP32 CAMERA module (KAKI5) with ESP32
>>>
We can test the camera module in the REPL
>>> import camera
>>> camera.init()
True
>>> img=camera.capture()
>>> len(img)
58810
>>>
Congratulation. We now have a working MicroPython with the camera module.
We will now upload the five script files onto the flash file system using thonny IDE. Click [Open...] to load each script file into the IDE. You should have all five files in different TAB windows. You need to edit the 'wifi.py' file. Change the "YOUR-SSID" and "YOUR-PWD" to the values of your home WiFi.
Save all the five files to "MicroPython device". Do this for each script file. Click File --> Save as... and choose MicroPython device as destination. Make sure to write the correct file name.
We can check whether all five files are in the flash storage using the REPL.
>>> uos.listdir()
['boot.py', 'help.py', 'html.py', 'site.py', 'webcam.py', 'wifi.py']
>>>
We are now ready to try our webcam server. In the REPL:
>>> execfile('webcam.py')
Camera ready?: True
Camera ready
Waiting ...
Waiting ...
Connected to dlink-3530
network config: ('10.0.0.46', '255.255.255.0', '10.0.0.138', '148.122.164.253')
PWD: M1XDYKh3
Start server 80
Try - http://10.0.0.46/login/M1XDYKh3
Your output will differ from what is shown here. Open a browser and go to the login URL. You will get "OK!" if successful. Now, go to the 'root' page, for example, http://10.0.0.46. You will receive a 'help' page.
Once login, the server is locked to the IP of the PC. Requests from other PCs are not allowed. To remove the lock, you need to logout, for example, http://10.0.0.46/logout. The server will create a new random login password. You will see the new password in the REPL.
('10.0.0.72', 37146) ['GET', '/logout']
New PWD: IT0XfQOQ
You need to use the new password to login again. You can disable the authentication scheme by 'auth.on=False' in webcam.py.
After login, you can try:
Please change the IP to your server IP. For more information, please read the help page.
Our webcam server provides us with microservices to control the camera and capture images. This means, on a linux PC, we can use wget or curl to request a service.
It is super easy to make timelapse video on a linux PC:
wget http://10.0.0.46/login/M1XDYKh3
-OR-
curl http://10.0.0.46/login/M1XDYKh3
wget http://10.0.0.46/foto -o foto1.jpeg
-OR-
curl http://10.0.0.46/foto --output foto2.jpeg
#!/bin/bash
cnt=0 while : do let "cnt=cnt+1" N=$( printf '%04d' $cnt ) curl http://10.0.0.87/foto --output foto$N.jpeg sleep 30 done
4. run the *get_foto.sh* script
```bash
/get_foto.sh 2>/dev/null &
[1] 34394
kill -9 34394
[1]+ Killed ./get_foto.sh 2> /dev/null
6. rotate the photos if needed using *convert* in a script *rot_foto.sh*, try different rotate value (-90, 90)
```bash
#!/bin/bash
for f in `ls foto*.jpeg`
do
echo "Rotate $f"
convert $f -rotate 90 $f
done
cat foto*.jpeg | ffmpeg -f image2pipe -r 1 -vcodec mjpeg -i - -vcodec libx264 tmlap.mp4
curl http://10.0.0.87/live --output live.avi
<ctrl>+c to kill curl
celluloid tmlap.mp4
celluloid live.avi
You can now live stream video from your ESP32-Camera board at your front gate.
You can also do other projects with your ESP32-Camera board now that you have camera-enabled MicroPython firmware.
Good luck.