Hi,
I am using NativeWifi dll for finding devices connected to a wifi network. I can find list of connected devices. But, In case of iphone, if I press power button of iphone and put phone in idle mode , I get iphone as disconnected from wifi but actually it is connected to wifi
If I press sleep button of android mobile, it remains shown as connected with nativewifi.
Anyone faced such issue? or any possible solution?
Code to find wifi devices is below:
public void FindNetworks()
{
List<string> deviceList=new List<string>();
try
{
int networkID = 0;
WlanClient client = new WlanClient();
string networkName = string.Empty;
string signalQuality = string.Empty;
foreach (WlanClient.WlanInterface wlanIface in client.Interfaces)
{
Wlan.WlanAvailableNetwork[] networks = wlanIface.GetAvailableNetworkList(0);
foreach (Wlan.WlanAvailableNetwork network in networks)
{
Wlan.Dot11Ssid ssid = network.dot11Ssid;
networkName = Encoding.ASCII.GetString(ssid.SSID, 0, (int)ssid.SSIDLength);
networkName = networkName.Replace("'", "");
signalQuality = network.wlanSignalQuality.ToString();
networkID = _odbContext.InsertNetworks(1, networkName, signalQuality);
if (network.profileName == wlanIface.CurrentConnection.profileName)
{
deviceList = GetConnectedDeviceList();
if (deviceList.Count > 0)
{
bool result = _odbContext.UpdateConnectDisconnectStatus(deviceList);
foreach (string devicename in deviceList.ToList())
{
string maac = "";
var deviceMaac = dbContext.DevicesDetails.Where(x => x.DeviceName == devicename).FirstOrDefault();
bool result1 = _odbContext.InsertNetworkDevices(1, networkID, devicename, deviceMaac.DeviceMaac);
bool result2 = _odbContext.InsertEmployeesStatus(devicename, deviceMaac.DeviceMaac, 1);
DeviceHistory deviceHistory = dbContext.DeviceHistories.Where(x => x.DeviceName == devicename && x.DisconnectedAt == null).FirstOrDefault();
if (deviceHistory == null)
{
lstNewlyConnectedDeviceName.Add(devicename);
DeviceHistory odh = new DeviceHistory();
odh.ConnectedAt = DateTime.Now;
odh.DeviceName = devicename;
dbContext.DeviceHistories.Add(odh);
dbContext.SaveChanges();
}
}
IQueryable<devicehistory> lstDeviceHistoryForConnected = dbContext.DeviceHistories.Where(x => x.DisconnectedAt == null);
foreach (DeviceHistory device in lstDeviceHistoryForConnected.ToList())
{
if (!deviceList.Contains(device.DeviceName))
{
device.DisconnectedAt = DateTime.Now;
dbContext.SaveChanges();
}
}
deviceList.Clear();
}
}
}
break;
}
if (networkID == 0)
{
_oException.UserExcepMessage(1, "FindNetworks()", "No Networks Found. Please check your router.");
}
}
catch (Exception ex)
{
_oException.UserExcepMessage(1, "FindNetworks()", "Exception = " + ex.Message.ToString());
}