- Posts: 8
- Thank you received: 0
Please Log in or Create an account to join the conversation.
chrisrock wrote: Hi,
I tried searching the forum for my question, but did not find anything. So I'm askin.
I have a home automation system at home and want to extend it with MySensors.
Does the EasyIoT sever support sending UDP message if somthing happens on MySensors (PIR sensor)?
My home automation system can react on such UDP messages.
thx in advance!!
public void SendBroadcast(int port, string message)
{
UdpClient client = new UdpClient();
byte[] packet = Encoding.ASCII.GetBytes(message);
try
{
client.Send(packet, packet.Length, IPAddress.Broadcast.ToString(), port);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
public void Receive(int port)
{
UdpClient client = null;
try
{
client = new UdpClient(port);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
IPEndPoint server = new IPEndPoint(IPAddress.Any, 0);
while (true)
{
try
{
byte[] packet = client.Receive(ref server);
Console.WriteLine("{0}, {1}", server, Encoding.ASCII.GetString(packet));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.