HomeGenie Forum
Automation Program Plugins and Wizard Scripting => Help => Topic started by: kobi.beja on January 24, 2015, 09:29:39 PM
-
Hi all
I'm looking for help, To send via tcpclient the real status of light/sensor, For example "lights:02:on", "lights:03:0ff" to 3rd party server.
Right now i know how to open the tcpclient and send only one light status.
hope to some help.
Kobi
-
var remoteServer = "192.168.123.45";
var remotePort = 12345;
Action<string> HandleStringReceived = (string message) => {
// this will be called every time a message is received from the tcp channel
Program.Notify("Server String", message);
};
Action<byte[]> HandleMessageReceived = (byte[] message) => {
// this will be called every time a message is received from the tcp channel
Program.Notify("Server Bytes", BitConverter.ToString(message));
};
Action<bool> HandleStatusChanged = (bool connected) => {
// this will be called whenever the tcp connection status has changed
Program.Notify("TCP Client", "Connected = " + connected);
};
Program.Notify("TCP Client", "Starting");
// open the TCPIP port channel and register handlers
//TcpClient.EndOfLine = "\r\n"; // default is "\n"
TcpClient
.OnStringReceived( HandleStringReceived )
.OnMessageReceived( HandleMessageReceived )
.OnStatusChanged( HandleStatusChanged )
.Service( remoteServer )
.Connect( remotePort );
Program.Notify("TCP Client", "Started");
When.ModuleParameterChanged((module, parameter) => {
if (module.IsOfDeviceType("Light,Dimmer") && parameter.Is("Status.Level"))
if (TcpClient.IsConnected)
{
var message = String.Format("{0}:{1}:{2}", module.Instance.Domain, module.Instance.Address, parameter.Value);
TcpClient.SendMessage(message);
}
else
{
Program.Notify("TCP client disconnected", "Unable to deliver message.");
}
return true;
});
Program.GoBackground();
g.
-
Hi Gene,
Thanks a lot! it's working perfect. ;D ;D
in this case it is connect only to one server, But if I want to make the HG to the server and one or more clients will be able to speak with him it is possible?
Thx
Kobi.
-
in this case it is connect only to one server, But if I want to make the HG to the server and one or more clients will be able to speak with him it is possible?
please explain better. Do you need HG to connect to more than just one server?
g.
-
Ok,
The HG is the TCPClient and he speak only with one TCPServer 192.xxx.xxx.xxx,
It's possible to make the HG to the TCPServer and other TCP clients speak with him?
Otherwise if it's not possible to open on HG TCPServer there is any way to convert the TCPClient to Serial Port via USB?
Thanks.
Kobi
-
Hi Gene,
In the same code that you sent to me, There is possibility to add alarm system and send ARMED or DISARMED status?
Thanks
Kobi
-
change the line
if (module.IsOfDeviceType("Light,Dimmer") && parameter.Is("Status.Level"))
with
if (module.Is("Security Alarm System") || (module.IsOfDeviceType("Light,Dimmer") && parameter.Is("Status.Level")))
g.
-
Thanks!!!
:D :D
Appreciate it
Kobi.