locked
WiFi and Connection Manager RRS feed

  • Question

  • Hi,
    I'm trying to make my app sending data through GPRS and Wifi. For this purpose I'm trying to use Connection Manager and I support with this tutorial: http://msdn.microsoft.com/en-us/library/bb840031.aspx. Everything is fine my phone (Samsung Omnia sgh-i900) connects to net with GRPS but I want to force it to make connection with WiFi. How can I make it ? I try to use ConnMgrEnumDestinations and ConnMgrMapConRef functions but I got stuck.Is there any way to chose wifi and then kind of Messagebox appears to enter the key and so on ?
    I don't mentioned that I tried to use Opennetcf but NetworkInterfaces hasn't found on my phone are only Etherent type. When I use obsolete class like AccessPoint from OpenNETCF.Net.AccessPoint I'm able to find APs but I can't connect cause I have error in adapter.SetWirelessSettingsAddEx() function.
                foreach (WirelessNetworkInterface wni in NetworkInterface.GetAllNetworkInterfaces())
                {
                 MessageBox.Show(wni.Name);
                }
    Something like this return "Ethernet" twice, and this:
    ...
    OpenNETCF.Net.EAPParameters eapp = new OpenNETCF.Net.EAPParameters();
    eapp.Enable8021x = true;
    ...
    bool polacz = adapter.SetWirelessSettingsAddEx(SSID, true, key, 1, AuthenticationMode.WPAPSK, WEPStatus.WEPEnabled, eapp);
                                
    return always error, I've tried every possible combination AuthenicationMode, WEPStatus or key.
    So I try almost everything (i think) and I really need to make it work, please help me!!

    Sunday, November 15, 2009 12:03 AM

Answers

  • I know this problem. I often had an exception: "Unable to clear adapter's NDIS cache" when I called NearByAccessPoints. I had this problem only on my Samsung device and not on other devices.
    So I did something like you:


    public List<AccessPoint> getNearByAccessPoints()
    {
       List<AccessPoint> listSFRNearByAP = new List<AccessPoint>();            
                
       WirelessZeroConfigNetworkInterface wzc = findWirelessAdapter();
       if (wzc != null)
       {
          try
          {
             AccessPointCollection apColl = wzc.NearbyAccessPoints;
             int cpt = 0;
             while (apColl.Count < 1 && cpt < 5)
             {
                apColl = wzc.NearbyAccessPoints;
                Thread.Sleep(1000);
                cpt++;
             }
    
             foreach (OpenNETCF.Net.NetworkInformation.AccessPoint ap in apColl)
             {
                listSFRNearByAP.Add(ap);
             }
          }
          catch (Exception ex){ } 
       }  
            
       return listSFRNearByAP;
    }
    

    Like you, I loop on "NearbyAccessPoints" and it's finally work.

    Hope I help.


    • Marked as answer by warrentang Friday, November 20, 2009 6:15 AM
    Sunday, November 15, 2009 10:12 PM

