19.10.2023, 03:49 (This post was last modified: 19.10.2023, 03:51 by Azar.)
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:
123
localsocket = require("socket")
localhost, port = "192.168.1.246", 48631localtcp = assert(socket.tcp())
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?
Lua syntax error at line 9: unexpected symbol near '\'
How do I get "value x 257" into "command" so that it can be sent
Hi,
There is an error in the char ` use '.
Best regards Cristian
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?
-- socket connectedifconnectedthen-- Get level of the Volume control group in the Symetrix Control 127 application on the local networkvalue = GetCBusLevel(0, 127, 10)
-- Convert level to command--command = 'cs 34' ..(value*257).. crcommand = 'CS 34 '..(value * 257).. '\r'-- send commandsock:send (command)
-- read until one line received or error occuredwhiletruedochar, err = sock:receive(1)
-- error while receiving, timeout or closed socketiferrthen-- remote server closed connection, reconnectiferr == 'closed'thenconnected = falsealert('[tcp-sock] connection closed')
os.sleep(1)
endbreak-- end of line, parse bufferelseifchar == '\r'thendata = table.concat(buffer)
log(data)
buffer = {}
-- wait some time before next requestos.sleep(1)
break-- other char, add to bufferelsebuffer[ #buffer + 1 ] = charendend-- first call or previously disconnectedelse-- close previous connection when disconnectedifsockthensock:close()
sock = nilend-- create tcp socketsock = require('socket').tcp()
sock:settimeout(1)
connected, err = sock:connect('192.168.1.246', 48631)
-- connect ok, reset bufferifconnectedthenalert('[tcp-sock] connection ok')
buffer = {}
-- error while connectingelsealert('[tcp-sock] connection failed: %s', err)
os.sleep(5)
endend
All is good now, conversion from cbus 255 to control 65535 is working,
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?
But if the value is not change often i would make it event based, initiate the connection, write the command and close the connection..
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