page_type | urlFragment | languages | products | description | ||
---|---|---|---|---|---|---|
sample |
iot-onboarding-rfcomm |
|
|
Create a simple solution to configure your Headless IoT Device (an IoT device without a display) to connect WiFi network through Bluetooth RFCOMM at startup. |
This sample shows how to join your Headless IoT Device (an IoT device without a display) to your WiFi network through Bluetooth RFCOMM.
- IoT Device (Server): A headed or headless IoT device with WiFi and Bluetooth capability running Windows 10.
- Manager Device (Client): A Windows 10 device with WiFi capability. It can be a PC or a even a Windows 10 Phone.
- Dev Machine: A laptop or desktop running Visual Studio 2017 or newer.
- An available WiFi network for onboarding your IoT device. WiFi network may provide Open Authentication or may be secured with WPA2-PSK authentication. Substitute a Personal Hotspot from a cell phone if desired.
There are two parts to this sample:
- Server - Running on the IoT Core device. This app (foreground or background) helps the Client connect your IoT Core device to a desired WiFi network.
- Client - Running on Windows 10 system (can be a PC or a phone). This app talks to the RFCOMM server on the IoT Core device to get its network list and sends the network information back to the Server to join a desired WiFi network.
The general communication flow between Client and Server
- Install a clean OS to your IoT Device. If using IoT Dashboard, deselect the "WiFi Network Connection" checkbox when preparing your SD Card.
- If your IoT Device needs an external Wi-Fi adapter, attach it now.
- Open the "Server" solution in Visual Studio 2017 on your Dev Machine. Build and deploy the Server app to your IoT Device.
- Set the Server App as the Default App. You may follow the directions here.
- Turn off the IoT Device for now.
- Ensure your WiFi router is on and configured to allow a network connection.
- On your Manager Device, go to Settings > About to get the Device Name under Device Specifications.
- Open the "Client" solution in Visual Studio 2017 on your Dev Machine.
- Open SampleConfiguration.cs, find the line
and replace
public const string TARGET_NAME = "<DESKTOP_NAME>";
<DESKTOP_NAME>
with Device Name of your Manager Device. - If you have only one network adapter on your IoT Device, skip to Step 5. Otherwise:
- Open NetworkManager.cs, and Search for
//TODO:
. - Edit the the following section to find your targeted network adatper:
//Get the first WiFi adatper from the list. //TODO: Edit this part if the system has more than one WiFi adatpers. m_wiFiAdapter = m_wiFiAdapterList[0];
- Open NetworkManager.cs, and Search for
- Build and deploy the Client app to your Manager Device.
-
Turn on Bluetooth on your Manager Device. Make sure it is discoverable by other devices.
-
Turn on your IoT Device.
-
On you Manager Device, wait for the incoming pairing notifcation from your IoT Device. Complete the Bluetooth pairing.
-
Once the Bluetooth connection between the IoT Device and Manager Device is successfully established, open the Client app on Manager Device. Press the Start button.
-
Select the IoT Device as the Target Device. The Client app will attempt to connect to the RFCOMM server on the selected device.
-
Once the RFCOMM session is established, the IoT Device will send a list of available network. On the Client app, select the desired WiFi network and enter the password. Click Connect to join the WiFi network.
-
Once the WiFi connection is established, the IoT Device will terminates the RFCOMM session. The network information is cached in the app. Next time when the Server apps starts, it will automatically connect to the last WiFi network it successfully connected to. If it fails to connect to the network, it will starts from Step 1 again.
Please refer to Bluetooth RFCOMM for more information on UWP implementation.
We use credential locker to securely cache WiFi network information. Please refer to Credential Locker for more information.