After experiencing Chromecast Setup Discovery, I looked for a way to replicate the approach on NodeMCU. Found it! Now you can reconfigure your IoT project at runtime, just like the pros.
One of my Christmas gifts this year was a Chromecast. As you probably know, Chromecast is a media streaming device that plugs into the HDMI port on a television. Because it also connects to your home network, you can use a phone, tablet or computer to stream content to your TV. I set it up quickly and it works great.
After you plug the Chromecast into your TV, you use a mobile app or browser to connect it to your secure network. The app somehow finds the device, then prompts you to select your network and enter a password. It struck me that this was a seamless and fast way to discover an IoT device and configure it for the local network. But, how does the setup work before your have actually got the Chromecast device on your network?
Here’s how Chromecast Setup Discovery works. On first boot, it creates a WiFi temporary access point. In other words, its own network. As long as the app is running on a WiFi enabled phone or computer, it is able to search for and connect to the Chromecast. It then presents you with a login screen to select your home network. Voila. You are able to configure Chromecast without having a keyboard or fiddling around with WPS on your WiFi gateway. Once you enter the password, Chromecast switches from Access Point to Station Mode and logs onto your WAN.
(If you are interested, you can use a WiFi sniffer on your phone to see the temporary network. It disappears after you configure the Chromecast.)
Chromecast Setup Discovery and Configure Library for your NodeMCU
I was thinking this would be a great way to be able to setup your NodeMCU whenever you change networks. Normally, folks will hard code their SSID and Password into the NodeMCU firmware. Luckily, a NodeMCU user has already written a library to replicate the approach used by Chromecast.
Just download WiFiManager to your Arduino IDE and use the examples to modify your program. When you run your NodeMCU, here is what happens.
- NodeMCU boots in Station Mode and tries to connect to a previously configured network. If that fails…
- It will switch to Access Point Mode and create a web server.
- Then you can use any WiFi device to log in to this temporary Access Point and configure the NodeMCU for a new LAN.
- After you enter your password, NodeMCU will reboot in Station Mode and connect to the new network.
Good stuff. Something you can use in your IoT projects.