public async Task <bool> SearchForDevices()
        {
            AddOutputText("Searching for devices...");

            Devices = await Broadlink.Discover(1);

            AddOutputText($"Found {Devices.Length} device(s).");

            if (Devices.Length > 0)
            {
                _comboBoxDevices.Items.Clear();

                for (int index = 0; index < Devices.Length; index++)
                {
                    var    device = Devices[index];
                    string mac    = BitConverter.ToString(device.Mac);
                    string id     = BitConverter.ToString(device.Mac);
                    AddOutputText($"Device {index + 1}:   DeviceType:'{device.DeviceType}'   Host:'{device.Host}'   MAC:'{mac}'");

                    ComboBoxItem item = new ComboBoxItem();
                    item.Content = $"Device {index + 1}";
                    item.ToolTip = $"Device {index + 1}:   DeviceType:'{device.DeviceType}'   Host:'{device.Host}'   MAC:'{mac}'";
                    //item.Tag = device;
                    _comboBoxDevices.Items.Add(item);
                }

                _comboBoxDevices.SelectedIndex = 0;
            }

            return(true);
        }
Ejemplo n.º 2
0
        private static async Task <bool> Sp2SmartPlugTest()
        {
            var devs = await Broadlink.Discover(3);

            var dev = (Sp2)devs.First(d => d.DeviceType == DeviceType.Sp2);

            // before Auth, cannot get values.
            var res1 = await dev.Auth();

            // result not recieved.
            var powerState = await dev.CheckPower();

            var nightLightState = await dev.CheckNightLight();

            var status = await dev.CheckStatus();

            var res2 = await dev.SetPower(true);

            var res3 = await dev.SetNightLight(true);

            await dev.SetPower(false);

            await dev.SetNightLight(false);

            var energy = await dev.GetEnergy();

            return(true);
        }
Ejemplo n.º 3
0
        private static async Task <bool> RmRfSignalTest()
        {
            var devs = await Broadlink.Discover(3);

            var targetIp = new byte[] { 192, 168, 254, 142 };
            var rm       = (Rm2Pro)devs.FirstOrDefault(d => d.Host.Address.GetAddressBytes().SequenceEqual(targetIp));

            if (rm == null)
            {
                throw new Exception("Rm2Pro Not Found");
            }

            if (!await rm.Auth())
            {
                throw new Exception("Auth Failure");
            }

            var res1 = await rm.EnterRfLearning();

            var res20 = await rm.CheckRfStep1Data();

            var res21 = await rm.EnterRfLearning();

            var res3 = await rm.CheckRfStep2Data();

            var res4 = await rm.CancelRfLearning();

            var res5 = await rm.SendRfData(res3);

            return(true);
        }
Ejemplo n.º 4
0
        private static async Task TestIrLearning()
        {
            Console.WriteLine("Searching for Rm2Pro devices...");
            var devs = await Broadlink.Discover(1);

            var rm = (Rm2Pro)devs.FirstOrDefault(d => d.DeviceType == DeviceType.Rm2Pro);

            if (rm == null)
            {
                throw new Exception("Rm2Pro Not Found");
            }
            Console.WriteLine($"Rm2Pro found at {rm.Host}");

            if (!await rm.Auth())
            {
                throw new Exception("Auth Failure");
            }

            Console.WriteLine("Learning command, press remote now");
            var command = await rm.LearnIRCommnad(null, CancellationToken.None);

            if (command == null || command.Length == 0)
            {
                throw new Exception("Failed to learn command");
            }

            Console.WriteLine("Command learned, press any key to send the command now...");
            Console.ReadKey();

            Console.WriteLine("Sending IR command");
            await rm.SendData(command);

            Console.WriteLine("IR command sent");
        }
Ejemplo n.º 5
0
        private static async Task <bool> RmTemperatureTest()
        {
            var devs = await Broadlink.Discover();

            var rm = (SharpBroadlink.Devices.Rm)devs[0];

            if (!await rm.Auth())
            {
                throw new Exception("Auth Failure");
            }

            var temp = await rm.CheckTemperature();

            return(true);
        }
Ejemplo n.º 6
0
        private static async Task <bool> AuthTest()
        {
            var devs = await Broadlink.Discover();

            foreach (var dev in devs)
            {
                // SmarPlug Sp2 cannot Auth
                if (dev.DeviceType == DeviceType.Sp2)
                {
                    continue;
                }

                await dev.Auth();
            }

            return(true);
        }
Ejemplo n.º 7
0
        private static async Task <bool> A1SensorTest()
        {
            var devs = await Broadlink.Discover(1);

            var dev = (SharpBroadlink.Devices.A1)devs.First(d => d.DeviceType == DeviceType.A1);

            // before Auth, cannot get values.
            var res0 = await dev.CheckSensorsRaw();

            var authRes = await dev.Auth();

            var res1 = await dev.CheckSensorsRaw();

            var res2 = await dev.CheckSensors();

            return(true);
        }
