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

http module


robd

Question

to make a connection between the HC2 and other IP base units like a raspberry PI you need to use the LUA code

local name = Net.FHttp("IP adress", port)

in my case this leads to a error message telling me that I am trying to index or assign a nil value to the variable "Net".

some investigation leads to the assumption that my HC2 is missing a HTTP module. to test this I used the lines

if Net == nil

then fibaro:debug("no net")

end

alternatively

if Net ~= nil

then fibaro:debug("net")

end

 

I get "no net" as result.

 

then I read that I should install the network module with

local name require ("socket.http")

see

Please login or register to see this link.

the require function should take care of all the dependencies and install the network module.

 

unfortunately this also leads to a error saying that I am trying to assign a nil value to a variable.

 

where am I going wrong?

 

HC2 with latest software version

Edited by robd
Link to comment
Share on other sites

16 answers to this question

Recommended Posts

  • 0

Hi @robd

 

Are you trying this from a scene or a virtual device 

The syntax is different between the two. 

There are some examples of both in the links with my signature 

 

_f

Link to comment
Share on other sites

  • 0
17 minutes ago, robd said:

then I read that I should install the network module with

local name require ("socket.http")

see

Please login or register to see this link.

the require function should take care of all the dependencies and install the network module.

 

The HC implementation of Lua does not allow you to do a "require", so you cannot add (user or system) modules. This is by design. Also things like coroutines have been disabled. But as @AutoFrank said, both VD and Scenes come with a http interface (but using different syntax and concept) that will allow you to interface to your Pi.

