예제 #1
0
파일: LEDBridge.cs 프로젝트: edd46/miled
        public static async Task <Dictionary <string, string> > FindBridgesAsync()
        {
            var bridges = new Dictionary <string, string>();
            var client  = new LEDAdminClient("10.10.100.255");

            try
            {
                for (var i = 0; i < 10; i++)
                {
                    await client.SendDataAsync("Link_Wi-Fi");
                }
                var data = string.Empty;
                while (!string.IsNullOrEmpty(data = await client.ReceiveDataAsync()))
                {
                    var ma = _IPIdRegEx.Match(data);
                    if (ma.Success)
                    {
                        var id = ma.Groups["id"].Value;
                        if (!bridges.ContainsKey(id))
                        {
                            bridges.Add(id, ma.Groups["ip"].Value);
                        }
                    }
                }
            }
            finally
            {
                client.Close();
            }
            return(bridges);
        }
예제 #2
0
파일: LEDBridge.cs 프로젝트: edd46/miled
        private static async Task <bool> HandshakeAsync(LEDAdminClient client)
        {
            await client.SendDataAsync("Link_Wi-Fi");

            var ok   = false;
            var data = string.Empty;

            while (!string.IsNullOrEmpty(data = await client.ReceiveDataAsync()))
            {
                var ma = _IPIdRegEx.Match(data);
                if (ma.Success)
                {
                    ok = true;
                    break;
                }
            }
            if (ok)
            {
                await client.SendDataAsync("+ok");

                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #3
0
파일: LEDBridge.cs 프로젝트: edd46/miled
        public static async Task <string> VersionAsync(string bridgeIP)
        {
            var client = new LEDAdminClient();

            try
            {
                if (await HandshakeAsync(client))
                {
                    await client.SendDataAsync("AT+VER\r\n");

                    var data = string.Empty;
                    while (!string.IsNullOrEmpty(data = await client.ReceiveDataAsync()))
                    {
                        var ma = _versionRegEx.Match(data);
                        if (ma.Success)
                        {
                            return(ma.Groups["ver"].Value);
                        }
                    }
                }
            }
            finally
            {
                client.Close();
            }
            return(string.Empty);
        }
예제 #4
0
파일: LEDBridge.cs 프로젝트: edd46/miled
        public static async Task <List <LEDHotspot> > ListHostspotsAsync(string bridgeIP)
        {
            var hostspots = new List <LEDHotspot>();
            var client    = new LEDAdminClient();

            try
            {
                if (await HandshakeAsync(client))
                {
                    await client.SendDataAsync("AT+WSCAN\r\n");

                    await Task.Delay(1000);

                    var data = string.Empty;
                    while (!string.IsNullOrEmpty(data = await client.ReceiveDataAsync()))
                    {
                        foreach (var s in data.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            var ma = _hotspotRegEx.Match(s);
                            if (ma.Success)
                            {
                                var id      = ma.Groups["ssid"].Value;
                                var hotspot = hostspots.Find((h) => { return(h.BSSID == id); });
                                if (hotspot == null)
                                {
                                    hotspot = new LEDHotspot()
                                    {
                                        BSSID    = ma.Groups["ssid"].Value,
                                        Channel  = byte.Parse(ma.Groups["ch"].Value),
                                        DPID     = ma.Groups["dpid"].Value,
                                        ExtCH    = ma.Groups["extch"].Value,
                                        NT       = ma.Groups["nt"].Value,
                                        Security = ma.Groups["security"].Value,
                                        Signal   = byte.Parse(ma.Groups["signal"].Value),
                                        SSID     = ma.Groups["ssid"].Value,
                                        WPS      = ma.Groups["wps"].Value
                                    };
                                    hostspots.Add(hotspot);
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                client.Close();
            }
            return(hostspots);
        }
예제 #5
0
파일: LEDBridge.cs 프로젝트: edd46/miled
        public static async Task <bool> SetupHotspotAsync(string bridgeIP, string ssid, string password)
        {
            var client = new LEDAdminClient();

            try
            {
                if (await HandshakeAsync(client))
                {
                    await client.SendDataAsync(string.Format("AT+WSSSID={0}\r\n", ssid));

                    if (await ReceiveOkAsync(client))
                    {
                        await client.SendDataAsync(string.Format("AT+WSKEY={0},{1},{2}\r\n", "WPA2PSK", "AES", password));

                        if (await ReceiveOkAsync(client))
                        {
                            await client.SendDataAsync(string.Format("AT+WMODE=STA\r\n", ssid));

                            if (await ReceiveOkAsync(client))
                            {
                                await client.SendDataAsync(string.Format("AT+Z\r\n", ssid));

                                if (await ReceiveOkAsync(client))
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                client.Close();
            }
            return(false);
        }
예제 #6
0
파일: LEDBridge.cs 프로젝트: edd46/miled
        private static async Task <bool> ReceiveOkAsync(LEDAdminClient client)
        {
            var s = await client.ReceiveDataAsync();

            return(s.Contains("+ok"));
        }
예제 #7
0
 private static async Task<bool> ReceiveOkAsync(LEDAdminClient client)
 {
     var s = await client.ReceiveDataAsync();
     return s.Contains("+ok");
 }
예제 #8
0
 private static async Task<bool> HandshakeAsync(LEDAdminClient client)
 {
     await client.SendDataAsync("Link_Wi-Fi");
     var ok = false;
     var data = string.Empty;
     while (!string.IsNullOrEmpty(data = await client.ReceiveDataAsync()))
     {
         var ma = _IPIdRegEx.Match(data);
         if (ma.Success)
         {
             ok = true;
             break;
         }
     }
     if (ok)
     {
         await client.SendDataAsync("+ok");
         return true;
     }
     else
     {
         return false;
     }
 }
예제 #9
0
 public static async Task<bool> SetupHotspotAsync(string bridgeIP, string ssid, string password)
 {
     var client = new LEDAdminClient();
     try
     {
         if (await HandshakeAsync(client))
         {
             await client.SendDataAsync(string.Format("AT+WSSSID={0}\r\n", ssid));
             if (await ReceiveOkAsync(client))
             {
                 await client.SendDataAsync(string.Format("AT+WSKEY={0},{1},{2}\r\n", "WPA2PSK", "AES", password));
                 if (await ReceiveOkAsync(client))
                 {
                     await client.SendDataAsync(string.Format("AT+WMODE=STA\r\n", ssid));
                     if (await ReceiveOkAsync(client))
                     {
                         await client.SendDataAsync(string.Format("AT+Z\r\n", ssid));
                         if (await ReceiveOkAsync(client))
                         {
                             return true;
                         }
                     }
                 }
             }
         }
     }
     finally
     {
         client.Close();
     }
     return false;
 }
예제 #10
0
 public static async Task<string> VersionAsync(string bridgeIP)
 {
     var client = new LEDAdminClient();
     try
     {
         if (await HandshakeAsync(client))
         {
             await client.SendDataAsync("AT+VER\r\n");
             var data = string.Empty;
             while (!string.IsNullOrEmpty(data = await client.ReceiveDataAsync()))
             {
                 var ma = _versionRegEx.Match(data);
                 if (ma.Success)
                     return ma.Groups["ver"].Value;
             }
         }
     }
     finally
     {
         client.Close();
     }
     return string.Empty;
 }
예제 #11
0
 public static async Task<List<LEDHotspot>> ListHostspotsAsync(string bridgeIP)
 {
     var hostspots = new List<LEDHotspot>();
     var client = new LEDAdminClient();
     try
     {
         if (await HandshakeAsync(client))
         {
             await client.SendDataAsync("AT+WSCAN\r\n");
             await Task.Delay(1000);
             var data = string.Empty;
             while (!string.IsNullOrEmpty(data = await client.ReceiveDataAsync()))
             {
                 foreach (var s in data.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries))
                 {
                     var ma = _hotspotRegEx.Match(s);
                     if (ma.Success)
                     {
                         var id = ma.Groups["ssid"].Value;
                         var hotspot = hostspots.Find((h) => { return h.BSSID == id; });
                         if (hotspot == null)
                         {
                             hotspot = new LEDHotspot()
                             {
                                 BSSID = ma.Groups["ssid"].Value,
                                 Channel = byte.Parse(ma.Groups["ch"].Value),
                                 DPID = ma.Groups["dpid"].Value,
                                 ExtCH = ma.Groups["extch"].Value,
                                 NT = ma.Groups["nt"].Value,
                                 Security = ma.Groups["security"].Value,
                                 Signal = byte.Parse(ma.Groups["signal"].Value),
                                 SSID = ma.Groups["ssid"].Value,
                                 WPS = ma.Groups["wps"].Value
                             };
                             hostspots.Add(hotspot);
                         }
                     }
                 }
             }
         }
     }
     finally
     {
         client.Close();
     }
     return hostspots;
 }
예제 #12
0
 public static async Task<Dictionary<string, string>> FindBridgesAsync()
 {
     var bridges = new Dictionary<string, string>();
     var client = new LEDAdminClient("10.10.100.255");
     try
     {
         for (var i = 0; i < 10; i++)
         {
             await client.SendDataAsync("Link_Wi-Fi");
         }
         var data = string.Empty;
         while (!string.IsNullOrEmpty(data = await client.ReceiveDataAsync()))
         {
             var ma = _IPIdRegEx.Match(data);
             if (ma.Success)
             {
                 var id = ma.Groups["id"].Value;
                 if (!bridges.ContainsKey(id))
                     bridges.Add(id, ma.Groups["ip"].Value);
             }
         }
     }
     finally
     {
         client.Close();
     }
     return bridges;
 }