Home | pfodApps/pfodDevices | WebStringTemplates | Java/J2EE | Unix | Torches | Superannuation | | About Us
 

Forward Logo (image)      

pfodWifiConfig for Adafruit CC3000
Simple Wifi Network Configuration

by Matthew Ford 5th January 2016 (originally posted 6rh April 2015)
© Forward Computing and Control Pty. Ltd. NSW Australia
All rights reserved.

How to configure Adafruit CC3000
on any WiFi network

without re-programming

Introduction

This page describes how to use pfodWifiConfig to connect your Adafruit CC3000 shield to any Wifi network without re-programming. Two supporting Arduino libraries are needed pfodWifiConfig.zip and pfodWifiConfig_AdafruitCC3000.zip

For a general description of pfodWifiConfigV1, see pfodWifiConfig. Read that page first before continuing here.

See Quick Start for using pfodWifiConfigV1 Android App for how config using the free Android app.
See Configuration of pfodWifiConfig™ Wifi devices using Telnet for an example of using telent to configure your device.

Why use pfodWifiConfig for a CC3000 chip?

i) pfodWifiConfig is open source so you can modify it as you need.
ii) pfodWifiConfig does more then just get you connected to the network.

pfodWifiConfigV1 also allows your user to configure the rest of the device. If your device runs as a Server, you can set the portNo the server listens on. If your device runs as a Client, you can set the host to connect to. If your Client device needs a login username and passwork, pfodWifiConfig prompts the user to set this as well.

Developer Setup to use pfodWifiConfigV1.

This section describes how to prepare your AdafruitCC3000 to use pfodWifiConfigV1. First read the pfodWifiConfig page for detail of how the system works.

Preparing the QR code image

First prepare the QR code that will contain the details of the temporary Wifi network that will be used to configure your Adafruit CC3000 shield. See pfodQRpsk for details on downloading and running the application.

Here is an example generated QR code.


A sample image is shown below. The file name is
pfodWifiConfigV1_the generated key.PNG

pfodWifiConfigV1_plyWtEDk6uZ0yfmAEM5wMc.PNG

The scanned text is from this image is
pfodWifiConfigV1
WPA2-PSK
plyWtEDk6uZ0yfmAEM5wMc
Port:23
www.pfod.com.au

That is
Network SSID: pfodWifiConfigV1
Security: WPA2-PSK
Password: plyWtEDk6uZ0yfmAEM5wMc
Connect to PortNo: 23
website: www.pfod.com.au

Generate your own QR image and attach it to your device and insert the password into your code (see below). This tutorial will use this QR image, and its password as an example.

Coding for Adafruit CC3000 for pfodWifiConfigV1

You need to download and install two libraries, pfodWifiConfig.zip which contains all the common code and the pfodWifiConfig_AdafruitCC3000.zip library which has the specialized code for the Adafruit CC3000 shield. Install these using Arduino's Sketch → Import Library → Add Library function.

Under Examples → pfodWifiConfig_AdafruitCC3000 there is an example file pfodWifiConfig_AdafruitCC3000_WebServer.ino
At the top of that file you will find the additional code needed.

Include the libraries

#include <EEPROM.h>
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include "utility/debug.h"
#include "utility/socket.h"
#include "pfodWifiConfig.h"
#include "pfodWifiConfig_AdafruitCC3000.h"

Add the settings for pfodWifiConfigV1

pfodWifiConfig_AdafruitCC3000 pfodWifiConfig;
// =============== start of pfodWifiConfigionV1 settings ==============
// update this define with the password from your QR code
// http://www.forward.com.au/pfod/pfodWifiConfig/pfodQRpsk.html
#define pfodWifiConfigPASSWORD "plyWtEDk6uZ0yfmAEM5wMc"
// the ssid is pfodWifiConfigV1 and the port is 23 -- set by pfodQRpsk program

// note pfodSecurity uses 19 bytes of eeprom usually starting from 0 so
// start the eeprom address from 20 for configureWifiConnect
int eepromAddress = 20;
int wifiSetup_pin = 4; // name the input pin for setup mode detection
// =============== end of pfodWifiConfigionV1 settings ==============


