/// <summary> /// Event handler for Stations connecting or Disconnecting /// </summary> /// <param name="NetworkIndex">The index of Network Interface raising event</param> /// <param name="e">Event argument</param> private static void NetworkChange_NetworkAPStationChanged(int NetworkIndex, NetworkAPStationEventArgs e) { Debug.WriteLine($"NetworkAPStationChanged event Index:{NetworkIndex} Connected:{e.IsConnected} Station:{e.StationIndex} "); // if connected then get information on the connecting station if (e.IsConnected) { WirelessAPConfiguration wapconf = WirelessAPConfiguration.GetAllWirelessAPConfigurations()[0]; WirelessAPStation station = wapconf.GetConnectedStations(e.StationIndex); string macString = BitConverter.ToString(station.MacAddress); Debug.WriteLine($"Station mac {macString} Rssi:{station.Rssi} PhyMode:{station.PhyModes} "); connectedCount++; // Start web server when it connects otherwise the bind to network will fail as // no connected network. Start web server when first station connects if (connectedCount == 1) { // Wait for Station to be fully connected before starting web server // other you will get a Network error Thread.Sleep(2000); server.Start(); } } else { // Station disconnected. When no more station connected then stop web server if (connectedCount > 0) { connectedCount--; if (connectedCount == 0) { server.Stop(); } } } }
/// <summary> /// Find the Wireless AP configuration /// </summary> /// <returns>Wireless AP configuration or NUll if not available</returns> public static WirelessAPConfiguration GetConfiguration() { NetworkInterface ni = GetInterface(); return(WirelessAPConfiguration.GetAllWirelessAPConfigurations()[ni.SpecificConfigId]); }