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

Forward Logo (image)      

pfodWifiConfig for LinkIt ONE
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 connect LinkIt ONE
to any WiFi network

without re-programming

Introduction

This page describes how to use pfodWifiConfig to connect your LinkIt ONE to any Wifi network without re-programming. Two supporting Arduino libraries are needed pfodWifiConfig.zip and pfodWifiConfig_LinkItOne.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.

Developer Setup to use pfodWifiConfigV1.

This section describes how to prepare your LinkIt ONE 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 LinkIt ONE. 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 LinkIt ONE for pfodWifiConfigV1

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

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

Include the libraries

#include "pfodWifiConfig.h"
#include "pfodWifiConfig_LinkIt.h"
#define WIFI_AUTH LWIFI_WPA

Add the settings for pfodWifiConfigV1

pfodWifiConfig_LinkIt 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 "CBP1JvFTJVeB7BTMGmVcRb"
// 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 D4
// =============== 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::WPA; // bit or these together e.g. pfodFeatures::OPEN | pfodFeatures::WPA

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


  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);

  server = LWiFiServer(portNo); // set correct portNo  LWiFi.begin();
  // keep retrying until connected to AP
  while (0 == LWiFi.connect(ssid, LWiFiLoginInfo(WIFI_AUTH, password))) {
    delay(1000);
  }
  //  etc ….... rest of setup() here

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 your LinkIt ONE 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


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