Click here to Skip to main content
16,012,468 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
public void FindNetworks()
        {
            List<string> deviceList=new List<string>();
            
            try
            {

               // for (int i = 0; i < 1; i--)
               //{

                    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);
                                 //   _odbContext.InsertHistory(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.Entry(device).State = EntityState.Modified;
                                            dbContext.SaveChanges();
                                            //dbContext.SaveChangesAsync();

                                        }

                                    }
                                

                                    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());
            }
Posted
Updated 3-Nov-15 21:16pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900