These settings define the password (same one as in your generated QR image) for the temporary pfodWifiConfig network.

The eepromAddress is the starting address in EEPROM where the user's network configuration will be stored. The static constant pfodWifiConfig::EEPROM_USAGE contains the maximum number of EEPROM bytes used by the library starting at eepromAddress.

The wifiSetup_pin is the digital input to check to see if we should start in configuration mode. If that pin is LOW, the sketch starts pfodWifiConfigionV1 otherwise it uses the configuration parameters stored in EEPROM to connect to the real network.

Then at the top of setup() add the following lines

  //============ pfodWifiConfigV1 config ====================
  // see if config button is pressed
  pinMode(wifiSetup_pin, INPUT_PULLUP);
  if (digitalRead(wifiSetup_pin) == LOW) {
    digitalWrite(LED, HIGH); // show we are in setup mode
    // connect to temporary wifi network for setup
    // the features determine the format of the {set...} command
    uint16_t ipSources = pfodFeatures::DHCP; // bit or these together pfodFeatures::DHCP|pfodFeatures::STATIC_IP if both are available
    uint16_t security = pfodFeatures::WPA2; // bit or these together e.g. pfodFeatures::OPEN | pfodFeatures::WPA
    pfodWifiConfig.configureWifiConfig(&cc3000,eepromAddress,"pfodWifiConfigV1",pfodWifiConfigPASSWORD,23,
    pfodFeatures::SERVER, security, ipSources );
    // configureWifiConfig never returns.  Need to reboot afterwards
  }
  //============ end pfodWifiConfigV1 config ====================

This code sets the wifiSetup_pin as an input with a pullup and then checks if it is being held LOW (pulled to GND). If it is LOW then configureWifiConfig() is called to connect to the temporary pfodWifiConfig network using the settings which should match those in the QR code image and to start a server on listening on port 23 for the configuration message.

The pfodFeatures class (in pfodWifiConfig.h) defines the various constants for the mode, security and ipSources.

Version 1 defines a set of features a device may support. For pfodWifiConfigV1 the possible features are:-
Mode: Server|Client|ClientLogin
IPsource: DHCP|staticIP
Security: OPEN|WEP|WPA|WPA2|WPA-WPA2

NOTE: The call to configureWifiConfig() never returns. So the user needs to power cycle the device after configuration to run it normally.

Below this setup code add the lines

  // else button was not pressed continue to load the stored network settings
  digitalWrite(LED, LOW);
  //else use configured setttings from EEPROM
  // use these local vars
  char ssid[pfodWifiConfig::MAX_SSID_LEN + 1]; // allow for null
  char password[pfodWifiConfig::MAX_PASSWORD_LEN + 1];
  char staticIP[pfodWifiConfig::MAX_STATICIP_LEN + 1];
  uint16_t portNo = 0;
  uint16_t security = 0;
  uint16_t ipSource = 0;
  byte mode = 0;


  server = Adafruit_CC3000_Server(portNo);
  if (!cc3000.begin())  {
    while(1);
  }
  if (!cc3000.connectToAP(ssid, password, WLAN_SECURITY)) {
    Serial.println(F("Failed!"));
    while(1);
  }
etc … 

This code, and the rest of the sketch, is run if the wifiSetup_pin is not grounded (LOW). It calls loadNetworkConfigFromEEPROM() to load the user configured network settings from EEPROM and connect to their network.

The complete code for sketch is here. That is all that is required by the developer.

Conclusion

That's all that is required to connect and configure your AdafruitCC3000 board on any user's network without re-programming it each time.

pfodWifiConfig and pfodQRpskare trademarks of Forward Computing and Control Pty. Ltd.
Android
TM is a trademark of Google Inc. For use of the Arduino name see http://arduino.cc/en/Main/FAQ


The General Purpose Android/Arduino Control App.
pfodDevice™ and pfodApp™ are trade marks of Forward Computing and Control Pty. Ltd.


Forward home page link (image)

Contact Forward Computing and Control by
©Copyright 1996-2020 Forward Computing and Control Pty. Ltd. ACN 003 669 994