how to send image to server by post to http?

I am so sorry to send this message to you.I want to ask for some advice.
I am working on a project related to gesture recognition. Currently, there are OpenMV3 and WIFI extensions. I want to capture images through OpenMV CAM, convert the images to binary data or base64 encoding, use wifi to access the server, and access the server through the browser. The stream post is sent to the server and the server returns the result. There are two problems here: The first one is how to get a frame of image obtained in sensor.snapshot() into binary data or base64 encoded data? The second problem is that the request format required by the server API is the POST request http method, and the OpenMV3 has no related requests module or urllib module. How to set the POST entity header in the OpenMV3?
This is the server API request:
1.HTTP method:POST
url : … 5-15254242
2.Content-Type application/x-www-form-urlencoded
3.Header:Content-Type application/x-www-form-urlencoded
4.Body:image: base64 string

Thank you very much!
Looking forward to your reply!

Hi, use this to encode:

And call .compress() on the image to get a jpeg byte stream.


base63_data = ubinascii.b2a_base64(img.compress(quality=90))

Then transmit that data.

thanks so much. :smiley:
Do you know how to post to http in the openmv ?just follow the request which i to set the header about client.send()?
And,How to parse url?Is there a function in OpenMV just like Python function-urlopen() to parse urls?

Ibrahim will have to answer this. The WiFi part I’m not strong with.

I can’t find him in the Members.Can you help me to invite him to see this question?
best wishes

You just send it with socket.send(). This is not a high level library, it’s just plain sockets. See the MJPEG example.

Hi,the MJPEG example is based on http,but my server address is based on https.
when i use the function:usocket.getaddrinfo(),it can’t parse url correctly,there was an error in the OpenMV IDE,Oserror -1.
My URL is … 5-15254242
I thought it just related to Https ssl encryption. Can this socket module solve it? I just want to realize that send an image to my specified https server via wifi or lan.
Do you have any other ideas for my purpose?

The socket module doesn’t support SSL.

Thanks.By the way,Is the ATwinC1500 hardware itself not supported SSL or just does not transplant the relevant ssl code in OpenMV3?

No the hardware supports it, but currently there’s no way to download certificates to the module flash.

Sorry to resurrect an old post.

Given the wifi shield uses the same atwinc1500 chip as both the Adafruit feather M0 and their standalone winc1500, couldn’t this same concept here:

be used to flash the SSL certificates? or have there been sufficient modifications to the winc1500 firmware that would prevent this?

You could try to update the certificates with that (all the pins are broken out, including the debugging uart), but you should Not update the firmware because it needs to match the host driver (the driver OpenMV uses), otherwise it won’t work with OpenMV after a firmware update.

I’ll work on a way to update the certificates, but this may take some time.

Hi, just an update on this, we now support SSL with mod ussl (mbedtls) it’s available in the latest beta release with mbedtls, additionally the WINC1500 host driver and firmware have been updated to the latest (v19.3.0/v19.6.1). I’m not sure if there’s a way to add certificates, but the client seems to not validate them anyway… Note if you want to use the the new release it requires a WINC1500 firmware update (included with the release).

I’m trying to send images coninuously to a php by http POST and after two times, three four the camera reboot or disconnect. Not all the time in the same line nor in the same snapshot. I have tried many things. Here is the last code attached.
Could be a memory issue that I have to manage? It is a problem of the Openmv H7 that might be solved in the Plus version or it is the Wifi Shield or maybe the code? (2.96 KB)

I can’t say for sure without testing the code, and I can’t test this code because I need a server to post the images. However, I noticed that there’s a commented print line in the IRQ callback, you can’t call any functions that allocate memory (including print statements) in an IRQ callback. Also, you use ping inside the callback it must be global…

def callback(line):
    global ping

Hi, we will have a rather robust demo for how to do good TCP/UDP connections soon in our upcoming RPC library.

Alright, thanks, I understand, but it was added at the end. I was trying the post code for a few days without the callback. I tried also many other options. Also trying to send with PUT instead POST.
The server and php is working right now for testing. You can use it. It is only for development. You only need to change the SSID and Pass in the py code.
I will try with the PUS version of the camera that we also bought and maybe we might try with a multipart POST method. I’m not sure but the last wifi shield is blue, not red that we also bought some month ago.
We are testing the camera for a wildlife conservation project (biodiversity monitoring). If we succedd we will buy 20-40 units in the first deployment and then 1000 units to cover the whole Amazon Rainforest.

This will be great! Do you have an expected release date?

Next week. I’m finishing up the library right now. I just got TCP and UDP raw image transfer from one OpenMV Cam to another working. Wifi can nominally move between 1 to 2 Mbps. I am writing a script for the computer now and I’ll have the ability to transfer images wirelessly to a desktop working soon.

Note, the library shows off a custom protocol I designed called RPC which let’s you remote call a method on the OpenMV Cam. You are allowed to pass an arbitrary length bytearray to the procedure that can contain anything… and it will be delivered to that method on the OpenMV Cam. That method can then respond with an arbitrary length bytearray which will be delivered back to the caller. Both the argument bytearray and response can be variable length per call response.

Anyway, the code however shows off how to use sockets in a really robust way so if you don’t like the protocol you can just lift code from it.

Finally, you can also just implement the protocol over another transport layer like http. However, it will work for raw sockets right out the box.

I was working on a similar project using raspberry pi. What I did was use ffmpeg to pipe an image stream over UDP to a netcat listener on a server. You can stream and save these UDP streams once they get to your server. Here was my example for the Pi, you could replace ffmpeg with usocket on the OpenMV cam.

This is how I did it on the PI,

ffmpeg -f v4l2 -video_size 1280x720 -re -i "0:0" -f mpegts -b:v 3M udp://YOURPUBLICIP:5555

On the Server

nc -l -p 5555 | mplayer - -benchmark

This example will just open up a live stream on your host server. If you want to say and stream you could do something like this:

 nc -l -p 555 | tee  file_containing_the_video.mp4 | mplayer - -benchmark

You can get creative on the server end to make it more robust.