POST images from ESP32-CAM (MicroPython) to the server

If you want to use ESP32-CAM quickly, you can use Arduino IDE.

  1. Short the IO0 / GND and write a sketch
  2. When writing is completed, put it back and start it.

That is very troublesome.

That's where MicroPython comes in.

Quoted from official documentation

MicroPython works on a variety of system and hardware platforms.

However, since it does not currently support ESP32-CAM, there is no library for using the camera. (There is a custom FW that can use the camera, and this time I used it) In addition, MicroPython is a subset of Python, so some methods and modules are not supported.

MicroPython version of requests urequests

MicroPython has a library called urequest, which can be used almost like requests. Easy to install.

import upip
upip.install('urequests')

However, when I installed it this way, I couldn't call the method. So I transferred the one pulled from the official MicroPython repository to esp32 and used it. urequest.py Transferring to esp32 is easy with ampy.

#installation of ampy
$ pip install adafruit-ampy

#File transfer to esp32
$ ampy -p /dev/tty.<According to the environment> put <File>

Initially, just like when using Python requests,

urequests.post(url, files={'image': open('Image file', 'rb)})

I was wondering if I could go there, but urequests doesn't have files.

As a result of various investigations, I found that I could go by converting to JSON once.

buf = camera.capture()
img_byte = base64.b64encode(buf)
img_json = ujson.dumps({"image": img_byte})
res = urequests.post(url, data=img_json)

I referred to this article. Send / receive image data as JSON in Python over the network

The processing on the received server side (Flask) looks like this

data = request.data.decode('utf-8')
data_json = json.loads(data)
image = data_json['image']
image_dec = base64.b64decode(image)
data_np = np.frombuffer(image_dec, dtype='uint8')
decimg = cv2.imdecode(data_np, 1)
cv2.imwrite(filename, decimg)

For the time being, the purpose of "POST the image taken by ESP32-CAM" was fulfilled. Click here for what I made ↓ ESP32-CAM_ImagePost

Recommended Posts

POST images from ESP32-CAM (MicroPython) to the server
Post images from Python to Tumblr
Send log data from the server to Splunk Cloud
How to post a ticket from the Shogun API
Post from Python to Slack
[Part 4] Use Deep Learning to forecast the weather from weather images
[Part 1] Use Deep Learning to forecast the weather from weather images
[Part 3] Use Deep Learning to forecast the weather from weather images
[Postgresql] SSH connection to the external DB server from the client
[Part 2] Use Deep Learning to forecast the weather from weather images
Post from python to facebook timeline
[Lambda] [Python] Post to Twitter from Lambda!
Terminal association from the server side to Amazon SNS (python + boto3)
How to set the server time to Japanese time
Push notification from Python server to Android
Try using the Python web framework Django (1)-From installation to server startup
How to operate Linux from the console
How to access the Datastore from the outside
[python] Send the image captured from the webcam to the server and save it
SSH login to the target server from Windows with a click of a shortcut
Send a message from Slack to a Python server
Log in to the remote server with SSH
Change the decimal point of logging from, to.
How to operate Linux from the outside Procedure
How to measure line speed from the terminal
Download the VGG Face2 dataset directly to the server
[Python] I will upload the FTP to the FTP server.
From the introduction of pyethapp to the execution of contract
Learn how to inflate images from TensorFlow code
The story of moving from Pipenv to Poetry
The guy who gets fitbit data from the server
Extract images and tables from pdf with python to reduce the burden of reporting
The best tool to protect your privacy from your photos ...!
I want to see the file name from DataLoader
Images created with matplotlib shift from dvi to pdf
[Python] How to remove duplicate values from the list
How to create an article from the command line
The wall of changing the Django service from Python 2.7 to Python 3
POST messages from python to Slack via incoming webhook
I want to detect images of cats from Instagram
I tried to detect the iris from the camera image
Clear the cron.log regularly to prevent it from growing.
Try setting NETCONF (ncclient) from software to the router
I wanted to use the Python library from MATLAB
The one that graphs the one that got the fitbit data from the server
How to instantly launch Jupyter Notebook from the terminal
The first step to getting Blender available from Python
Post to your account using the API on Twitter
Coloring points according to the distance from the regression curve
Let's add it to the environment variable from the command ~
I read the Chainer reference (updated from time to time)
ODBC access to SQL Server from Linux with Python
Send a message from the server to your Chrome extension using Google Cloud Messaging for Chrome
A Python script that allows you to check the status of the server from your browser
I tried to find the trend of the number of ships in Tokyo Bay from satellite images.