epfl-cs358 / 2024sp-helping-hand

2 stars 0 forks source link

Integrate the vision server communication protocol and the camera capture to application #39

Closed gruvw closed 1 month ago

gruvw commented 2 months ago

Implement the automatic configuration protocol in the Flutter application.

gruvw commented 1 month ago

I have tested this locally with a simple flask server and was successfully able to go through the full automatic configuration process using the app.

The image is sent through the internet using a POST request to the /analyse endpoint of the CV server, the image is in the request's body and base64 encoded.

Basic Flask code snippet to get the base64 image:

@app.route("/analyse", methods=["POST"])
def analyse():
    print(request.data)
    ...

One can paste the data to retrieve the actual picture in any common conversion tool (like https://onlinejpgtools.com/convert-base64-to-jpg that I used during my tests).

To retrieve the bytes data of the image, we can simply decode the base64 as follows:

import base64

...
base64.b64decode(request.data)

Response

Also note (for the record) that for the flask response to be accepted by the app, one has to set up the response headers as follows:

response = make_response("PLO,fake:mac:addr")  // example response
response.headers.add("Access-Control-Allow-Origin", "*")
response.headers.add("Access-Control-Allow-Credentials", "true")
response.headers.add("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
response.headers.add("Access-Control-Max-Age", "1000")
response.headers.add("Access-Control-Allow-Headers", "Origin,Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,locale")
return response
gruvw commented 1 month ago

As per the description of the two backlinks above, I already implemented this new base64 encoding on the server.

gruvw commented 1 month ago

I did a final integration test using the real CVserver from #45 and the new version of the app that uses the server analyse protocol. I found a bug while doing it. Fixed the bug. Now it is working (tested) end-to-end with real app and real server.