I’m looking to use Lua code to take a photo (which is already shown in the documentation). But this time, I need to edit the meta data associated with it. Looking at the MQTT broker, the image metadata is usually x,y,z and name, but I need to add in a tag so I can extract the image separately. I’m aware I’ll have to make a HTTP Post request but I’m not sure how it would work in Lua.
Has anyone managed to do something like this before?
result = api({
method = "put",
-- Don't forget the leading "/":
url = "/api/images/",
-- `body` is optional for GET requests.
body = {
meta = {
test = "test"
}
}
})
The result is a HTTP error status 404. The developer documentation description of this call says it should create a new image.
I assumed that you were going to capture and store an image using Lua take_photo() and then add the meta key-value pair for that image in a separate additional api() call.
To make that Lua code (above) work for an existing image you need to append the image id to your url.
e.g.
The only problem I forsee is that take_photo() does not give you the image_id, thus it would be difficult for me to add the meta key-value pair for that image.
My ideal situation is that using the MQTT broker (listening to the logs), I should see the attachment URL link along with the meta data with the information I wanted to put in one message.
Use api() to GET all images filtered by whichever attribute(s) make sense and then call api() to put new meta using ids in the filtered set and then possibly add send_message() to make sure the stuff you need is in a Log record.