Ejemplo n.º 8
0
        private async void InitBlasters()
        {
            WLog("Scanning blasters...");
            Blasters.Clear();
            var devices = await Broadlink.Discover(5);

            WLog("Found: {0} online blasters", devices.Length.ToString());
            foreach (BlasterInfo bi in gs.Blasters)
            {
                bi.Online = false;
            }
            foreach (Rm Discovered in devices)
            {
                var Registered = GetBlasterByIP(Discovered.Host.Address.ToString());
                if (Registered != null)
                {
                    Blasters.Add(Registered.Name, Discovered);
                    WLog("Blaster '{0}' [{1}] online", Registered.Name, Registered.IP);
                }
                else
                {
                    WLog("Found new blaster [{0}]. Added to collection", Discovered.Host.Address.ToString());
                    BlasterInfo biNew = new BlasterInfo()
                    {
                        IP = Discovered.Host.Address.ToString(), Name = Discovered.Host.Address.ToString()
                    };
                    gs.Blasters.Add(biNew);
                    Registered = GetBlasterByIP(Discovered.Host.Address.ToString());
                    Blasters.Add(Registered.Name, Discovered);
                }
                Registered.Online = true;
            }
            // check for offline
            foreach (BlasterInfo bi in gs.Blasters)
            {
                if (!bi.Online)
                {
                    WLog("! Blaster '{0}' [{1}] offline", bi.Name, bi.IP);
                }
            }
        }
Ejemplo n.º 9
0
        private static async Task <bool> RmTest()
        {
            var devs = await Broadlink.Discover();

            var rm = (Rm)devs[0];

            if (!await rm.Auth())
            {
                throw new Exception("Auth Failure");
            }

            await rm.EnterLearning();

            var data1 = await rm.CheckData();

            var data2 = await rm.CheckData();

            await rm.SendData(data2);

            return(true);
        }
Ejemplo n.º 10
0
        private async Task TestAsync()
        {
            var devices = await Broadlink.Discover(5);

            var device = (SharpBroadlink.Devices.Rm)devices.First(d => d.Host.Address.ToString() == "192.168.100.44");

            await device.Auth();

            //device.

            // Enter Learning mode
            //await device.EnterLearning();

            //var signal = await device.CheckData();

            // Test signal
            var pronto = "0000 006d 0000 0022 00aa 00aa 0015 0040 0015 0015 0015 0040 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0040 0015 0015 0015 0040 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0040 0015 0015 0015 0040 0015 0015 0015 0040 0015 0015 0015 0040 0015 0015 0015 0015 0015 0040 0015 0015 0015 0040 0015 0015 0015 0040 0015 0015 0015 0040 0015 0737";
            var bytes  = Signals.String2ProntoBytes(pronto);

            await device.SendPronto(bytes);
        }
Ejemplo n.º 11
0
        private static async Task <bool> DiscoverTest()
        {
            var devs = await Broadlink.Discover(5);

            return(true);
        }
Ejemplo n.º 12
0
        //private async void LearnIr_Click(object sender, System.EventArgs e)
        //{
        //    var dev = (IDevice)devs[Devices.SelectedIndex];       //
        //    if (dev.DeviceType == DeviceType.Rm)
        //    {
        //        var device = (Rm)dev;
        //        await device.EnterLearning();
        //        var signal = await device.CheckData();
        //    }

        //    if (dev.DeviceType == DeviceType.Rm2Pro)
        //    {
        //        var device = (Rm2Pro)dev;
        //        await device.EnterLearning();
        //        var signal = await device.CheckData();
        //    }

        //}


        private async Task <bool> ScanForDevices()
        {
            this.devs = await Broadlink.Discover(1);

            if (devs.Length > 0)
            {
                Output.AppendLine(Color.White, devs.Length + " Devices Have been found...");

                foreach (var dev in devs)
                {
                    Devices.Items.Add(dev.DeviceType.ToString());
                    Output.AppendLine(Color.White, "     " + dev.DeviceType.ToString() + " (" + dev.Host + ")");
                }
            }
            else
            {
                Output.AppendLine(Color.Yellow, "Device not found!");
            }


            //var rm = (Rm)devs.FirstOrDefault(d => d.DeviceType == DeviceType.Rm);

            //if (rm == null)
            //    throw new Exception("Rm2Pro Not Found");
            //else Console.WriteLine($"Rm2Pro found at {rm.Host}");

            //if (!await rm.Auth())
            //    throw new Exception("Auth Failure");

            //Console.WriteLine("Starting RF frequency learning - press any button to continue, then, press and hold the remote button...");
            //while (!Console.KeyAvailable)
            //    await Task.Delay(TimeSpan.FromMilliseconds(100));
            //while (Console.KeyAvailable)
            //    Console.ReadKey(true);

            //var cancellationSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
            //byte[] command = null;
            //try
            //{
            //    command = await rm.LearnIRCommnad(cancellationSource.Token);

            //    if (command == null || command.Length == 0)
            //        throw new InvalidOperationException("Failed to learn RF command");
            //}
            //catch (TaskCanceledException)
            //{
            //    Console.WriteLine("Command learning cancelled");
            //    return false;
            //}

            //while (Console.KeyAvailable)
            //    Console.ReadKey(true);
            //Console.WriteLine();
            //Console.WriteLine($"RF Command learned [{command.Length}], press any key to trigger the command. Press ESC to exit...");
            //while (Console.ReadKey(true).Key != ConsoleKey.Escape)
            //{
            //    Console.Write("Sending RF command... ");
            //    await rm.SendData(command);
            //    Console.WriteLine("RF command sent");
            //}

            return(true);
        }