Link to comment
Share on other sites

  • 0
  • Inquirer
  • 10 hours ago, AutoFrank said:

    Hi @robd

     

    Are you trying this from a scene or a virtual device 

    The syntax is different between the two. 

    There are some examples of both in the links with my signature

     

    Currently I am trying this from a scene just to start testing things. Eventually I want to use this from a VD.

    purpose is to connect a ventilation unit with RS232 interface via a Rasperry Pi to the HC2. (alternatively I could use a RS232 to IP converter but this requires implementing the ventilation unit's protocol in the HC2 which seems more work).

    goal is to read 4 temperatures from the ventilation unit and put one steering level (setpoint) to the unit.

     

    Implementation: connect a PI to the ventilation unit and implement the protocol in the PI.

    HC2 reads the temperature values from the PI and sends the setpoint to the PI.

    the readings are presented in a VD and the setpoint could be a slider in the VD.

     

    total it is a complete project to be devided in chunks.

    the first chunk is to setup the connection between the HC2 and the PI

     

    @AutoFrank Thanks for the tutorials

    I started with the one for the VD's.

    next was the LAN monitor 2.5. Awesome. works like a charm. This is just what I needed to check the connection from HC2 to PI.

     

    So on the PI I make a json table with the collected values.

    And in the main loop (or the button) of the VD I plan to program a GET to retrieve the json table from the PI.

     

    Edited by robd
    Link to comment
    Share on other sites

    • 0

    Hi @robd

     

    I'm doing almost the same, I am reading data from my smart electric meter with a Raspberry Pi, write this to a temporary file on my RasPi, and then read the temporary file with a http call made by a VD on my HomeCenter2.

    I'm just copying the data I read to strings in the VD, not using them any further, but that you can easily change.

     

    This is the LUA code of the VD, calling the readmeter-PHP file on the RasPi (you have to setup an Apache web server on the RasPi, and to setup PHP)

     

    PI1 = Net.FHttp("192.168.178.62");
    res, status, errorCode = PI1:GET("/readmeter.php");

    vDevId = 285;

    arrData = json.decode(res);
    fibaro:call(vDevId,"setProperty", "ui.lvermogen.value" ,arrData[1].vermogen.." Watt");
    fibaro:call(vDevId,"setProperty", "ui.lvermogenterug.value",arrData[1].tvermogen.." Watt");
    fibaro:call(vDevId,"setProperty", "ui.ldaleneco.value" ,arrData[1].daldag.." kWh ");
    fibaro:call(vDevId,"setProperty", "ui.lpiekeneco.value",arrData[1].piekdag.." kWh ");
    fibaro:call(vDevId,"setProperty", "ui.ldalterug.value" ,arrData[1].dalterug.." kWh ");
    fibaro:call(vDevId,"setProperty", "ui.lpiekterug.value",arrData[1].piekterug.." kWh ");

     

    the readmeter php file looks as follows (in directory /var/www/html

     

    <?php

        // roep script aan om file aan te maken
            $command=system("/usr/bin/python /var/www/scripts/p1script.py >/var/tmp/wim-p1.log 2>&1");

        // bestandje ophalen

        $filename = "/var/tmp/jsonmeters.txt";
        $fhandle = fopen($filename,"r");
        $jsonspul = fread($fhandle,filesize($filename));
        fclose($fhandle);

        // nu teruggeven
        echo($jsonspul)

    ?>

     

    this calls again a python script, which makes the file jsonmeters.txt, which is a java file looking as follows:

     

    [{"daldag": 2723.718, "piekdag": 1692.615, "dalterug": 1455.3, "piekterug": 3294.882, "vermogen": 2681.0, "tvermogen": 0.0}]

     

    Hopes this brief explanation helps, if not, drop a note and I will explain futher.

     

    Regards,

    Wim

     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • @Wimjanse Thanks Wim,

    Currently I am waiting for some serial to USB hardware to hook up my PI to the ventilator.

    but in the mean time (this weekend I hope) I can try your solution tot connect my HC2 to the PI and get some testdata up and down.

    I"ll keep you informed.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • broke my shoulder yesterday.

    whole project on ice for a few months

    Link to comment
    Share on other sites

    • 0
    4 hours ago, robd said:

    broke my shoulder yesterday.

    whole project on ice for a few months

    Oh man, 

     

    Beterschap!!

    Link to comment
    Share on other sites

    • 0
    On 5/22/2017 at 3:05 PM, robd said:

    broke my shoulder yesterday.

    whole project on ice for a few months

     

    Ufff, I wish you quick and full recovery!

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • thanks for all your good wishes.

    pain is gradually decreasing.

    another 4 weeks with my hand in a sling and then some months "rehabilitation" (revalidatie) to get the shoulder joint working again.

    I hope I have had the worst behind me.

     

    in the mean time the new FTDI 5 volt serial > usb convertor is connected but without result. BTW this was before my crash.

    if I do a loop back it is working fine, but connected to the whr930, no result.

    I have not connected to the rj45, but to the screw terminal, may be the misstake is there, but with my arm there is no way to climb up to the unit and change to the rj45 connector.

     

    I have progress on the rest of the chain, comms between hc2 and PI is working so I hope to continue this project in July

    thanks again for your support

     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • back again.

    it was a long recovery including an operation in july. but I can work on this project again and i think I can even physically access the WHR930 controller.

    I am trying to pick up the pieces of this project. the hardware is still there, but the knowledge is far gone.

    Including a vast number of (browser)favorites to a.o. AutoFrank and others (also on other forums) due to a scrub of my computer before an upgrade to Win10.

    but DuckDuckGo en Google are my friends :-)

    the only thing these search engines can't do is recover the passwords for my PI for my account and the admin account :-(

    and with a complete new install I will probably lose the very latest changes in the Python scripts I used on the PI to read the WHR 930

     

    regards

     

    Link to comment
    Share on other sites

    • 0
    8 hours ago, robd said:

    back again.

    it was a long recovery including an operation in july. but I can work on this project again and i think I can even physically access the WHR930 controller.

    I am trying to pick up the pieces of this project. the hardware is still there, but the knowledge is far gone.

    Including a vast number of (browser)favorites to a.o. AutoFrank and others (also on other forums) due to a scrub of my computer before an upgrade to Win10.

    but DuckDuckGo en Google are my friends :-)

    the only thing these search engines can't do is recover the passwords for my PI for my account and the admin account :-(

    and with a complete new install I will probably lose the very latest changes in the Python scripts I used on the PI to read the WHR 930

     

    regards

     

     

    Welcome back!

    Welkom terug!

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • On 5/1/2017 at 3:46 PM, Wimjanse said:

    <?php

        // roep script aan om file aan te maken
            $command=system("/usr/bin/python /var/www/scripts/p1script.py >/var/tmp/wim-p1.log 2>&1");

        // bestandje ophalen

        $filename = "/var/tmp/jsonmeters.txt";
        $fhandle = fopen($filename,"r");
        $jsonspul = fread($fhandle,filesize($filename));
        fclose($fhandle);

        // nu teruggeven
        echo($jsonspul)

    ?>

    @Wimjanse

    I don't understand something.

    What is the function of the PHP script. I would guess that the python script that collects the meterdata should be able to construct a textfile in json format in the correct directory.

    it now is a 3 tier construct:

    first a python program to collect the meterdata

    second a PHP script to do ??? produces a json style file.

    third a LUA script in a virtual device in my HC2 that reads the json file on the PI and processes the json data.

     

    third step is ready. I can read a json file from my PI and present the data in a VD.

    first step I am working on but I have some issues with RS232 ==> USB

    what is the inbetween step?

    BTW 1 project and I have to learn 3 programming languages, LUA, PHP and python :-(

    Link to comment
    Share on other sites

    • 0

    Hi @robd

     

    the Python program collects the meter data, and already writes a json style file.

     

    the Lua program on the HC2 reads and processes this json style file. 

     

    The PHP program is just a step in the middle, being triggered by the http call, opens the json file and writes the contents back to the calling program.

     

    I found this approach from others on the internet. It might well be possible to call the python script directly, but I lack python/http knowledge how to write the data back to the calling program. Neither I have much knowledge on PHP, but do understand the working of these few lines.

    As this approach worked well, I did not spend any time in improving the 3-step approach towards a 2-step ( if it works, don’t touch it ).

     

    Hope this explains, as I said, no need to learn PHP, just use these lines above, which I did for approx. 15 different scenes called by virtual devices.

     

    Hi @robd

     

    welkom terug trouwens, hoop dat alles goed met je gaat momenteel

     

    groet,

    Wim

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • I have all the programming checked and working but getting no results.
    My guess is that the protocol description for the WHR930 is not compatible with the WHR930 Luxe which I am using.
    I get no response on the commands that I send to the unit.
    the send led on the USB<->RS232 interface is blinking when I send a command but the receive led stays dark. no response at all.
    I have changed the Rx and Tx and I used the RJ45 as well as the screw terminals.
    Only the DB9 is not tried yet.
    Does anyone know if there is a protocol specification for the WHR930 Luxe.
    Zehnder Netherlands is not supporting this type of information.

    On 10/24/2017 at 7:39 PM, Wimjanse said:

    Hi @robd

     

    the Python program collects the meter data, and already writes a json style file.

     

    the Lua program on the HC2 reads and processes this json style file. 

     

    The PHP program is just a step in the middle, being triggered by the http call, opens the json file and writes the contents back to the calling program.

     

    I found this approach from others on the internet. It might well be possible to call the python script directly, but I lack python/http knowledge how to write the data back to the calling program. Neither I have much knowledge on PHP, but do understand the working of these few lines.

    As this approach worked well, I did not spend any time in improving the 3-step approach towards a 2-step ( if it works, don’t touch it ).

     

    Hope this explains, as I said, no need to learn PHP, just use these lines above, which I did for approx. 15 different scenes called by virtual devices.

     

    Hi @robd

     

    welkom terug trouwens, hoop dat alles goed met je gaat momenteel

     

    groet,

    Wim

    ja, dank, de schouder gaat beter.

     

    you should take a look at this project. you can learn a lot from the python programming. and I have it running without the PHP interface.

    a HC2 virtual device is reading a json file from the PI in directory /var/www/html

    in my opinion you don't need the PHP intermediate step.

     

    may be I have to start a new thread because it has noting to do anymore with the http interface.

     

    I don't have time now but I can explain further in the first week of december.

     

    Edited by robd
    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...