Trying to change crop settings on the fly

  • I'm trying to change the crop settings on the fly using the API. I tried this:


    #!/usr/bin/python3

    import json

    import requests

    s = requests.Session()


    #Get Config

    json_query = '{"command":"config", "subcommand":"getconfig"}'

    response = requests.post("http://127.0.0.1:8090/json-rpc", data=json_query)

    config = response.json()


    # Modify the values directly in the config dictionary

    config['info']['grabberV4L2']['cropTop'] = 20

    config['info']['grabberV4L2']['cropBottom'] = 20


    json_modify = {

    "command": "config",

    "subcommand": "setconfig",

    "config": config

    }


    response = requests.post("http://127.0.0.1:8090/json-rpc", json=json_modify)

    print(response.json())

    When I run it, it gives a successful response, but the configuration breaks. I actually lose the grabber device. Did anyone accomplish something like this?

    Can anyone help me?

  • No I'm running 2.0.16. But is the method I'm using correct? Do I have to send all values or can I just only send the crop settings?

    • New
    • Official Post

    It might not properly work in 2.0.16 anyway...


    Besides that your script is also producing a wrong configuration.

    config = response.json()

    includes the whole response, but you would need only the object provided by info.

    In addition, you should check, if the response indicates a successful execution of the request before doing a setconfig


    Otherwise you might see "strange" behaviours...


    2.0.17-beta should be more advanced and it is more clear on errors.


    In addition, you can now just get and manipulate the v42l grabber config only without updating the whole configuration.

  • OK I will try to test the beta and adapt. But regarding your last remark. I would like to only change the VL42l grabber part, but do I still need to send all fields? Or can I also only send the crop values?

    • New
    • Official Post

    With digital grabbers you don't need crop settings, so I'm interested in why you want to change that even on the fly.


    regards pclin

    • New
    • Official Post

    sioux Those should be the commands.

    Note: You MUST use an authentication (aka bearer) token for Admin commands.


    {

    "command": "config",

    "subcommand": "getconfig",

    "configFilter" : {

    "global" : {

    "types" : [ "grabberV4L2" ]

    },

    "instances" : {

    "types" : [ "" ]

    }

    }

    }


    {

    "command": "config",

    "subcommand": "setconfig",

    "config" :

    {

    "global": {

    "settings": {

    "grabberV4L2": your updated config

    }

    }

    }

    }

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!