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
parper

Modify global variable using REST API with HTTP.PUT

Question

Hello,

I'm trying to modify a already define global variable using the REST API for the HC2.

This is done from a ESP2866 (nodeMCU-isch) board.

 

I can do a http.get towards the HC" and I get the correct JSON information.

When I do http.put I seem not to be able to set the variable.

My message headers contains a basic auth, and I have payload that looks like this

{"value":"On"}

The address looks like this http://1.2.3.4/api/globalVariables/thevariable

 

According to the httpclient i'm using i seem to get return code 200 but no result and the variable is not changed.

 

Using the hc2ip/docs link I can test this out with the correct payload and it works fine.

However I'm logged in as an Admin then.

Trying to change the user from my ESP2866 I just got that the HC" banned me for 30 min.

 

So is there a problem using normal users when trying to modify a global variable ? Do I need to be admin ?

Or is there something else I need to check ?

 

Regards P

Share this post


Link to post
Share on other sites

15 answers to this question

Recommended Posts

  • 0

Hi @parper,

 

You probably missing Content-Lenght property.

 

Please, check my testing VD

Please login or register to see this link.

. I believe it helps.

 

 

Share this post


Link to post
Share on other sites
  • 0
  • Inquirer
  • Hello, 

    I have checked that and that is not the problem, length variable that is.

    How ever I can see that normal users in Fibaro HC2 only has read access to the global variables.

    This is probably the cause of this.

     

    I do not want to login with my admin account so how do I give access to the global variables from a normal user ?

    Anyone know ?

    Share this post


    Link to post
    Share on other sites
    • 0
  • Inquirer
  • Ok I got the solution:

     

    Since 4.530 of HC2(can't tell if this is the case on earlier versions).

    1. To read global variables you can use any of the registered HC2 users.

    2. To write you need to be administrator. I needed to use my whole email to the super user and password. Then I could set the global variables.

           123@123.com/password when generating the basic auth secret.

     

    So this is a working pseudo code package structure:

     

    PUT /api/globalVariables/myvar HTTP/1.1
    Authorization: Basic thiscontainsthehashedsecretstring
    Content-Length: 14(is calculated depending on the payload)
    Host: 192.168.xx.xx:80
    Content-Type: application/json

    {"value":"tothevalueyouwant"}

    Share this post


    Link to post
    Share on other sites
    • 0

    Hi Parper,

     

    Good to see you have solved this. I'm still struggeling a bit to get my lolin32 sending variable values to my HC2.

    Do you sent the Username/Password in the URL? If you add it before the IP like HTTP:123@123.com:password@HC2IP:80/api/globalVariables/yourvariable it doesn't seem to work with the email adress.

     

    Or do you add the authentication in the header? Can you share an example?

     

    Thanks,

     

    Erik

    Share this post


    Link to post
    Share on other sites
    • 0
    Posted (edited)

    Thanks for the reply. Can you please share an example.

    This is what I have now in my arduino sketch: 

     

    http.addHeader(" {\"Content-Type\" : \"application/json\"",
                   " \"login\": \"admin username\"",
                   "\"password\": \"admin password\"}");

     

    This results in a 401 response code....

    Edited by EK

    Share this post


    Link to post
    Share on other sites
    • 0

    @EK

    Please login or register to see this code.

     

    Share this post


    Link to post
    Share on other sites
    • 0

    Thanks for the code. I had all but

    Please login or register to see this code.

    But when I insert it (with the right credentials of course) it returns an error:


    HTTP_Put_temp_and_hum:71:1: error: stray '\357' in program
     http.setAuthorization("Bill.Gates@gmail.com", "Micro$oft");
     ^

     

    Without this line, I get no errors in the script. any thoughts? Am I using the wrong library?

    (now using #include <WEMOS_SHT3X.h>
    SHT3X sht30(0x45);
    #include <Arduino.h>
    #include <WiFi.h>
    #include <WiFiMulti.h>
    #include <HTTPClient.h>)

     

    Share this post


    Link to post
    Share on other sites
    • 0
    Posted (edited)

    #include "ESP8266WiFi.h"
    #include <ESP8266HTTPClient.h>
    #include <ESP8266mDNS.h>
     

    Edited by 10der

    Share this post


    Link to post
    Share on other sites
    • 0
    Posted (edited)
    On 6/8/2019 at 8:49 PM, 10der said:

    @EK

    Please login or register to see this code.

     

     

    Hi @10der

     

    Thanks for sharing the above

    What does the 'param' represent in the function call above

     

    I want to start scene  269  so I use 

    doCall(269) but not sure what else to pass in the function call

     

    I tried leaving it blank but it wouldn't compile

    full sketch attached

     

     

     

     

    Please login or register to see this attachment.

    Edited by AutoFrank

    Share this post


    Link to post
    Share on other sites
    • 0
    51 minutes ago, AutoFrank said:

     

    Hi @10der

     

    Thanks for sharing the above

    What does the 'param' represent in the function call above

     

    I want to start scene  269  so I use 

    doCall(269) but not sure what else to pass in the function call

     

    I tried leaving it blank but it wouldn't compile

    full sketch attached

     

     

     

     

    Please login or register to see this attachment.

     

    All sorted  - thanks 

    Share this post


    Link to post
    Share on other sites
    • 0
    10 hours ago, AutoFrank said:

     

    All sorted  - thanks 

    param - it's json.

     

    Please login or register to see this code.

    Please login or register to see this code.

    after this trick you can get any data in your scene 

    Share this post


    Link to post
    Share on other sites
    • 0

    This is what works for me when updating global variables using a wemos.

     

    Some other example used a POST but that didn't work. PUT does work

     

    Please login or register to see this code.

     

    • Thanks 1

    Share this post


    Link to post
    Share on other sites
    • 0
    7 minutes ago, EK said:

    This is what works for me when updating global variables using a wemos.

     

    Some other example used a POST but that didn't work. PUT does work

     

    Please login or register to see this code.

     

     

    Thanks @EK

    Share this post


    Link to post
    Share on other sites
    • 0
    Posted (edited)

    This is far too complicated ... Is it  so that we have to make fibaro to poll outside system with http (because https does not wok either) ,  or open fibaro web interface to internet via NAT just to do the update manually.

     

    Not fun at all :-(

     

     

     

     

     

    Edited by Markoe

    Share this post


    Link to post
    Share on other sites

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