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

Trying to send a single character from a VD over HTTP


Question

Posted

I have created a simple VD with a single button. When I press the button the character "E" should be sent to the IP address and port below. I am using the following code as LUA for the button:

 

local http = Net.FHttp("192.168.1.100", 4660);
local response = http:GET("E");
fibaro:debug(response)

 

The http request goes out and is received by the target device but it is not receiving the "E" character. Sorry - cannot tell what it is receiving but there is no response coming back to the HC2 and the device is not switching ON.

 

The address:port and sending the character "E" works fine when I send over HyperTerminal. My guess is I am not constructing the GET statement correctly? 

Any advice is greatly appreciated. 

1 answer to this question

Recommended Posts

  • 0
  • Inquirer
  • Posted

    Lots of progress thanks to @Turmoil

     

    Who has written and excellent tutorial 

    Please login or register to see this link.

     

    I have been trying to use HTTP to send and receive messages from an OmniPro 2 controller without success. Based on @Turmoil posts and tutorial I am now having success using NET.FTcpSocket

     

    Here is the LUA code on a button on the VD I am working on. Simply sends the character "A" to message the OmniPro 2 to arm the alarm. 

     

       local devId = fibaro:getSelfId();
       local ipAddr = fibaro:getValue( devId, "IPAddress");
       local tcpPort = fibaro:getValue( devId, "TCPPort");
       local timeOut = 5 * 1000;

       local vdConn = Net.FTcpSocket(ipAddr, tcpPort);
       local bytes, retc = vdConn:write("A");
       if retc > 0 then
            if retc == 2 then
                 fibaro:debug( "Connection to ".. ipAddr ..":"
                      ..tcpPort .." not established");
              else
               fibaro:debug( "Write failed: "..retc);
              end;
           else
            fibaro:debug( "Write complete, sent: "..bytes.." bytes");
            vdConn:setReadTimeout(timeOut);
          local resp, retc = vdConn:read();
            if retc > 0 then
                 if retc == 1 then
                      fibaro:debug( "Request timed out");
                   else
                      fibaro:debug( "Read complete: "..retc.." - "..resp);
                   end;
              else
             fibaro:debug( "Read complete, received: "..resp);
              end;
          end;
       vdConn:disconnect();

       

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