TCP Socket Connection for Legrand - Printable Version +- Logic Machine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: TCP Socket Connection for Legrand (/showthread.php?tid=2068) Pages:
1
2
|
TCP Socket Connection for Legrand - savaskorkmaz - 06.05.2019 Hi, We have Legrand system that we can send commands via TCP Socket. IP Address : 192.168.161 Port : 20000 Password : 12345 On Command : *1*1*11## Off Command : *1*0*11## I tried to use some TCP socket examples in here but i failed. Can you help me for script regarding to information above. RE: TCP Socket Connection for Legrand - Daniel - 06.05.2019 Do you have some description the legrand interface? RE: TCP Socket Connection for Legrand - savaskorkmaz - 06.05.2019 Hi, We connected via f455 Legrand IP interface. We used some Legrand softwares called Scenarx. https://www.myhome-project.it/software/scenarx Via this software, we send Light on Command *1*1*11## and Light Off Command *1*0*11## and communicatin is worked. Legrand system send commands via Open WebNet protocol based on TCP Socket communication. There are open resources for openwebnet in here https://github.com/openwebnet . One is Java Client. You can see the communication example via Java. One of the our competitor in this project make connection with this Java Client example. But we want to use LM and Luascript. We heard that our competitor just send simple tcp socket commands but via Java. Regards, RE: TCP Socket Connection for Legrand - admin - 06.05.2019 At least try connecting via telnet using Putty or similar client from your PC. Since there's a password specified some extra protocol implementation is required. RE: TCP Socket Connection for Legrand - savaskorkmaz - 06.05.2019 Hi there , I will try. But if there is no password, can you write a simple script which connect to 192.168.161 address and 20000 port then it will send *1*1*11## code if the value is true. Regards, RE: TCP Socket Connection for Legrand - admin - 06.05.2019 Maybe you are missing additional \r\n after the command? RE: TCP Socket Connection for Legrand - savaskorkmaz - 06.05.2019 Hi, You can find some videos with putty connection. https://www.youtube.com/watch?v=O2d_abVaqe0 https://www.youtube.com/watch?v=qDQftLB25Hc Can you write an example script considering there is no password . Regards, RE: TCP Socket Connection for Legrand - admin - 07.05.2019 This is not a proper protocol implementation, but see if this works for you: Code: function openwebnetcmd(ip, cmd) RE: TCP Socket Connection for Legrand - savaskorkmaz - 07.05.2019 Hi, With a little change, it worked well. Thank you very much. RE: TCP Socket Connection for Legrand - savaskorkmaz - 07.05.2019 Hello, As I said before above, sending command is working. Now I need to listen status information. For getting status, I send *99*1## command first , Then I send *1*11## command. It means, I request status information for light address 11. In putty, we get information like *1*1*11## . In logic machine, how can i write this feedback in to a variable (Like value ) in script. Regards, RE: TCP Socket Connection for Legrand - a455115 - 11.04.2022 (07.05.2019, 16:00)savaskorkmaz Wrote: Hi, Hello, Would you share the changes to the script and how you tied it to a password? Thanks in advance! RE: TCP Socket Connection for Legrand - admin - 11.04.2022 The password algorithm differs between gateways. Which one are you using? RE: TCP Socket Connection for Legrand - a455115 - 12.04.2022 (11.04.2022, 12:14)admin Wrote: The password algorithm differs between gateways. Which one are you using? Gateway is MH200N RE: TCP Socket Connection for Legrand - admin - 13.04.2022 Try this, change PASS and IP as needed. The script handles the authentication part, after that you can issue commands, read status info etc. Code: function calcpass(pass, nonce) RE: TCP Socket Connection for Legrand - a455115 - 14.04.2022 Thank you very much for the answer and the example! I will try it on Saturday and give feedback. RE: TCP Socket Connection for Legrand - a455115 - 15.04.2022 (13.04.2022, 12:02)admin Wrote: Try this, change PASS and IP as needed. The script handles the authentication part, after that you can issue commands, read status info etc.I get this as errors: AS 15.04.2022 22:59:11 Resident script:19: bad argument #1 to 'band' (number expected, got nil) stack traceback: [C]: in function 'band' Resident script:19: in function 'calcpass' Resident script:132: in function 'openwebnetinit' AS 15.04.2022 22:59:21 Resident script:19: bad argument #1 to 'band' (number expected, got nil) stack traceback: [C]: in function 'band' Resident script:19: in function 'calcpass' Resident script:132: in function 'openwebnetinit' AS 15.04.2022 22:59:32 Resident script:19: bad argument #1 to 'band' (number expected, got nil) stack traceback: [C]: in function 'band' Resident script:19: in function 'calcpass' Resident script:132: in function 'openwebnetinit' AS 15.04.2022 22:59:45 Resident script:19: bad argument #1 to 'band' (number expected, got nil) stack traceback: [C]: in function 'band' Resident script:19: in function 'calcpass' Resident script:132: in function 'openwebnetinit' AS 15.04.2022 22:59:58 Resident script:19: bad argument #1 to 'band' (number expected, got nil) stack traceback: [C]: in function 'band' Resident script:19: in function 'calcpass' Resident script:132: in function 'openwebnetinit' RE: TCP Socket Connection for Legrand - a455115 - 17.04.2022 What I managed to do so far is to redirect the data from MH200 to LM without a password, because obviously the error in the script is from the password. I'm trying to read what's going on the line using the first code, but to no avail. How do I make the codes coming out of the MH200N visible in the console and be able to associate them with virtual objects? RE: TCP Socket Connection for Legrand - admin - 19.04.2022 Start by logging what data the gateway is sending. Modify read function like this: Code: function read(sock) For an event session you need to change OPEN command to *99*1## RE: TCP Socket Connection for Legrand - a455115 - 20.04.2022 Code: function read(sock) Code: Resident script:5: calling 'receive' on bad self (tcp{client} expected, got userdata) RE: TCP Socket Connection for Legrand - admin - 20.04.2022 Line 37 is incorrect: Code: local res, err = socket.connect('192.168.1.247', 20000) It should be: Code: local res, err = sock:connect('192.168.1.247', 20000) |