3 Replies
      Latest reply on Dec 3, 2019 7:41 AM by meaton
      tattniko Level 1 Level 1 (0 points)

        Hi,

         

        I have the following use case & problem:

        - iPhone is connected to the users home network (known by iOS/iPhone itself). On this home network, a 1st IOT device is present.

        - To be able to configure a 2the IOT device, I let my app disconnect from the home network, and connect to a temporary access point set up by that 2th IOT device.

        - When configuration is done, i remove the access point configuration.

        - At this point, the iPhone tries to connect again to a known wifi network, but i can not specify to which network it should return to. Sometimes it connects to another known wifi, which is not the right one. (It should return to the users home network, to connect with the 1st IOT device again).

         

        So my question: How can i ensure that the iPhone picks a certain known wifi network instead of some random known network after disconnecting from the temporary access point. (I know the ssid of the right network in my app)

         

        I've tried with the applyConfiguration method with a configuration with only the ssid, but that is interpreted as a new wifi without password...

         

        Thank you in advance

        • Re: How to connect to a certain known wifi network programmatically
          meaton Apple Staff Apple Staff (20 points)

          One approach to consider would be using the NEHotspotConfiguration.  Using this API you can define a specific network configuration and apply it or remove it at will. So in this particular scenario you could disconnect from the IoT's temporary access point and then use NEHotspotConfigurationManager to apply a specific network configuration (your home network) you created with NEHotspotConfiguration.

           

          For example:

           

          let networkHotspot = NEHotspotConfiguration(ssid: ssidName, passphrase: password, isWEP: false)
          
          ...
          
          NEHotspotConfigurationManager.shared.apply(networkHotspot) { (error) in
            // Act upon setup connection to the hotspot
          }
            • Re: How to connect to a certain known wifi network programmatically
              tattniko Level 1 Level 1 (0 points)

              But that would require the user to enter his home network password in my app? That's not very user friendly, because the iPhone already knows that network.

               

              I indeed use the NEHotspotConfigurationManager for applying & removing the IOT's temporary wifi configuration. But the question is, after removing the temporary network configuration, can i control to which known wifi network it returns to? I don't want to ask the user for the home network password in my app...

                • Re: How to connect to a certain known wifi network programmatically
                  meaton Apple Staff Apple Staff (20 points)

                  I see, the Wi-Fi antenna will always try to connect to best available known network to provide the best possible connectivity for the device.  If you are seeing your device connect to another SSID other than the one desired, check the RSSI (signal strength) and this might provide insight into why the device is connecting to this network.  To avoid this you could investigate setting up a Keychain accounts for known/trusted networks.  That way these accounts could be used by `NEHotspotConfiguration` to automatically configure the network of your choosing.  This could be a user managed set of networks and would not have to be done each time a user wants to join the network.  One disadvantage to be aware of with this solution is that the user would need to update the password if the network password changed, but that would have to be done anyway even if there was an API to join via SSID only.

                   

                  -----

                   

                  Matt Eaton

                  DTS Engineering, CoreOS

                  meaton3 at apple.com