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


  • 1

Using API with Arduino


gilbert

Question

Hope somebody can help me...

I want to use my Arduino Uno for sending a http request to HC2 for turning off a light. When I enter

"http://admin:[email protected]:80/api/callAction?deviceID=7&name=turnOff"

into the address bar of my browser, the light nicely turns off.

I tried the following code for the Arduino, but with no succes:

Please login or register to see this code.

I tried different things like PUT and POST and different examples I found on different forums. The serial monitor of the Arduino IDE prints "connected", so I assume a connection is established with the HC2. I'm not that familiar with http requests so any help is appreciated

Please login or register to see this image.

/emoticons/default_icon_biggrin.gif" alt=":-D" />.

Thanks in advance.

Link to comment
Share on other sites

14 answers to this question

Recommended Posts

  • 0

gilbert, try with on the same line

Please login or register to see this code.

. Perhaps try encode url

Please login or register to see this code.

but I don't know much about this platform... Good luck

Please login or register to see this image.

/emoticons/default_icon_wink.gif" alt=";-)" />

Link to comment
Share on other sites

  • 0

The reason your browser is successfull is because you are logged in to the HC2 with a session. But you don't enter your credentials with your arduino code...

So you have to find out how to add that. I am very interested in the code you are building. Was thinking of building a Arduino device with a Keypad, rfid, and tts engine for arming and disarming the alarm with voice feedback. What kind of arduino and module do you use?

Link to comment
Share on other sites

  • 0
  • Inquirer
  • Krikroff, thanks for your reply. I will try this tonight.

    stevenvd, I hoped using

    Please login or register to see this code.

    would log into the HC2. But 'm not sure it works correctly.

    I use an Arduine Uno Rev3 with an ethernet shield (Wiznet W5100) from dealextreme.

    Link to comment
    Share on other sites

    • 0
    Krikroff, thanks for your reply. I will try this tonight.

    stevenvd, I hoped using

    Please login or register to see this code.

    would log into the HC2. But 'm not sure it works correctly.

    I use an Arduine Uno Rev3 with an ethernet shield (Wiznet W5100) from dealextreme.

    You can also try

    Please login or register to see this code.

    or put basic authentification (encoded in Base64) in header:

    Please login or register to see this code.

    cf.

    Please login or register to see this link.

    regards.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Krikroff Thanks for your help, appreciate it. I tried a lot of things, but with no succes. I think indeed the problem is with the authorization.

    As I did not found examples for http communication between Arduino and HC2, I found enough examples of http communication between Arduino and Vera from micasaverde. I assume it also needs authorization, but I don't know the Vera.

    Nevertheless, I made some progress. I managed to create a TCP connection between HC2 and Arduino. To do this I created a virtual device button with the following code:

    Please login or register to see this code.

    The Arduino can read this code and send back an acknowledgement using the following code:

    Please login or register to see this code.

    However, to get information from Arduino, HC2 has to poll the Arduino, for example each x seconds in the main loop of the virtual device. I know this isn't the best solution, but for me it will work for the things I want to achieve.

    Still, any suggestions and tips are welcome

    Please login or register to see this image.

    /emoticons/default_icon_biggrin.gif" alt=":-D" />

    Link to comment
    Share on other sites

    • 0

    gilbert, have you try to add a custom header to your http request with

    Please login or register to see this code.

    ? normally it should work...

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • I tried:

    Please login or register to see this code.

    where xxxxx is the base64 encoded text of username:password (encoding at

    Please login or register to see this link.

    )

    But without succes...

    Please login or register to see this image.

    /emoticons/default_icon_confused.gif" alt=":-?" />

    Link to comment
    Share on other sites

    • 0
    Guest rafal_ll
    I tried:

    Please login or register to see this code.

    where xxxxx is the base64 encoded text of username:password (encoding at

    Please login or register to see this link.

    )

    But without succes...

    Please login or register to see this image.

    /emoticons/default_icon_confused.gif" alt=":-?" />

    Solved the problem?

    Link to comment
    Share on other sites

    • 0

    Did you manage to get it working? I want to build a wall thermostat and Alarm panel on an Arduino with a 4d systems touchscreen and Wifi shield.

    Link to comment
    Share on other sites

    • 0
    Guest samuelboerhoop

    gilbert or others how did you solve the problem?

     

    I have a arduino nano with en enc28j60 ethernet module. 

    a webserver, with a webpage is working, with 4 inputs and 4 outputs, displaying.

    From my HC2 I can sent commands to the arduino nano to switch on/off the relays, when i go to the webserver from the arduino nano on the webpage i am able to switch on/off the relays too.

     

    Now I have to arrange the inputs feedback and output feedback towards the fibaro hc2 isn't working yet.

     

    if someone needs my arduino sketch let me know. 

     

    when i type this line below in a normal browser it will trigger by means of a VD button a global variable.

    So i need to convert this to arduino language to sent to the fibaro hc2

     

     

    Please login or register to see this link.

     

    login = loginname from hc2

    password = password from hc2

    ip-address-hc2 = ip address from Hc2

    deviceid = device id from virtual device

    last digit 1 = number button

     

    love to hear from you guys

    Link to comment
    Share on other sites

    • 0
    Guest samuelboerhoop

    Gilbert: you said: However, to get information from Arduino, HC2 has to poll the Arduino, for example each x seconds in the main loop of the virtual device.

     

    What is the code you put in de main loop to read the response ? Thanks for sharing

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" />

    Link to comment
    Share on other sites

    • 0

     

    Please login or register to see this code.

    #include <Ethernet.h>
    #include <SPI.h>
    #include "RestClient.h"

    RestClient client = RestClient("192.16.1.136"); //IP Home Center

    //Setup
    void setup() {
      Serial.begin(9600);
      // Connect via DHCP
      Serial.println("connect to network");
      client.dhcp(); //DHCP IP
      Serial.println("Setup!");
    }

    String response;
    void loop(){
      response = "";
      client.setHeader("Authorization: Basic XXXXXXXXXX"); //In base 64 user: password
      int statusCode = client.get("/api/sceneControl?id=id&action=start", &response); //code to execute the id scene
      Serial.print("Status code from server: ");
      Serial.println(statusCode);
      Serial.print("Response body from server: ");
      Serial.println(response);
      delay(1000);
    }

     

    Please login or register to see this code.

    Link to comment
    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...