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!

  • 3,435 views
  • 0 comments
  • 20 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

Windows PC Lock/Unlock Using RFID

Project tutorial by Prasanth K S

  • 6,594 views
  • 6 comments
  • 29 respects

LED Cube

Project tutorial by Praditha Alwis

  • 311 views
  • 0 comments
  • 4 respects

Makers (Cubecon) #1 Infrared Transmit & Infrared Receive

Project in progress by Alpha

  • 119 views
  • 0 comments
  • 3 respects

Lie Detector

Project tutorial by Adaline Baskaran

  • 5,601 views
  • 5 comments
  • 16 respects

Arduino Keyboard

Project in progress by Gabriele Scordamaglia

  • 376 views
  • 2 comments
  • 4 respects
Add projectSign up / Login