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

Sending UDP Commands Lua


morsink

Question

Hello,

 

I'm a starter in programming for my HC2.
I made a Virtual Device (KMTronice, UDP Relay) and wanne send this code:

 

local ip, port = "192.168.100.166", 12345      
local message = "FF0100"
local socket = require "socket" 
sock, msg = socket.udp()
if sock then 
  sock:setpeername(ip, port) end         -- connect to destination
  sock:send(message)
  sock: close()
end

 

But I get this error:

[ERROR] 13:32:10: line 2: unexpected symbol near '%'

[ERROR] 13:40:35: line 9: '' expected near 'end'

 

What I'm doing worng @ this script ?

 

 

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

is this part ok?

 

local ip, port = "192.168.100.166", 12345      
local message = "FF0100"
local socket = require "socket" 

 

i get  a error on require 

[ERROR] 16:06:08: line 4: attempt to call global 'require' (a nil value)

Edited by fkruis
Link to comment
Share on other sites

  • 0
  • Inquirer
  • I don't know exactly.
    I wanne send a UPD command!
    Where can I find some basis scirpts ?
    Did some research and maybe I have to edit some, username + password.

     

    TCP I find a working script but not for UDP.

    Link to comment
    Share on other sites

    • 0

    not sure about model of the KMTronic you using, but feel free to try my VD

    You will have to create two global variables, relayone and relaytwo

     

    Edit: i use http and hidden Relais status, not UDP

     

    Please login or register to see this attachment.

     

    now regarding your code:

     

    On ‎7‎/‎20‎/‎2018 at 1:41 PM, morsink said:

    local ip, port = "192.168.100.166", 12345      

    local message = "FF0100"
    local socket = require "socket" 
    sock, msg = socket.udp()
    if sock then 
      sock:setpeername(ip, port) end         -- connect to destination
      sock:send(message)
      sock: close()
    end

     

    you have unexpected 'end' in this line

     

    Please login or register to see this code.

    then you are using 'require', which ich not working on HC2 (it is not allowed to use it), so that code will not work.

     

    If you really need UDP, you can try following (i do send here udp data to KNX bone)

    Please login or register to see this code.

     

    Edited by tinman
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Thanks for your information.

     

    Please login or register to see this link.

     is not going to work because I have another version.

     

    So here I found some more information about he product:

    Please login or register to see this link.

     

    I tried also using Packet Sender, and works perfect. Without any username or password.

    So on the next Line:

    Please login or register to see this code.

     

    FF0000 - Status Read command
    FF0100 - Relay 1 OFF command
    FF0101 - Relay 1 ON command

    FF0200 - Relay 2 OFF command
    FF0201 - Relay 2 ON command

    FF0300 - Relay 3 OFF command
    FF0301 - Relay 3 ON command

    FF0400 - Relay 4 OFF command
    FF0401 - Relay 4 ON command

    FF0500 - Relay 5 OFF command
    FF0501 - Relay 5 ON command

    FF0600 - Relay 6 OFF command
    FF0601 - Relay 6 ON command

    FF0700 - Relay 7 OFF command
    FF0701 - Relay 7 ON command

    FF0800 - Relay 8 OFF command
    FF0801 - Relay 8 ON command

    FFE000 - All relays OFF command
    FFE0FF - All relays ON command

     

    I'm correct ?  for every buttion ? Or like a Toggle buttion if that's possible ? 

     

    And about this line:

     

    -- if you need to do broadcast
    -- for example to do WOL
    -- socket:setBroadcast(true)
    socket:setReadTimeout(1000)

     

    Do I broadcast ? Because is sending some message ?

     

     

    15 hours ago, tinman said:

     

     

    not sure about model of the KMTronic you using, but feel free to try my VD

    You will have to create two global variables, relayone and relaytwo

     

    Edit: i use http and hidden Relais status, not UDP

     

    Please login or register to see this attachment.

     

    now regarding your code:

     

     

    you have unexpected 'end' in this line

     

    Please login or register to see this code.

    then you are using 'require', which ich not working on HC2 (it is not allowed to use it), so that code will not work.

     

    If you really need UDP, you can try following (i do send here udp data to KNX bone)

    Please login or register to see this code.

     

     

    Link to comment
    Share on other sites

    • 0

    Hello, Can somebody please post an UDP LUA SCRIPT FOR Sending specific KNX commands? using commands for switch on/off, dimm to group adreses in knx? Thank you

    Link to comment
    Share on other sites

    • -1
    On ‎7‎/‎23‎/‎2018 at 3:15 PM, morsink said:

    Please login or register to see this link.

     is not going to work because I have another version.

     

    So here I found some more information about he product:

    Please login or register to see this link.

     

    ok

     

    On ‎7‎/‎23‎/‎2018 at 3:15 PM, morsink said:

     

    I tried also using Packet Sender, and works perfect. Without any username or password.

    So on the next Line:

    Please login or register to see this code.

     

    FF0000 - Status Read command
    FF0100 - Relay 1 OFF command
    FF0101 - Relay 1 ON command

    FF0200 - Relay 2 OFF command
    FF0201 - Relay 2 ON command

    FF0300 - Relay 3 OFF command
    FF0301 - Relay 3 ON command

    FF0400 - Relay 4 OFF command
    FF0401 - Relay 4 ON command

    FF0500 - Relay 5 OFF command
    FF0501 - Relay 5 ON command

    FF0600 - Relay 6 OFF command
    FF0601 - Relay 6 ON command

    FF0700 - Relay 7 OFF command
    FF0701 - Relay 7 ON command

    FF0800 - Relay 8 OFF command
    FF0801 - Relay 8 ON command

    FFE000 - All relays OFF command
    FFE0FF - All relays ON command

     

    I'm correct ?  for every buttion ? Or like a Toggle buttion if that's possible ? 

     

    in principle you can do read the status in main loop, to show in labels and control them on/off with buttons, where each button have then set of values to send to relais

     

    local data = string.char(0xff, 0x01, 0x01) -- that should be Relay 1 ON command

     

    On ‎7‎/‎23‎/‎2018 at 3:15 PM, morsink said:

     

    And about this line:

     

    -- if you need to do broadcast
    -- for example to do WOL
    -- socket:setBroadcast(true)
    socket:setReadTimeout(1000)

     

    Do I broadcast ? Because is sending some message ?

     

    no you don't need these lines, you do send to specific IP (of the Relais), and not to all devices in the network

     

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