Sunday, 26 May 2019

Setup a headless device to connect to a wifi network

I have a device with no screen + a microcontroller + a wifi module.

So far so good but basically I'd like to setup my device so it can connect to a wifi network, so I made an app to do that.

The strategy is:

  • put the device in wifi AP mode with a custom ssid like "Device XXXX"
  • connect to this ssid "Device XXXX"
  • Ask the user for its home wifi credentials
  • send the credentials to the device (for example using http) -> POST http://x.x.x.x/wifi_creds "Home" "homepassword"
  • poll the device to check whether it could connect to the "Home" network -> GET http://x.x.x.x/conn_status
  • Once it's connected, stop the AP mode -> POST http://x.x.x.x/wifi_ap_mode 0

This works pretty well, but it requires the user to manually connect to the "Device XXXX" ssid. And actually on Android I can make things even easier by connecting automatically to this ssid, but I need to find the ssid first.

So my idea was to scan all the ssids and to connect to the first one that matches the pattern /^Device [0-9a-zA-Z]{4}/ (like Device 1234).

However this doesn't look like a good way to find a hotspot, and there might be a better way. Also, I don't want to give it a default name as it could conflict with another ssid.

Is there another way to find my device (or my device ssid) without this trick?

I know that Google home is able to connect to a Chromecast allowing you to configure it while the Chromecast is in AP mode with a ssid that looks like "Chromecast XXXX" (when the bluetooth is disabled), and I'm not sure how they do it



from Setup a headless device to connect to a wifi network

No comments:

Post a Comment