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

Reading consumption from web server using php


danidani

Question

Hi,

 

I would like to crate a simple web page to show summary of energy consumption of previous day.

 

This is my request to HC3:

Please login or register to see this code.

 

This is my simple php page:

Please login or register to see this code.

 

Actually, my php knowledge is very basic, just "learn by example", so I am not sure what exactly is wrong and why I don't get any result.

 

Could you please give me some working example of this?

Link to comment
Share on other sites

9 answers to this question

Recommended Posts

  • 0
On 12/10/2021 at 6:34 PM, danidani said:

Could you please give me some working example of this?

 

Please login or register to see this code.

Please login or register to see this image.

/monthly_2021_12/image.png.fc8ad3807590199f1260aaba9ea8561e.png" />

  • Thanks 2
Link to comment
Share on other sites

  • 0
  • Inquirer
  • Thank you!

     

    Actually, I am getting this error message:

     

    Notice: Trying to get property 'topConsumingDevices' of non-object in /volume1/web/elektro/index.php on line 31 Warning: Invalid argument supplied for foreach() in /volume1/web/elektro/index.php on line 31

    Top consuming devices
    Name

    Consumption

     

    If I try the same link in a browser, I got a valid json response. Do you have an idea, what could be wrong?

     

    Please login or register to see this image.

    /monthly_2021_12/obrazek.png.53efe4d89292649024ba5c493d994676.png" />

     

     

    edit: It looks like I am getting no data from HC3. I don't know why, both user name and password are correct.

     
       
    Edited by danidani
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • I used exactly your code and have changed login, password and ip address only:

     

          $login = 'my_admin_user';
          $password = 'my_admin_password';
          $url = 'http://my_ip_address/api/energy/consumption/summary?period=2021-12-11';

     

    As a web server I am using Synology Web Station with PHP 7.4.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Thank you for your patience. The result is "NULL".

     

    Please login or register to see this image.

    /monthly_2021_12/obrazek.png.5d604c19a95669438ec6584c22746ab3.png" />

     

    obrazek.png.c921920688cbca6a5397df324738a39e.png

     

    I think it is not a Fibaro issue. I suppose the problem is at Synology side or in the network configuration.

     

    edit:

     

    I tried this:

    Please login or register to see this code.

    And this is the result:

    Please login or register to see this attachment.

    If I try https instead of http in the url then result change:

    Please login or register to see this code.

     

    obrazek.png.00088e18dafa5ce67b9c4ece10e935bd.png

     

    Any idea, what could be wrong?

     

    Both HC3 and Synology are in the same local network.

     

    edit 2:

     

    If the fibaro url is "hc3-myserialnumber" then the result "bool(false)" is the same for http and https:

    Please login or register to see this code.

     

    Edited by danidani
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • After some tests, the problem is in the curl to fibaro (I don't know where).

     

    If I try this:

    Please login or register to see this code.

    I get a valid json data and I am able to parse it.

     

    If I modify

    Please login or register to see this code.

    to anything else (e.g. /api2/ or whatever in the address), the result is still the same "bool(false)".

     

    edit:

     

    I have tried this syntax aswell, but the result is the same:

    Please login or register to see this code.

     

    Edited by danidani
    Link to comment
    Share on other sites

    • 0

    https - SSL

    curl is not expect selfSigned URL

    so do not use https with fibaro API

     

    IMHO

    • Thanks 1
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Solved, thank you very much! "http" works for me.

     

    I had to change Secure Connection settings from https to http/https. Also "hc3-xxxxxxxx" is not correct if it is not registred in local DNS (even if it works in web browser). IP address in the request url is the trick.

     

    Please login or register to see this image.

    /monthly_2021_12/obrazek.png.3cf89dc3b33b2ce00d247586418cdf3f.png" />

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