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

Cannot get JSON Response - [ERROR] Operation canceled


Question

Posted

Hello!

I am trying to communicate with a sonoff mini DYI mode from my HC3. I was able to turn on the switch on the sonoff but I cannot get a response to know if the command was completed successfully. Instead I get the following: [ERROR] Operation canceled

The code that I used in my QA is:

 

function QuickApp:buttonOn()
    local http = net.HTTPClient()
    http:request("http://192.168.0.216:8081/zeroconf/switch", {
        options = { method = 'POST', headers = {Accept = "application/json"}, data = '{"deviceid": "", "data": {"switch": "on"}}', timeout = 3000 },
           success = function(status)
        if status.status ~= 200 and status.status ~= 201 then print("failed"); end
           print(status.data);
            end,
         error = function(err)
           print('[ERROR] ' .. err)
         end
      })
end
 
Could anyone help me with this issue to understand what I am doing wrong? 
Thank you

Recommended Posts

  • 0
Posted

99% IP address with such port is not accessible for HC3 

  • Thanks 1
  • 0
  • Inquirer
  • Posted

    10der Thank you for your answer. The IP is SonOff's IP address in my LAN and the port is the sonoff's default communicate port. The SonOff reacts on my POST command and "turns on" but the response I get is: [ERROR] Operation canceled. 

    I believe  that the timeout expires without  the HC3 can read the comfirm respond of the sonoff that the switch is at "On State".

    I want to get this switch status confirmation of the SonOff .

    • 0
    Posted

    @Prokopis Bor

    Try increasing the timeout to a larger value (for example 6000ms)

    • Thanks 2
    • 0
    Posted

    @Prokopis Bor sorry.

    both my QA' works like a chatm

    Please login or register to see this attachment.

     

    double

     

    Please login or register to see this attachment.

     

    2 minutes ago, Martin_N said:

    Try increasing the timeout to a larger value (for example 6000ms)

    btw! yes!

    • Thanks 1
    • 0
  • Inquirer
  • Posted
    51 minutes ago, Martin_N said:

    @Prokopis Bor

    Try increasing the timeout to a larger value (for example 6000ms)

    I have already done that. Unfortunately this is not the issue.

    51 minutes ago, 10der said:

    @Prokopis Bor sorry.

    both my QA' works like a chatm

    Please login or register to see this attachment.

     

    double

     

    Please login or register to see this attachment.

     

    btw! yes!

     

     

    Thank you for your QA's ! As I understand you have flashed the sonoff with Tasmota firmware. My sonoff is not flashed with tasmota. I use it in DIY mode with sonoff RESTAPI (it is sonoff Mini). 

    • 0
    Posted

    Hmm sonoff now can work without clouds? wow.

    • 0
  • Inquirer
  • Posted (edited)

    Yes some specific models only! 

    (

    Please login or register to see this link.

    )

     

    If I use postman I get the answer:  {"seq":23,"error":0}

    How can I read this with HC3?

    Edited by Prokopis Bor
    • 0
    Posted (edited)

    @Prokopis Bor

    If it works for you at least from a PC, give a return message here. See picture.

    Please login or register to see this spoiler.

     

    EDIT:

    heh ... you were faster.
    I don't see signalStrength information in your post

    Edited by Martin_N
    • Thanks 1
    • 0
  • Inquirer
  • Posted (edited)
    11 minutes ago, Martin_N said:

    @Prokopis Bor

    If it works for you at least from a PC, give a return message here. See picture.

    Please login or register to see this spoiler.

     

    Yes it works from a PC and also from my Fibaro Quick App. The SonOff change state to On but I want to read the comfirmation answer.

    If I use postman I get the answer:  {"seq":23,"error":0}

    How can I read this with HC3 QA? 

    I want to read the  {"error":0} value so HC3 will know that the command has been executed successfully.

    Edited by Prokopis Bor
    • 0
    Posted

    Hello,

    I have exactely the same trouble with a Dingz module.

    If i make a api request from a scene it works perfectly but from a QA i alwas get the message "Operation canceled".

    Post request works from my QA. ist it the same for you?

    did you find a solution to your problem?

    • 0
  • Inquirer
  • Posted

    I will try to make the request from a scene and I will let you know. From the QA I have the same issue as you. I did not find any solution yet. Thanks!

    • 0
  • Inquirer
  • Posted

    @

    Please login or register to see this link.

     yes we have got exactly the same issue. After I saw your answer I created a similar scene and when I ran it I got the "200" status answer and {error:0} too. You have helped me a lot with your answer. I haven't found any solution yet. If you have found a solution please let me know! Thanks a lot!

    • 0
    Posted

    Hi, no sorry i didn't found anything. I think it is a bug on the HC3.

    I will tell you if i find anything.

    • 0
    Posted
    1 hour ago, idomotique said:

    Hi, no sorry i didn't found anything. I think it is a bug on the HC3.

    I will tell you if i find anything.

    I don't have a sonoff device but I stumbled upon another service where the POST would give "operation cancelled" in a QA on the HC3 (and I had similar code worked on the HC2). My solution was to add the header

    ['Connection']='keep-alive'

    ...and it suddenly started to work. Seemed like the HC3 QA closed the connection too fast for the server to read the payload...(?)

    You can give it a try and see if it solves your problem...

    • Thanks 1
    • 0
    Posted

    Thanks @jgab.

    Do you have an example of your request?

    i will try that

     

    • 0
    Posted (edited)

    Please login or register to see this code.

     

     
    ...header added to the example in the first post
    Edited by jgab
    • 0
    Posted

    hum it doesn't seems to work for me. Did you try with a get request too?

    The post request worked for me but not the get.

    • 0
    Posted
    1 minute ago, idomotique said:

    hum it doesn't seems to work for me. Did you try with a get request too?

    The post request worked for me but not the get.

    did you try also add timeout?

     

    Please login or register to see this code.

    • 0
    Posted

    Yep,

    that is my function

    Please login or register to see this code.

     

    • 0
    Posted
    1 minute ago, idomotique said:

    Yep,

    that is my function

    Please login or register to see this code.

     

    and if you add

    ['Content-Type']='application/json'

    to the header?

    • Thanks 1

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