Unable to join Wifi for the first time using NEHotSpotConfiguration - ios

My iOS app needs to connect to an IOT device Wi-Fi, which does not have internet access.
iOS app already knows the ssid password of the iOT device Wi-Fi.
So I tried connecting to IOT device Wi-Fi using [NEHotspotConfigurationManager applyConfiguration] API.
The issue is that my app fails to join IOT device Wi-Fi in the first attempt. It connects on second attempt.
I have verified that IOT wifi was enabled and availble in Wi-Fi list in Settings > Wi-Fi
In code, error in applyConfiguration callback is nil, indicating success, so I check for connected Wi-FI SSID using CNCopyCurrentNetworkInfo
As SSID is different (other network) from my IOT device Wi-Fi SSID, it implies that iPhone is still connected to previosly connected Wi-Fi.
At around the same point, iOS shows the system dialog "Unable to connect to Wifi".
I checked for error in system logs while attempting connection, and found that the "wifid" process logs
"__WiFiDeviceManagerForcedAssociationCallback: failed to association error 2" for com.apple.SystemConfiguration subsystem
I tried this couple of times, and got this error in console logs everytime connection attempt failed.
App is able to connect on subsequent attempts.

I m doing this, too.
It seems like certificate problem.
Check this.

The [NEHotspotConfigurationManager applyConfiguration] API does not give a callback but the error. You might try to ping the server repeatedly for a certain timeout. Only if the ping is successful, is the wifi connected. Do you know the ip address of the IOT device?

Related

Can iOS application use cellular internet connection while doing "Wireless Accessory Configuration" through WiFi?

Is it possible to access internet (using cellular) during WiFi device configuration using Apple's "Wireless Accessory Configuration" feature?
This device would create the WiFi network and we would need to get data from the server while configurating the device.
Specifications:
Would iOS automatically use cellular to connect to the internet if there is no internet connection through WiFi? (But still keeps WiFi connection with device)
Or is it possible to programmatically switch between connections? For example: Get data from device through WiFi, send data to server through cellular, get data from server through cellular and then configurate device through WiFi.
Some other way to accomplish this?
From Apple Developers Forum:
eskimo:
"iOS keeps WWAN active even when Wi-Fi is fully functioning. That’s done because important system services, like push notifications, always run over WWAN where possible.
So, what you’re asking about is the switch of the default route. In general, iOS only switches the default route to Wi-Fi when the Wi-Fi is fully up and running. That means that WWAN should remain the default route during the WAC process."
https://forums.developer.apple.com/thread/46528

How to Provide and Check Wifi Credentials for Headless Device

