Triggering rule through the HTTP request



  • I need to trigger certain MyController rule by pressing bluetooth button.
    I plan to use bluetooth daemon on RPi that will handle button press and will send MyController HTTP request.
    Could someone explain how to craft HTTP request params?



  • Where could I lookup REST API samples or docs?


  • ADMIN

    @benya For now there is no doc for REST API. You have to refer source code.



  • @jkandasa said:

    @benya For now there is no doc for REST API. You have to refer source code.

    Are there any samples?
    I need to pass credentials and trigger some operation.

    Besides REST API, MyController supports any other IPC?
    May I trigger operation from external app or shell script on the same host?



  • Looks like I could replace client that pushes data through REST API with a rule that uses condition script.
    Condition script could read external file and return true/false accordingly.

    How often MyController executes condition script (linked to the rule)? Every 5sec?


  • ADMIN

    @benya

    Looks like I could replace client that pushes data through REST API with a rule that uses condition script.
    Condition script could read external file and return true/false accordingly.

    You can use operation to execute the script and configure your operation on timer/cron.

    How often MyController executes condition script (linked to the rule)? Every 5sec?

    Yes, Condition scripts executes 5 seconds once.



  • Here is a sample REST API call that modifies MyController repository variable:

    curl -X PUT -H "Content-Type: application/json" -d '{"key":"Var1","value":"222"}' "http://demo:demo@demo.mycontroller.org/mc/rest/variables"


  • Looks like dummy sensor variable triggers rule much faster than repository variable.
    How could I change sensor variable (referring by UID tag) through REST API?
    Could you post sample HTTP payload?



  • I figured how to set dummy sensor by script called through REST API.

    I created "Set DummySensor" groovy script:

    def uid = "DummySensor"
    def value = "1"
    def sensor = mcApi.uidTag().getByUid(uid).getResource()
    sensor.setValue(value)
    mcApi.sensor().sendPayload(sensor);
    

    and call it through the REST API:

    curl "http://admin:admin@localhost:9880/mc/rest/scripts/runNow?bindings=%7B+%7D&script=operations%2FSet+DummySensor.groovy&scriptBindings=%7B%7D"
    

    I defined rule that gets triggered when dummy sensor value changes.
    No 5 sec delays anymore. Cool!


Log in to reply
 

7
Online

439
Users

231
Topics

1378
Posts

Looks like your connection to MYCONTROLLER.ORG was lost, please wait while we try to reconnect.