-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Send image over http request #48
Comments
Hi, yes, each call to That example simply crafts a UDP packet for each 128-byte chunk and sends it off to some server, which will . It's not the most practical example, since in real usage, you'd probably want to send some sort of "packet header" to the server first, to tell it that you're about to send it an image, so that it gets ready to parse, assemble and store the image from the chunks. That's actually what you'll be doing here with a POST. The image data is binary (not text) data, which should go in your POST request's body, and your POST headers should inform your server -- mainly by means of the URI and Content-Type -- exactly what data is contained in the body, and how to interpret/use/store it, as applicable. So, to POST this binary data, you'll likely need to use the This page seems to explain the HTTP Multipart pretty well, especially with its linked pages/references. |
You can also see an example of Arduino HTTP Multipart here, sending a file: https://github.com/nailujx86/ESP8266_multipart/blob/master/ESP8266_multipart.cpp. (Slightly buggy since it seems it calculates the Content-Length incorrectly, and is missing a few CRLFs) |
So, something along the very-rough lines of:
|
I'll be closing this, if this answers your questions. Maybe I'll update the example at some point, to send the image over HTTP, rather than just raw UDP datagrams. |
Hi, sorry for the late response, I couldn't use the code because arduino uno didn't had enough memory, I purchased a mega 2560 and now I have enough hardware. I managed to test the code today, but I am getting two errors, sometimes it returns
I don't know why but the errors can change between the tests, also, thanks for the help before. |
Ah, that's probably happening because your HTTP client isn't pushing the data out quickly enough. You end up losing image data from the sensor, as the UART buffer gets filled and the UART driver starts discarding data. I'd forgotten about this old factor. To confirm that's the problem:
Once you've confirmed this, we'll then have to think of a way to optimize the data flow from UART -> HTTP such that data is never lost. Perhaps the (It may be in the end that streaming each image chunk will not be feasible in real-time -- in which case, you may have to get a device with oodles of RAM, at least 48 K (like some STM32 or ESPxxxx) in order to be able to hold the entire image (37 kB) in RAM before sending it off at leisure over HTTP.) |
Maybe we could do like on the image_to_pc sketch and pass the data through serial to the http? |
Perhaps the malformed http request it's because the server await something like "message=I am a text message" and the code only sends the imagem, maybe if I do a |
Do you think that an ESP32 would be better for solving this? |
Okay, that's good to know. I've modified the example a bit here, to frame the HTTP request more correctly: https://gist.github.com/brianrho/e95c893de4fd980ec610ca60b5de013f Integrate this into your sketch and see if things improve. (When testing, get a dump from your server end, of the request headers it received from the client, so we can inspect the structure if it's still malformed.) If you still don't get the complete image with this, then we'll look into streaming directly from UART -> HTTP, if that will help. |
Generally, it would make things easier for you since you can read the entire image into RAM, before sending it to the server at any rate you like, no pressure. You don't need to get an ESP32 specifically, even some STM32 or similar with loads of RAM should suffice. But if you want, you can leave that till you've exhausted all other options. |
It's almost working, the code you sent me worked, but there's two problems:
I tried to change the ´char fileName[] = "finger.bmpp"´ to ´char fileName[] = "finger.bmp"´, but didn't worked, still receiving the bin file. |
So after fixing your wiring issues, are you able to reliably receive all 36864 bytes of the image every time, without HTTP errors? If not everytime, what's the % rate of failures? Do these failures happen only with this image_http sketch or do they happen when you POST other stuff as well? Also, how long does it take roughly to POST the entire image to the server? Any idea why the server disconnects in the middle and how often this happens? |
So the file type is "correct",
![]() (Though typically, pixels that are that close to each other will have very similar colours and thus similar high-nibbles. So, more likely, the 2 pixel colours above should've been 0xAB and 0xAD.) Quoting the poorly-translated ZFM20 datasheet:
This means you actually receive 73728 / 2 = 36864 bytes from the sensor -- as you've observed. It also means that before you can view the image, you need to do a bit of processing on the 36 kB raster your server received -- mainly to prepend a BMP header to it and to fill out the missing pixels. That's what you'll see happening in this Python script, which you used to stream the image to your PC over Serial: https://github.com/brianrho/FPM/blob/master/extras/GetImage/getImage.py. If you want to view the image on your server, you'll need to do similar processing. You can try your hand at porting the relevant parts of that script, using whatever programming language your server's using. |
After fixing the wiring issues, I could send the image through the POST every time, like a 100% rate or something like 95-99%, I don't remember having any issues. I already had this problem before when posting a text, the server disconnects and I don't know why, I think that's probably the wires because when I remove and plug then again, it works for like 20-30 minutes. When the wire is with malfunction, it's rather common to receive a error while trying to do the
it's about 7-8 seconds and it's constantly. |
I will be trying to understand better the Python script and port it to my php server. Thanks for explaining me how to do the code and post the data, seriously, I couldn't do anything if it weren't for your help. I think I undestood what I need to do with your explanation right now. |
It worked!!! Thank you very much! I adapted your python code to receive the bin file generated by the sensor, read each byte and then generate the image, so basically, I just call the script in php, pass the file name that should be created and the path to the bin file. If you ever want to add a image_to_http example, here is the arduino code, feel free to modify it:
The Python code I basically just changed the
Again, thank you so much, without you I wasn't going to be able to do this. |
Sure, glad to see you were able to port it easily :-) I should mention I made a tiny commit yesterday, to adjust the way the pixel colours get extrapolated to file: 9dea674 It's something I should've fixed since, though it's not a big deal really, since you still get a useful image regardless. As you can see from the commit, your code should basically be doing this instead:
Otherwise, good luck! |
Already updated the code, thanks! |
Hi, I found out the FPM library two weeks ago, I used it to store fingerprints on my pc using the python example, after that I used some C# code to compare the generated images and it worked. But I need to send the image to my web server that is in laravel (php framework) and has a path just for the image upload, I can upload the file using a web form, but I don't figured out how I can create a post request using the Arduino with the fingerprint image, I am using the ENC28J60 module, so I can do post requests using UIPEthernet library
The following code is used to do a post request with a text message:
If I understood correctly, the image_to_udp example has the function readRaw and the buffer variable is where the image is stored, but how can I send it over the post request?
Thanks for the help!
The text was updated successfully, but these errors were encountered: