Using Lua to take a photo and editing the meta data

Hello,

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?

Thanks.
P

Hi @aeroptl

The HTTP method (request) for this is put

There’s a recent discussion about meta property updates here →
Iterating over variables to associate plants with soil moisture readings - Software / Sequences - FarmBot Forum

Hello,

I tried this but it doesn’t work.

This is what I have in Lua:

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.

Hi @aeroptl

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.

image_id = 473386
url = "/api/images/" .. tostring(image_id),

Sorry for the confusion.

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.

@aeroptl a couple of ways to go :slight_smile:

  • 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.

  • The FBOS image uploader code creates the standard meta contents. If you are happy to build custom FBOS you could edit farmbot_os/lib/ext/api/image_uploader.ex at staging · FarmBot/farmbot_os · GitHub ?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.