Wifi shield configuration from SD card


A library for the Digilent chipKIT development boards. It lets you configure the wifi settings of the digilent wifi shield from a configuration file on the SD card. Library main page : http://kurdymalloy.github.io/CKEasyWifiConfig



In most example sketches that you will find, the wifi settings are always hard-coded in the sketch; this is kind of problematic if every time that you want to connect to a different network you have to change code and rebuild the sketch and reload it on the board.


This library will let you configure the wifi shield with settings read from a configuration file saved on a SD card loaded on the shield. So to change the settings, you just have to change the configuration file on the SD card. This is a lot better especially when your device is deployed in a project.


The project files are available at : https://github.com/KurdyMalloy/CKEasyWifiConfig This is arduino’s standard way of installing a custom library:
  • Copy the folder named “CKEasyWifiConfig” from the repository to the sub-folder  /libraries/ under your sketchbook directory.
  • Use the “NetConf.cfg” file from the root of the repository as a template for your configuration file that will go on the SD card.


The library is dependent on four other libraries: You need to include these in your main sketch before you include this one. This library was tested with mpide 0023.

Configuration File

The configuration file included in the project is already self-documented. Any line beginning with the character ‘#’ or ‘/’ will be ignored and considered a comment. The parameter names in the file are case sensitive, they need to be uppercase. Here are the possible values for each parameters: SECURITY:
  • OPEN
  • WEP_40
  • WEP_104
  • A valid ipv4 address in the form xxx.xxx.xxx.xxx
  • DHCP or left blank to use dhcp
  • The ssid of your network; it is usually case sensitive.
  • Your key in hexadecimal if you can provide it.
  • Your key if you want to provide it in text.
  • The index of your key if it is indexed
Important: the KEY and KEYCHAR parameters are mutually exclusive; if you provide both, the last one read in the file will be the one that is used. Example of a configuration file to connect with dhcp and an hexadecimal wpa2 key :
Example of a configuration file to connect with a static address and a wpa2 passphrase key :


There are two example projects provided with the library; one to use a configuration file on the card and one where you can pass the security infos in the code. To use the library, make sure that you include all the dependency libraries before you include CKEasyWifiConfig. If you want the library to output some debugging information in the serial port, make sure to define “CKEASYWIFICONFIG_SERIAL_DEBUG” before you include the library. You will also have to make sure that you setup the serial port before you call the “Setup()” method of the library. It is also very important to initialize the SD card before you call the “Setup()” method of the CKEasyWifiConfig class since it will use it. Example:
#include <SD.h>
#include <Streaming.h>
#include <WiFiShieldOrPmodWiFi.h>  // This is for the MRF24WBxx on a pmodWiFi or WiFiShield
//#include <WiFiShieldOrPmodWiFi_G.h> // This is for the MRF24WGxx on a pmodWiFi or WiFiShield
#include <DNETcK.h>
#include <DWIFIcK.h>

// Remove the next line to stop the serial debugging of the library
#include <CKEasyWifiConfig.h>

//To enable serial debugging in the main sketch

// Name of the config file on the SD card
char networkConfigFile[] = "NetConf.cfg";

CKEasyWifiConfig networkConfig(networkConfigFile);

void setup() {
  // put your setup code here, to run once:

    Serial << "Initializing SD card..." << endl;

  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  if (!SD.begin(4)) {
      Serial << "SD Card initialization failed!" << endl;
      Serial << "SD Card initialization success." << endl;
      if (SD.exists(networkConfigFile))
        Serial << "Network Config File --> " << networkConfigFile << " is present on the SD card." << endl;
        Serial << "Network Config File --> " << networkConfigFile << " is NOT present on the SD card." << endl;
    #endif // USE_SERIAL_DEBUG

  // Call the initialization

void loop() {
  // put your main code here, to run repeatedly: 

  // every pass through loop(), keep the IP stack alive


The SD card library only supports file names in the 8.3 format. So your configuration file and any sub-folder that you want to put it in, need to have a name in this format. Due to some architecture differences; this library is not really suitable for the arduino platform. The arduino has a very different memory model especially to store static stuff into the flash memory (PROGMEM). This code was not designed with that in mind and take fully advantage of the fact that the PIC architecture is much easier to code for. Also since there is a lot more space available on the chipKIT platform, more time was spent developing for the usability of the library than on trying to reduce its size. The dependency to the Digilent networking libraries is also a factor to the non-portability of the library.  
VN:F [1.9.22_1171]
Rating: 6.5/10 (2 votes cast)
Wifi shield configuration from SD card, 6.5 out of 10 based on 2 ratings