All replies

  • Hi,

    If you manually configure the WiFi connection, can you get connected to the Internet?

    In regard to using the SDF, you may be interested in the sample code below, although it doesn't configure the connection for you, it provides a starting point :-

    http://www.smartmobiledevice.co.uk/Projects/WifiDiscoveryTester.zip

    Hope this helps.

    Paul Diston
    http://www.smartmobiledevice.co.uk/
    Sunday, November 15, 2009 9:23 AM
  • Yes, I can connect to the Internet when I manually configure WiFi.
    Unfortunately this code doesn't help, cause like I've mentioned earlier I was trying Opennetcf too and this line of code:

    foreach (OpenNETCF.Net.NetworkInformation.INetworkInterface currentNetworkInterface in OpenNETCF.Net.NetworkInformation.WirelessZeroConfigNetworkInterface.GetAllNetworkInterfaces())
                    
    return in my phone (Samsung sgh i900) two NetworkInterfaces but all are ethernet type. So this condition :

    if (currentNetworkInterface is OpenNETCF.Net.NetworkInformation.WirelessZeroConfigNetworkInterface)

    never works. That's why I'm trying to use Connection Manager.
    Sunday, November 15, 2009 1:07 PM
  • Hi przemast, Maybe your wifi firmware is not WZC-Compatible. I work on Samsung Omina II (Samsung I8000) and this code work for me. Try it and let me know if "findWirelessAdapter" return null or non-null object
    using OpenNETCF.Net.NetworkInformation;
            public WirelessZeroConfigNetworkInterface findWirelessAdapter()
            {
                foreach (INetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
                {
                    if (ni is WirelessNetworkInterface)
                    {
                        if (ni is WirelessZeroConfigNetworkInterface)
                        {
                            return ni as WirelessZeroConfigNetworkInterface;                        
                        }                    
                    }
                }
                return null;
            }
    I use OpenNETCF version 2.3.0.39
    Sunday, November 15, 2009 4:25 PM
  • I'm quite shocked cause I've tried similar code and always return me null, your code return me one interfaces, at last :] So I try to find APs by using NearbyAccessPoints but it returns me mostly null sometimes can find AP. So i decide to make something like that:
    while (counter < 10)
    {
    if (found == false)
    {

    if (wzci.NearbyAccessPoints.Count > 0)
    {
    try
    {
    for (int i = 0; i < wzci.NearbyAccessPoints.Count; i++)
    {
    listaAPZnalezionych.Add(wzci.NearbyAccessPoints[i].Name.ToString());
    found = true;
    MessageBox.Show(wzci.NearbyAccessPoints[i].Name.ToString());
    }
    }
    catch (Exception ee)
    {
    MessageBox.Show("Error");
    }

    }
    counter++;
    }
    else
    break;

    but when NearbyAccessPoints is bigger then 0 then
    wzci.NearbyAccessPoints[i].Name
    returns error (doesn't see any AP).
    Any idea why it (doesn't) works so strange ?
    Sunday, November 15, 2009 8:27 PM
  • I know this problem. I often had an exception: "Unable to clear adapter's NDIS cache" when I called NearByAccessPoints. I had this problem only on my Samsung device and not on other devices.
    So I did something like you:


    public List<AccessPoint> getNearByAccessPoints()
    {
       List<AccessPoint> listSFRNearByAP = new List<AccessPoint>();            
                
       WirelessZeroConfigNetworkInterface wzc = findWirelessAdapter();
       if (wzc != null)
       {
          try
          {
             AccessPointCollection apColl = wzc.NearbyAccessPoints;
             int cpt = 0;
             while (apColl.Count < 1 && cpt < 5)
             {
                apColl = wzc.NearbyAccessPoints;
                Thread.Sleep(1000);
                cpt++;
             }
    
             foreach (OpenNETCF.Net.NetworkInformation.AccessPoint ap in apColl)
             {
                listSFRNearByAP.Add(ap);
             }
          }
          catch (Exception ex){ } 
       }  
            
       return listSFRNearByAP;
    }
    

    Like you, I loop on "NearbyAccessPoints" and it's finally work.

    Hope I help.


    • Marked as answer by warrentang Friday, November 20, 2009 6:15 AM
    Sunday, November 15, 2009 10:12 PM
  • Hi again,
    sorry that I didn't answer earlier but now I've full of work and I don't have time to come back to this topic. Anyway I'm really grateful for your help  and I'm going to test this it as soon as possible. I hope if I'll have troubles yet you'll be still so helpful ?
    Wednesday, November 18, 2009 7:43 PM
  • Of course,

    Best regards.
    Thursday, November 19, 2009 7:47 AM
  • I just experimented the same problem (ie. not finding a WZCNetworkInterface) and found the reason: if the WiFi interface is down, then it doesn't find it and the interface is considered as an Ethernet one.
    Wednesday, August 4, 2010 12:50 PM
  • Thanks Paul.

    it's very helpful


    Thursday, December 6, 2012 11:23 AM