Arduino Project Hub
Project tutorial

Get Connected! WiFi Registration Using AP Mode! © Apache-2.0

Stop reflashing your devices everytime the WiFi password changes! Learn how to use anduinoWiFi and AP mode to initiate WiFi registration!

  • 1,495 views
  • 0 comments
  • 16 respects

Components and supplies

Apps and online services

About this project

Motivation

So I've just spent an "all nighter" working on this new IoT device that's going to change the world. The sun comes up, and I'm off to demo the device and pitch to my friends for some seed capital and soul crushing criticism. I get to their house, turn the device on, it won't connect... quickly I realize the device is still flashed with my home WiFi credentials. Time to quickly edit my code, reflash, and demo. But wait... there's a better way!

AnduinoWiFi ships with an example sketch, 'connectToWiFi'. With just a few lines of code you can add device hosted WiFi registration to any of your WiFi enabled prototypes. When the device first boots up it broadcasts it's own WiFi hotspot and serves a WiFi registration page at http://192.168.1.1/register. Once you enter the SSID and password anduino attempts to connect to the network you've just specified. Voilà internets!

Getting Started

In order to add end user facing WiFi registration to your arduino prototypes you'll need to make sure you've cloned the anduinoWiFi library and loaded it into your Arduino IDE. As long as you're using anduinoWiFi, or any WiFi101 enabled arduino, you should be able to immediately run the example sketch 'connectToWiFi'. This sketch runs the device registration process, hosts an access point named 'Anduino WiFi', and serves the registration page at http://192.168.1.1/register.

Open the serial terminal at 115200, join the 'Anduino WiFi' on your laptop or phone, enter your home WiFi SSID and password, and then follow along in the terminal. If all goes well you'll see something similar to this returned in the serial terminal...

SSID: Anduino WiFi 
Device IP Address: 192.168.1.1 
signal strength (RSSI):-100 dBm 
Registration server Running at http://192.168.1.1/register  

^^Registration mode is ready...

GET /register HTTP/1.1 
Host: 192.168.1.1 
Connection: keep-alive 
Cache-Control: max-age=0 
Upgrade-Insecure-Requests: 1 
User-Agent: Mozilla/5.0 (Macin...

^^We've received a request from your laptop or phone for the registration page!

POST /enterCredentials HTTP/1.1 
Host: 192.168.1.1 
Content-Type: application/x-www-form-urlencoded 
Origin: http://192.168.1.1 
Accept-Enco...
...
SSID=Andium&password=totallynotthepassword&eof=%23EOF 

^^Now we've received your submission with the SSID and password query args! Time to attempt to connect to the local WiFi...

Attempting to connect to SSID: Andium 
With password: totallynotthepassword 
Success! Connected to... 
SSID: Andium 
Device IP Address: 192.168.1.179 
signal strength (RSSI):-50 dBm 
WiFi connected  

Success! We're connected, lastly the 'connectToWiFi' example sketch attempts to connect to a web server...

char testSite[] = "andium.com";     //we'll connect and GET / to test our WiFi connection 

and GET/ the '/' root directory. If your local WiFi has a internet and no proxy settings you should see the web server's '200 OK' HTTP response header and then a ton of html stream across the terminal. It worked!

How can I add a device hosted WiFi registration process to my sketch?

Well that's a mouthful, I'm glad you've asked! In your sketch you'll want to include the library at the top and create you're own instance of the anduinoWiFi() class...

#include "AnduinoWiFi.h" 
AnduinoWiFi newWifi = AnduinoWiFi();

Next, within your setup() routine...

newWifi.begin("Anduino WiFi"); 

Begin AP mode and name your WiFi Access Point SSID (just replace "Anduino WiFi" with whatever you'd like to name the local network) This next chunk just creates the the wifi registration listener and waits until AP mode is disabled. Just below that add...

WiFiClient regClient; 
 //While we're in AP mode serve--------------  
 //reg webpage and parse POST response------- 
  while(newWifi.isAPmode()) 
 { 
   regClient = newWifi.getClient(); 
   //if we receive a client request to the server 
   if(regClient) 
   { 
     newWifi.parseRequest(regClient); 
   }   
 }  

As soon as the wifi registration successfully connects to your network it will drop out of this loop and continue with your setup() routine. That's all you need!

What's next?

Well that's up to you! Add this library to your toolbox and use it anytime you'd like to enable WiFi registration without requiring a full reflash of your hardware. I used it in a consumer facing prototype that scans NFC tags and purchases the associated item on Amazon, NFC Replenisher.

'connectToWiFi' in NFC Dash Replenisher @ 0:39

Code

Anduino
An Arduino library for the Andium(Anduino) shield. Transform your Arduino into an AndiumNode.
AnduinoWiFi
WiFi Registration library for anduino and WiFi101 enabled devices.

Comments

Similar projects you might like

3D-Printed Prank Vibrating Cup

Project tutorial by Alex Wulff

  • 1,306 views
  • 2 comments
  • 14 respects

The Magic Display With Arduino - The Mind Reader

Project tutorial by LAGSILVA

  • 1,531 views
  • 2 comments
  • 6 respects

Very First Hands On Arduino - Voice Activated LED

Project tutorial by Liren Yeo

  • 793 views
  • 1 comment
  • 9 respects

The Soldering Iron Controller for Hakko T12 Tips

Project tutorial by Alexander

  • 8,710 views
  • 4 comments
  • 26 respects

Voltmeter Using Arduino

by Team Next Tech Lab

  • 3,187 views
  • 8 comments
  • 44 respects

Prank Your Friends with Talking Darth Vader

Project tutorial by Chathuranga Liyanage

  • 335 views
  • 0 comments
  • 2 respects
Add projectSign up / Login