I want to understand how the AP provisioning works on a headless device, specifically for IoT applications (I'm developing on a Texas Instruments CC3200). It seems that the universally accepted method of provisioning an IoT device is for the device to act as an AP then the user connects to it in order to send the Wifi AP credentials via smartphone. I'm assuming this could be done via UDP or TCP.
Most of these IoT modules can act as an Access Point OR a Station but not both at the same time. So how does the device know that the Wifi credentials are correct? It must have to shut down the AP that it creates to try and connect to the user's Wifi, right? If the credentials are NOT correct, how does it let the user know on the smartphone side? At this point, the device's AP doesn't exists and the user would have to jump back on it again. What's really happening there?
So how does the device know that the Wifi credentials are correct ?
It have to try if using those credentials AP association is possible. For successful connection SSID, passphrase, encryption type have to be provided. All or some of those information can be already in device memory ie. application can connect only to known SSID.
It must have to shut down the AP that it creates to try and connect to the user's Wifi, right?
Yes. In case of TI CC3200 you can switch mode while application is running.
If the credentials are NOT correct, how does it let the user know on the smartphone side?
It is highly implementation depending. For example, if your IoT device cannot obtain outside world it can switch back to AP mode, what can be detected on the smartphone side. Other solution is that you can send and receive data while in AP mode so it is possible to write server application that will inform smartphone application about the connection state.
At this point, the device's AP doesn't exists and the user would have to jump back on it again. What's really happening there?
Not sure if understand this question. As I mentioned above IoT device knows the state of AP association (TI CC3200 SDK return known values for wide range of errors), if IoT device cannot connected as station using provided credentials it should rollback to AP mode.

Reachability reports Wifi when HotSpot is On via USB

When I tether my mobile network to laptop with Hotspot on iPhone and test for Reachability's currentReachabilityStatus it reports ReachableViaWiFi where neither Wifi is open nor is it sharing mobile network via Wifi.
I know even with this, it shows correct information on internet connectivity but the nature of my app requires exact information on whether Wi-fi is connected or not so its not the issue to determine internet connectivity but more of Wi-fi reachability.
x----x----x----x----x----x----x
EDIT:
Infact it fails if there is no device connected on USB. Only reports ReachableViaWiFi when a machine is using its internet via USB.
Open this post: detect hotspot enabling in iOS with private api's
Maybe enumerating network interfaces will let you discover the fact that connection is actually a tethered cellular network.
Don't worry that title includes private API - the solution contains also a way to this without using private API.

"Internet connection is offline" when connecting to AP without internet access - WiFi off/on fixes

BACKGROUND
We're trying to use an iOS app running on iPhone/iPad to give WiFi credentials to an embedded device (using an ARM SoC running Linux). The embedded device starts an AP (access point), we instruct the user to connect to this AP and then the user submits their WiFi credentials. After WiFi credentials are received the device drops the AP and connects to the WiFi the user gave credentials for.
Initially, we try to hit a PHP page to get the list of WiFi networks the embedded device can see.
ISSUE
We instruct the user to join XYZ network (in iOS they must background the app, go into settings and switch to our WiFi network). We listen for an app resumed from background notification, check the devices current ESSID (ensure its our AP ESSID) and try to hit a PHP page to receive the list of WiFi networks. Often, this connection fails reports "The internet connection appears to be offline" (or something of that nature).
We currently have a stop gap when this happens telling the user to toggle their WiFi off and then back on (in settings). The device will reconnect to our AP as it's the most recently connected network. This ALWAYS fixes the issue, we've never had to toggle the WiFi twice in order to reach the PHP page on the device. Please tell me any possible way we can avoid having to instruct the user to toggle WiFi and still access PHP pages on the embedded device.
Note: when we're connected to the AP (whether this bug is active or fixed) the device DOES NOT show the WiFi icon in the status bar. We assume this is because the AP doesn't have a viable connection to the internet (can only access pages served by the embedded device). We've been testing on a device that has LTE cellular access, but the error still says "Internet connection appears to be offline".
Obviously we have a DHCP server running on the embedded device.
It's looking like this was caused by an omission in our dhcpd.conf file.
This omission was causing iOS to believe the connection was unviable.
We added the following line and are getting much better results:
option domain-name-servers 10.10.10.1;

Force iOS device app to talk through the local WIFI network

I'm building an application that will run in a museum with a local area wifi network without internet access, for some strange reason I'm not able to fully "join" this network with an iOS device. Enabling internet access on this network solves the problem...
The network should provide only a web server and a DNS server, the access point has a DHCP server, android devices can connect to the network without problems.
When I try to join the network with the device it remains in a "spinning wheel" status, the DHCP server log on the debian server says it has assigned an address to the iOS device, and if I check for the wifi address with an application (like iSys o SBSettings) I see the WIFI DHCP assigned address.
But when my app (or safari) tries to connect to the web server the request is routed through the 3G connection and not completed.
In my app I'm using the standard "Reachability" framework from Apple to check the reachability of a provided host name through the wifi connection and I get 0 on the SCNetworkReachabilityFlags mask....
I'm quite sure the problem is due to the fact iOS (5.1 in my case) tries to check the reachability for some "standard" host in the network, before routing traffic through the WIFI connection.
Anyone knows what an iOS device do to "validate" a WIFI network? I can add hostnames or simple dummy services to the server machine if this can help me connect the device to a LOCAL-only network :)
It seems that iOS doesn't like to join networks without a gateway, also if the network is local you have to setup a correct gateway address.
Setting the gateway as the server itself did the trick and the device started to route TCP/IP over my local area wifi network.

Resources