UDP Message notification

9 years 6 months ago #1216 by chrisrock
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!!

Please Log in or Create an account to join the conversation.

9 years 6 months ago #1228 by EasyIoT
Replied by EasyIoT on topic UDP Message notification

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!!


Yes you can in automation module. There are examples on forum how to control TCP. It's easy to change TCP to UDP in those examples. Use UdpClient class:
msdn.microsoft.com/en-us/library/system....lient(v=vs.110).aspx

This are (untested) examples of code to send and receive UDP messages:
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);
            }
        }
    }
The following user(s) said Thank You: chrisrock

Please Log in or Create an account to join the conversation.

9 years 6 months ago #1236 by chrisrock
Replied by chrisrock on topic UDP Message notification
hi,

first of all, thank you for your help. I really love this project and want to use it to complete my home automation system.
I have to learn a lot, of how to use the automation feature. but thats only a matter of time ;-)

regards!!

Please Log in or Create an account to join the conversation.

Time to create page: 0.176 seconds

Forum latest

  • No posts to display.