Announcement

Collapse
No announcement yet.

Magic Color Controllers

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Great. That confirms that portion of the discovery is correct then. So really I need you to confirm each packet sender command and see if you get a reply for one address or both

    Comment


      #17
      I strongly suspect that this isn't isnt going to work. I suspect if you do attempt the packet sender commands, that these may will fail.

      There are a fair few number of post online claiming that SELinux breaks udp broadcast packets being send sent due to selinux permissions/configuration which prevents broadcast packets. This is where my knowledge starts getting fuzzy as I don't know enough about SELinux or what configuration could circumvent the issue

      I'm wondering if you can run the plugin with sudo then it could potentially work?

      Comment


        #18
        Originally posted by fuzzysb View Post
        I strongly suspect that this isn't isnt going to work. I suspect if you do attempt the packet sender commands, that these may will fail.

        There are a fair few number of post online claiming that SELinux breaks udp broadcast packets being send sent due to selinux permissions/configuration which prevents broadcast packets. This is where my knowledge starts getting fuzzy as I don't know enough about SELinux or what configuration could circumvent the issue

        I'm wondering if you can run the plugin with sudo then it could potentially work?
        Its a HomeSeer SEL, not SelLinux (that is completely different). Its ubuntu based. No issues sending broadcast packets, I do it from one of my plugins. Just got here, off to test.

        Comment


          #19
          Ah ok sorry I misunderstood.

          Comment


            #20
            Ok, here testing. On my iPhone on the correct network I do see the HF-A11ASSISTHREAD when I scan. However when I start the plugin I do not see it, I tested from both the network the device is on and the other vlan adapter in case it was being sent to the wrong interface. So for some reason the plugin isn't detecting the interfaces correct (I surmise). Can I suggest you try the below (DisposableList is a custom class that runs dispose on its members when it is disposed, you can just use a list instead). The below code absolutely works on Windows and Linux and is how I broadcast Tuya device registration data on the network.

            Code:
            [FONT=Menlo]        internal static DisposableList<UdpClient> GetUdpClients(int port)
                    {
                        var udpClients = new DisposableList<UdpClient>();
            
                        foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
                        {
                            if (ni.OperationalStatus == OperationalStatus.Up && ni.SupportsMulticast && ni.GetIPProperties().GetIPv4Properties() != null)
                            {
                                int id = ni.GetIPProperties().GetIPv4Properties().Index;
                                if (NetworkInterface.LoopbackInterfaceIndex != id)
                                {
                                    foreach (UnicastIPAddressInformation uip in ni.GetIPProperties().UnicastAddresses)
                                    {
                                        if (uip.Address.AddressFamily == AddressFamily.InterNetwork)
                                        {
                                            try
                                            {
            #pragma warning disable
                                                IPEndPoint local = new IPEndPoint(uip.Address.Address, port);
            #pragma warning restore
                                                UdpClient udpc = new UdpClient(local);
                                                //udpc.ExclusiveAddressUse = false;
                                                udpc.EnableBroadcast = true;
                                                udpc.Client.SendTimeout = 2 * 1000;
                                                udpc.Client.ReceiveTimeout = 2 * 1000;
                                                udpc.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);
                                                udpc.Ttl = 16;
                                                //udpc.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontRoute, 1);
                                                udpClients.Add(udpc);
                                            }    
                                            catch (Exception ex)
                                            {
                                                Console.WriteLine("GetUdpClients exception:" + ex);
                                                continue;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        return udpClients;
                    }[/FONT]

            Comment


              #21
              Since you are likely to be in the code soon, I forgot to mention one other issue I've noticed. Something is 'off' when trying to shutdown your plugin. It takes forever for some reason, most plugins exit pretty quickly, the interface management screen with yours is tied up for multiple minutes. Wondering in the no device case if maybe a thread is being left running that gets cleaned up properly when there are devices (this is assuming that shutdown is fast when there are devices, I can certainly let you know on that once we tackle the discovery)...

              Comment


                #22
                Just as an FYI about the port communications protocol in case you haven't seen this; https://github.com/Danielhiversen/flux_led/issues/53

                Comment


                  #23
                  ok i think i can replicate the issue, Thanks for the code BTW, however i hit the same issue with that code v1.0.0.167 has been released which pushes back the exception correctly.

                  I believe that this is for you is the same as me? Operation on non-blocking socket would block

                  this is because the buffer is exceeded (its not the case for Windows), still trying to figure out how to vercome this without needing OS udp buffer reconfiguration.

                  Comment


                    #24
                    Originally posted by fuzzysb View Post
                    ok i think i can replicate the issue, Thanks for the code BTW, however i hit the same issue with that code v1.0.0.167 has been released which pushes back the exception correctly.
                    I believe that this is for you is the same as me? Operation on non-blocking socket would block
                    this is because the buffer is exceeded (its not the case for Windows), still trying to figure out how to vercome this without needing OS udp buffer reconfiguration.
                    Sorry, not sure exactly what you are referring to, I don't have any issues transmitting UDP and don't get that exception. Where are you seeing it?

                    Comment


                      #25
                      I send multiple packets, one for each Nic and have a timeout of 5000ms in the endpoint. This exception I'm getting on the socket, but only on my Linux machine. Problem is Im having terrible attaching the debugger to the process. Will pick it up again at some point. When I have a moment.

                      Your code was pretty much identical to what I had in place already, Except I have this in an iEnumerable and to the sendTo function within the move next function.

                      However the code you posted did not show how you perform the connect/send on the udpclient.

                      I need get remote debugging working on my test Linux box, but can you confirm with v1.0.0.167 that you get the same exception now in the log

                      Comment


                        #26
                        I’ll try as soon as I’m back home. I’ll post my sending code as well.

                        Comment


                          #27
                          Code:
                          [FONT=Menlo]                using (var udpClient = new UdpClient())
                                          {
                                              udpClient.ExclusiveAddressUse = false;
                                              udpClient.EnableBroadcast = true;
                                              udpClient.Client.SendTimeout = 2 * 1000;
                                              udpClient.Client.ReceiveTimeout = 4 * 1000;
                                              udpClient.Client.Bind(new IPEndPoint(IPAddress.Any, UdpBeaconPort));
                          
                                              while (!cancellationToken.IsCancellationRequested)
                                              {
                                                  var receiveTask = await udpClient.ReceiveAsync().WithCancellation<UdpReceiveResult>(cancellationToken).ConfigureAwait(false);
                                                  if (!cancellationToken.IsCancellationRequested)
                                                  {
                                                      ProcessTuyaUdpBeacon(receiveTask);
                                                      packetsReceived++;
                                                  }
                                              }
                                          }
                          
                          
                           public static class TaskExtensions
                              {
                                  public static Task<T> WithCancellation<T>(this Task<T> task, CancellationToken cancellationToken)
                                  {
                                      return task.IsCompleted
                                          ? task
                                          : task.ContinueWith(
                                              completedTask => completedTask.GetAwaiter().GetResult(),
                                              cancellationToken,
                                              TaskContinuationOptions.ExecuteSynchronously,
                                              TaskScheduler.Default);
                                  }    
                              }[/FONT]
                          Here you go... Installing update now.

                          Comment


                            #28
                            OK, there is no exception being put into the HS or the text log file. Nothing abnormal in the log, reported the version number and that the write file setting changed. No other logs...

                            Comment


                              #29
                              Originally posted by fuzzysb View Post
                              I send multiple packets, one for each Nic and have a timeout of 5000ms in the endpoint. This exception I'm getting on the socket, but only on my Linux machine. Problem is Im having terrible attaching the debugger to the process. Will pick it up again at some point. When I have a moment.

                              Your code was pretty much identical to what I had in place already, Except I have this in an iEnumerable and to the sendTo function within the move next function.

                              However the code you posted did not show how you perform the connect/send on the udpclient.

                              I need get remote debugging working on my test Linux box, but can you confirm with v1.0.0.167 that you get the same exception now in the log
                              Btw, curious why you are attaching and not just running the plugin as a remote plugin so you can start it from the debugger?

                              Comment


                                #30
                                If I run it direct from VS as a remote plugin it works fine, as it's being executed against my Windows machine and loops through the nics on my Dev machine. But when I execute directly on my Linux box when it first polls the devices (takes quite a few mins before it first runs the poll, it reports this step is starting in the log) I now get that exception returned.

                                Once I get the remote debugging set up I will step through and it should become apparent why it's failing and reporting the socket is blocking. It's potentially a Mono bug as I'm seeing this issue is complained about quite a bit when googling this issue,

                                ​​

                                Comment

                                Working...
                                X