TCP/ip connect and maintain connection - 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/ip connect and maintain connection (/showthread.php?tid=5040) |
TCP/ip connect and maintain connection - Azar - 19.10.2023 I am trying to place a resident script to connect to an ip address, monitor connection and reconnect if connection is lost. I am reading and watching every tutorial i can find and am slowly getting more understanding but need others help with this. I am after some guidance in the implementation of a TCP/ip connection to third party device (Symetrix DSP, control protocol same as control4, amx, crestron, lutron). I have connection working between both the SHAC and the Symetrix DSP, as in I can ping it with a response through the "Network Utilities" I have full control of Symetrix working through PuTTY terminal and now need to implement scripting to send, and manage received data. Can anyone share with me scripting that will build this connection, maintain this connection, reconnect if device goes offline then returns online.. I have found multiple examples of this but am not getting much luck with connection or how to monitor if the connection is alive. Code: local socket = require("socket") Once i have this connection up and running I need to build scripting to send controls to and receive pushed controls back to update GA's in the SHAC. Control protocol info from Symetrix document shown below. The Control Protocol is a text-based (ASCII string) protocol. Commands are sent with simple character strings with terms separated by spaces and completed with a carriage return character <CR> (ASCII code decimal 13). The general form for commands is: <COMMAND> <PARAMETER1> <PARAMETER2> … <CR> When in PuTTY if i send the command CS 1 65535 <CR> I get Controller Set "CS" to controller number "1" set to maximum "65535" (all as expected) with a response of ACK. Can I send this same data through a LUA script? or does it need to be converted to another format? RE: TCP/ip connect and maintain connection - admin - 19.10.2023 Use this resident script (sleep time = 0) as a starting point: Code: -- socket connected RE: TCP/ip connect and maintain connection - Azar - 21.10.2023 Thank you so much, now i know that this will be achievable and I can manage everything from my SHAC. next question can i place a variable parameter into a sockend?? as in value = GetCBusLevel(0, 127, 10) --0-255 value * (65535/255) value * 257 example -- send command sockend('CS 34 value*257 \r') this is not working, how would i go about implementing this variable number into the "socket send" RE: TCP/ip connect and maintain connection - Erwin van der Zwart - 21.10.2023 Like this: Code: value = GetCBusLevel(0, 127, 10) RE: TCP/ip connect and maintain connection - Azar - 21.10.2023 (21.10.2023, 10:56)Erwin van der Zwart Wrote: Like this: I'm getting a error Lua syntax error at line 9: unexpected symbol near '\' How do I get "value x 257" into "command" so that it can be sent RE: TCP/ip connect and maintain connection - CristianAgata - 22.10.2023 (21.10.2023, 22:16)Azar Wrote:Hi,(21.10.2023, 10:56)Erwin van der Zwart Wrote: Like this: There is an error in the char ` use '. Best regards Cristian RE: TCP/ip connect and maintain connection - Azar - 22.10.2023 (22.10.2023, 10:21)CristianAgata Wrote:(21.10.2023, 22:16)Azar Wrote:Hi,(21.10.2023, 10:56)Erwin van der Zwart Wrote: Like this: Hi Cristian, would you kindly explain in more detail? I'm not sure what you mean! Are you pointing to the end of the second line ? Just prior to the backslash? RE: TCP/ip connect and maintain connection - CristianAgata - 22.10.2023 (22.10.2023, 11:45)Azar Wrote:In your code if I m looking good before the /r' there's this char "`" and it is wrong. You must change with this " ' ".(22.10.2023, 10:21)CristianAgata Wrote:(21.10.2023, 22:16)Azar Wrote:Hi,(21.10.2023, 10:56)Erwin van der Zwart Wrote: Like this: Best regards Cristian RE: TCP/ip connect and maintain connection - Erwin van der Zwart - 22.10.2023 Oeps.. responding with iOS on iPhone does that but indeed ‘ must be ' Corrected it in my original post RE: TCP/ip connect and maintain connection - Azar - 28.10.2023 Code: -- socket connected This script continues to send command at every 1 second interval is there any way i can change this so that it only sends socket command apon a new change of cbus level value. similar to an event script that waits for an event before acting? RE: TCP/ip connect and maintain connection - Erwin van der Zwart - 28.10.2023 Just add a if condition like this: Code: if previousvalue ~= value then RE: TCP/ip connect and maintain connection - Azar - 28.10.2023 (28.10.2023, 08:25)Erwin van der Zwart Wrote: Just add a if condition like this:I've decided to go to an event script but cant get this to work. Event script by Keyword: Symetrix. all GA's with keyword "Symetrix" also have there control comand number assigned to them by keyword " SYM=### " I'm trying to get the script to insert the control number into the "CS" Command Send line . I'm getting a log of * string: Error: sym=address tag missing Code: local value = event.getvalue() RE: TCP/ip connect and maintain connection - admin - 30.10.2023 Try using this: Code: tags = grp.gettags(event.dst) Note that tags are case-sensitive. |