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); }
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); } }
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); }
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); }
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); }
private static async Task <bool> ReceiveOkAsync(LEDAdminClient client) { var s = await client.ReceiveDataAsync(); return(s.Contains("+ok")); }
private static async Task<bool> ReceiveOkAsync(LEDAdminClient client) { var s = await client.ReceiveDataAsync(); return s.Contains("+ok"); }
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; } }
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; }
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; }
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; }
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; }