Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

Posting external data using curl to QuickApp method


Question

Posted

Hello,

 

Can anybody advice how to post using external curl data (json table) to custom QuickApp method defined n QuickApp device?

 

I've created device having custom method that is going to be triggered from outside by external system.

 

For test purposes created method shows posted data:

 

function QuickApp:updatecrazy(sentdata)
 
    self:debug("updatecrazy Invoked")
    self.debug("sentdata: "..sentdata) 
    self.debug("tostring(sentdata): "..tostring(sentdata)")
 
end
 
Trying to POST data from outside function is triggered but data is nil, regardless of posted data json (with "args" or without).
 
Examples of curl and debug output:
 
#1

curl -X POST "https://FIBARO_HC3_ADDRESS/api/devices/489/action/updatecrazy" -H  "accept: */*" -H  "Content-Type: application/json" -H  "X-Fibaro-Version: 2" -H  "Accept-language: en" -H  "Authorization: Basic  password==" -d "{\"args\":[\"{arg1_ss:1}\",\"{arg2_ss:1}\"],\"delay\":0}" -k

[23.04.2021] [17:13:42] [DEBUG] [QUICKAPP489]: onAction: {"args":["{arg1_ss:1}","{arg2_ss:1}"],"actionName":"updatecrazy","deviceId":489}
[23.04.2021] [17:13:42] [DEBUG] [QUICKAPP489]: updatecrazy Invoked
[23.04.2021] [17:13:42] [DEBUG] [QUICKAPP489]: nil
[23.04.2021] [17:13:42] [DEBUG] [QUICKAPP489]: nil


#2

curl -X POST "https://FIBARO_HC3_ADDRESS/api/devices/489/action/updatecrazy" -H  "accept: */*" -H  "Content-Type: application/json" -H  "X-Fibaro-Version: 2" -H  "Accept-language: en" -H  "Authorization: Basic  password==" -d "{\"args\":[\"{sentdata:1}\"],\"delay\":0}" -k

[23.04.2021] [17:17:07] [DEBUG] [QUICKAPP489]: onAction: {"actionName":"updatecrazy","args":["{sentdata:1}"],"deviceId":489}
[23.04.2021] [17:17:07] [DEBUG] [QUICKAPP489]: updatecrazy Invoked
[23.04.2021] [17:17:07] [DEBUG] [QUICKAPP489]: nil
[23.04.2021] [17:17:07] [DEBUG] [QUICKAPP489]: nil


#3

curl -X POST "https://FIBARO_HC3_ADDRESS/api/devices/489/action/updatecrazy" -H  "accept: */*" -H  "Content-Type: application/json" -H  "X-Fibaro-Version: 2" -H  "Accept-language: en" -H  "Authorization: Basic  password==" -d "{\"sensor1\":0,\"sensor2\":0,\"sensor3\":0,\"sensor4\":0}" -k

[23.04.2021] [17:19:19] [DEBUG] [QUICKAPP489]: onAction: {"actionName":"updatecrazy","args":[],"deviceId":489}
[23.04.2021] [17:19:19] [DEBUG] [QUICKAPP489]: updatecrazy Invoked
[23.04.2021] [17:19:19] [DEBUG] [QUICKAPP489]: nil
[23.04.2021] [17:19:19] [DEBUG] [QUICKAPP489]: nil


#4

curl -X POST "https://FIBARO_HC3_ADDRESS/api/devices/489/action/updatecrazy" -H  "accept: */*" -H  "Content-Type: application/json" -H  "X-Fibaro-Version: 2" -H  "Accept-language: en" -H  "Authorization: Basic  password==" -d "{\"args\":[{\"sensor1\":0,\"sensor2\":0,\"sensor3\":0,\"sensor4\":0}]}" -k

[23.04.2021] [17:21:25] [DEBUG] [QUICKAPP489]: onAction: {"actionName":"updatecrazy","args":[{"sensor4":0,"sensor2":0,"sensor1":0,"sensor3":0}],"deviceId":489}
[23.04.2021] [17:21:25] [DEBUG] [QUICKAPP489]: updatecrazy Invoked
[23.04.2021] [17:21:25] [DEBUG] [QUICKAPP489]: nil
[23.04.2021] [17:21:25] [DEBUG] [QUICKAPP489]: nil

 

#5

curl -X POST "https://FIBARO_HC3_ADDRESS/api/devices/489/action/updatecrazy" -H  "accept: */*" -H  "Content-Type: application/json" -H  "X-Fibaro-Version: 2" -H  "Accept-language: en" -H  "Authorization: Basic  password==" -d "{\"sentdata\":[{\"sensor1\":0,\"sensor2\":0,\"sensor3\":0,\"sensor4\":0}]}" -k

[23.04.2021] [17:22:59] [DEBUG] [QUICKAPP489]: onAction: {"actionName":"updatecrazy","args":[],"deviceId":489}
[23.04.2021] [17:22:59] [DEBUG] [QUICKAPP489]: updatecrazy Invoked
[23.04.2021] [17:22:59] [DEBUG] [QUICKAPP489]: nil
[23.04.2021] [17:22:59] [DEBUG] [QUICKAPP489]: nil

 
 
It seems trigger onAction gets data only when it is posted in format having "args" like e.g.:
{
"args":
[{"sensor1":0,"sensor2":0,"sensor3":0,"sensor4":0}]
}
 
but sentdata variable is nill.
 
Should I post something different using curl or should I read another data (not sentdata variable) in order to access posted values?
 
Any help would be appreciated,
Regards
Mike

1 answer to this question

Recommended Posts

  • 0
  • Inquirer
  • Posted

    Sorry all. My fault.

     

    self.debug instead of self:debug did the mess with my testing.

     

    For any who will have to manage posting do QuickApp from external sources - variable(s) value(s) shall be posted as an "args" json table, e.g.:

     

    {
    "args": [
          {"sensor1":0,"sensor2":0,"sensor3":0,"sensor4":0}
       ]
    }
     
    or
     
    {
    "args": [
          {"sensor1":0,"sensor2":0,"sensor3":0,"sensor4":0}
       ],
       "delay": 0
    }

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...