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

Forward Logo (image)      

pfodWifiConfig for RN WiFly + FioV3
Simple Wifi Network Configuration

by Matthew Ford 18rh March 2015 (originally posted 3rd March 2015)
© Forward Computing and Control Pty. Ltd. NSW Australia
All rights reserved.

How to configure your FioV3 + RN WiFly
for any WiFi network

without re-programming

Introduction

This page describes how developers can to use pfodWifiConfig to allow their FioV3 + RN WiFly device to be configured for any Wifi network without re-programming. Two supporting Arduino libraries are needed pfodWifiConfig.zip and pfodWifiConfig_WiFly.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?

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. The example code here is for a SERVER, and lets you choose either DHCP or set a Static IP for the RN WiFly and also set the port the SERVER code will listen on for connections.

Developer Setup to use pfodWifiConfigV1.

This section describes how to prepare your RN WiFly to use pfodWifiConfigV1. First read the pfodWifiConfig page for detail of how the system works. This page uses an FioV3 board with an RN WiFly Xbee format daughter board. See this page for extra information on this combination.

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 WildFire. 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 FioV3 + WiFly for pfodWifiConfigV1

You need to download and install two libraries, pfodWifiConfig.zip which contains all the common code and the pfodWifiConfig_WiFly.zip library which has the specialized code for RN WiFly Xbee board. Install these using Arduino's Sketch → Import Library → Add Library function.

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

Include the libraries

#include <EEPROM.h>
#include "pfodWifiConfig.h"
#include "pfodWifiConfig_WiFly.h"


Add the settings for pfodWifiConfigV1

pfodWifiConfig_WiFly 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 ==============
const int CONFIG_LED = 7; // use D7 to indicate in config mode, only set as output after reading wifiSetup_pin LOW 


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) {
    pinMode(CONFIG_LED, OUTPUT);
    digitalWrite(CONFIG_LED, LOW); // show we are in setup mode
#ifdef DEBUG
  Serial.println(F("Starting pfodWifiConfigV1"));
#endif
    // connect to temporary wifi network for setup
    // the features determine the format of the {set...} command
    uint16_t ipSources = pfodFeatures::DHCP|pfodFeatures::STATIC_IP; // bit or these options together
    uint16_t security = pfodFeatures::WPA2; // bit or these together e.g. pfodFeatures::OPEN | pfodFeatures::WPA

    pfodWifiConfig.configureWifiConfig(client,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
  //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;

  pfodWifiConfig.loadNetworkConfigFromEEPROM(eepromAddress, &mode,
      (char*)ssid, pfodWifiConfig::MAX_SSID_LEN + 1, (char*)password, pfodWifiConfig::MAX_PASSWORD_LEN + 1,
      &security, &portNo, &ipSource, (char*)staticIP, pfodWifiConfig::MAX_STATICIP_LEN + 1);
  pfodWifiConfig.setupWiFi(client, ssid, password, staticIP, portNo);

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. Setting RN WiFly network settings requires getting into CMD mode and monitoring it responses. The method setupWiFi(..) handle this for you. That method is also used by configureWifiConfig()

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 your FioV3 + WiFly board to 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


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-2017 Forward Computing and Control Pty. Ltd. ACN 003 669 994