Ejemplo n.º 13
0
        private static async Task <bool> RmRfSignalTest()
        {
            Console.WriteLine("Searching for Rm2Pro devices...");
            var devs = await Broadlink.Discover(1);

            var rm = (Rm2Pro)devs.FirstOrDefault(d => d.DeviceType == DeviceType.Rm2Pro);

            if (rm == null)
            {
                throw new Exception("Rm2Pro Not Found");
            }
            Console.WriteLine($"Rm2Pro found at {rm.Host}");

            if (!await rm.Auth())
            {
                throw new Exception("Auth Failure");
            }

            Console.WriteLine("Starting RF frequency learning - press any button to continue, then, press and hold the remote button...");
            while (!Console.KeyAvailable)
            {
                await Task.Delay(TimeSpan.FromMilliseconds(100));
            }
            while (Console.KeyAvailable)
            {
                Console.ReadKey(true);
            }

            var cancellationSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));

            byte[] command = null;
            try
            {
                Action <LearnInstructions> learnInstructionHandler = instructions =>
                {
                    //Get description from the enum - any other text will do
                    var msg = instructions.GetType().GetField(instructions.ToString())
                              ?.GetCustomAttributes(typeof(DescriptionAttribute), true)
                              .OfType <DescriptionAttribute>()
                              .FirstOrDefault()
                              ?.Description
                              ?? instructions.ToString();

                    Console.WriteLine(msg);
                    Console.ReadKey(true);
                };

                command = await rm.LearnRfCommand(learnInstructionHandler, cancellationSource.Token, () => { Console.Write('.'); });

                if (command == null || command.Length == 0)
                {
                    throw new InvalidOperationException("Failed to learn RF command");
                }
            }
            catch (TaskCanceledException)
            {
                Console.WriteLine("Command learning cancelled");
                return(false);
            }

            while (Console.KeyAvailable)
            {
                Console.ReadKey(true);
            }
            Console.WriteLine();
            Console.WriteLine($"RF Command learned [{command.Length}], press any key to trigger the command. Press ESC to exit...");
            while (Console.ReadKey(true).Key != ConsoleKey.Escape)
            {
                Console.Write("Sending RF command... ");
                await rm.SendData(command);

                Console.WriteLine("RF command sent");
            }

            return(true);
        }
Ejemplo n.º 14
0
        private static async Task <bool> RmRfSignalTest()
        {
            Console.WriteLine("Searching for Rm2Pro devices...");
            var devs = await Broadlink.Discover(1);

            var rm = (Rm)devs.FirstOrDefault(d => d.DeviceType == DeviceType.Rm);

            if (rm == null)
            {
                throw new Exception("Rm2Pro Not Found");
            }
            else
            {
                Console.WriteLine($"Rm2Pro found at {rm.Host}");
            }

            if (!await rm.Auth())
            {
                throw new Exception("Auth Failure");
            }

            Console.WriteLine("Starting RF frequency learning - press any button to continue, then, press and hold the remote button...");
            while (!Console.KeyAvailable)
            {
                await Task.Delay(TimeSpan.FromMilliseconds(100));
            }
            while (Console.KeyAvailable)
            {
                Console.ReadKey(true);
            }

            var cancellationSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));

            byte[] command = null;
            try
            {
                command = await rm.LearnIRCommnad(cancellationSource.Token);

                if (command == null || command.Length == 0)
                {
                    throw new InvalidOperationException("Failed to learn RF command");
                }
            }
            catch (TaskCanceledException)
            {
                Console.WriteLine("Command learning cancelled");
                return(false);
            }

            while (Console.KeyAvailable)
            {
                Console.ReadKey(true);
            }
            Console.WriteLine();
            Console.WriteLine($"RF Command learned [{command.Length}], press any key to trigger the command. Press ESC to exit...");
            while (Console.ReadKey(true).Key != ConsoleKey.Escape)
            {
                Console.Write("Sending RF command... ");
                await rm.SendData(command);

                Console.WriteLine("RF command sent");
            }

            return(true);
        }