In order to help with troubleshooting when people are having problems with the WiFly shield I’ve created a tool which enables you to enter command mode and send commands manually.
- Remove power from Arduino and WiFly shield then plug it back in (this ensures the WiFly module is in a semi-known state).
- Open Serial Monitor in Arduino IDE.
- Read the instructions that appear.
- You should get the message "Connected to SPI UART.". If you do not get this message then this tool will not be able to help you--you will need to confirm the library is configured properly for the version of the WiFly board you use and try again.
- Ensure the line ending pop-up menu at the bottom of the Serial Monitor window is set to "No line ending".
- Type "$$$" without quotes and then press the "Send" button
- The display should respond with "CMD". If it doesn't, make sure you had removed & reapplied power before starting. If it still doesn't work, try changing the line ending to "Carriage return" and press the send button--if this works continue the remainder of the steps. Otherwise this tool will not be able to help you.
- Change the line ending to "Carriage return" and press the send button.
- The display should respond with something like "<2.19>" which tells you the version of the firmware on the module.
- Try sending commands like "scan" or "get everything" (without quotes).
If you get this far then it means the shield and module are somewhat functional which means the problem is probably related to connecting to the network you’re trying to reach.
So after about 7 hours of troubleshooting I’ve configured my Wifly via Arduino UNO on a static IP etc to send data over TCP connection. Here is my code, I hope it helps some peoples’ problems!
/*
Timer
This program takes analog input from a soleniod monitoring
module on pin 9 (max 5V, 40mA), and records and transmits
its "on" duration.
Used in conjunction with a PC running a monitoring program,
on the same Wi-Fi network with preconfigured settings, this
program allows the Arduino UNO to communicate these timed
durations with the PC, for further calculation and storage.
This program is Intellectual Property of GSMAC.
Created 26 Jan 2011
Modified 5 Apr 2011
-- Added functionality for WiFly GSX Module to send data
over Wi-Fi network
By Gary Willette
The circuit:
* Soleniod monitoring module attached to digital input 9
* Pin 9 connected to ground via a 10kOhm resistor (pulldown)
* Sparkfun WiFly shield attached to UNO
*/
// include the WiFly code to communicate with SpiSerial:
#include "WiFly.h"
//SET THESE PARAMETERS FOR WI-FI NETWORK
const char WEP_KEY [] = "enter_key_here";
const char AUTH_LEVEL [] = "1"; // 0=OPEN 1=WEP 2=WPA1 3=Mixed WPA1&WPA2-PSK 4=WPA2-PSK 6=AD HOC
const char SSID [] = "enter_SSID_here";
const char DHCP [] = "0"; //0=static (DHCP disabled) 1=DHCP enabled
const char WIFLY_IP [] = "192.168.1.208";
const char BACKUP_IP [] = "192.168.1.209";
const char WIFLY_PORT [] = "2000";
const char PC_IP [] = "192.168.1.7";
const char PC_PORT [] = "2000";
const char GATEWAY_IP [] = "192.168.1.1";
const char NETMASK [] = "255.255.255.0";
const char DNS_SERVER [] = "192.168.1.1";
const char ANTENNA_OPTION [] = "0"; //0=internal, 1=external
const char UART_MODE [] = "2"; //2=make TCP connection when there is data to send
const char LINKMON [] = "5"; //number of AP re-scans until reassociation
//define constants to be used
const int dataSendInterval = 10000; // interval of time to send data (5 seconds)
const int Delay = 100; //interval to wait between wi-fi parameter sets
const int buttonPin = 6; // select the input pin for the button output
const int ledPin = 5;
//data variables
unsigned long currentFillTime = 0;
unsigned long afterFill = 0;
unsigned long beforeFill = 0;
unsigned long lastDataSend = 0;
unsigned long totalFillTime = 0;
unsigned long oldFillTime1 = 0;
unsigned long oldFillTime2 = 0;
int transmissionNumber = 0;
// Variables will change:
int ledState = LOW; // the current state of the output pin
int buttonState = LOW; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
int buttonPush = 0; // will prevent writing vars while button is held
long lastDebounceTime = 0; // the last time the output pin was toggled
int debounceDelay = 40; // the debounce time; increase if the output flickers
//displays on terminal everything in SPI Serial buffer
void readFromWifly(){
delay(100);
while(SpiSerial.available() > 0) {
Serial.print(SpiSerial.read(), BYTE);
}
Serial.print("\n");
delay(100);
}
void setup() {
pinMode(buttonPin, INPUT); // declare the sensor pin as input
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(9600);
Serial.println("Attempting to connect to SPI UART");
SpiSerial.begin();
Serial.println("Connected to SPI UART");
// Exit command mode if we haven't already
SpiSerial.println("");
SpiSerial.println("exit");
readFromWifly();
// Enter command mode
SpiSerial.print("$$");
delay(100);
// Reboot to get device into known state
Serial.println("Rebooting");
SpiSerial.println("reboot");
readFromWifly();
delay(3000);
// Enter command mode
Serial.println("\nEntering command mode.");
SpiSerial.print("$$");
readFromWifly();
delay(500);
// Set authorization level to <auth_level>
SpiSerial.print("set w a ");
SpiSerial.println(AUTH_LEVEL);
Serial.print("Set wlan to authorization level ");
Serial.println(AUTH_LEVEL);
readFromWifly();
delay(500);
//disable DHCP
SpiSerial.print("set ip dhcp ");
SpiSerial.println(DHCP);
Serial.print("Set WiFly DHCP to: ");
Serial.println(DHCP);
readFromWifly();
delay(500);
//set WiFly IP Address
SpiSerial.print("set ip address ");
SpiSerial.println(WIFLY_IP);
Serial.print("Set WiFly IP to: ");
Serial.println(WIFLY_IP);
readFromWifly();
delay(500);
//set Backup WiFly IP Address
SpiSerial.print("set ip backup ");
SpiSerial.println(BACKUP_IP);
Serial.print("Set Backup IP to: ");
Serial.println(BACKUP_IP);
readFromWifly();
delay(500);
//set WiFly remote port
SpiSerial.print("set ip local_port ");
SpiSerial.println(WIFLY_PORT);
Serial.print("Set Wifly local port to: ");
Serial.println(WIFLY_PORT);
readFromWifly();
delay(500);
//set PC IP Address
SpiSerial.print("set ip host ");
SpiSerial.println(PC_IP);
Serial.print("Set PC IP to: ");
Serial.println(PC_IP);
readFromWifly();
delay(500);
//Set PC remote port
SpiSerial.print("set ip remote_port ");
SpiSerial.println(PC_PORT);
Serial.print("Set PC remote port to: ");
Serial.println(PC_PORT);
readFromWifly();
delay(500);
//set Gateway IP Address
SpiSerial.print("set ip gateway ");
SpiSerial.println(GATEWAY_IP);
Serial.print("Set gateway IP to: ");
Serial.println(GATEWAY_IP);
readFromWifly();
delay(500);
//set Netmask Address
SpiSerial.print("set ip netmask ");
SpiSerial.println(NETMASK);
Serial.print("Set netmask to: ");
Serial.println(NETMASK);
readFromWifly();
delay(500);
//Set DNS Address
SpiSerial.print("set dns address ");
SpiSerial.println(DNS_SERVER);
Serial.print("Set dns addresss to: ");
Serial.println(DNS_SERVER);
readFromWifly();
delay(500);
// Set passphrase to <auth_phrase>
SpiSerial.print("set wlan key ");
SpiSerial.println(WEP_KEY);
Serial.print("Set security phrase to ");
Serial.println(WEP_KEY);
readFromWifly();
delay(500);
//set antenna to internal or external
SpiSerial.print("set wlan ext_antenna ");
SpiSerial.println(ANTENNA_OPTION);
Serial.print("Set wlan ext_antenna: ");
Serial.println(ANTENNA_OPTION);
readFromWifly();
delay(500);
//setup to make tcp connection when data from uart is received
//and close connection after data is sent
SpiSerial.print("set uart mode ");
SpiSerial.println(UART_MODE);
Serial.print("Set UART mode: ");
Serial.println(UART_MODE);
readFromWifly();
delay(500);
//set access point link monitor (if AP goes down, scan x # of times before
//re-associating)
SpiSerial.print("set wlan linkmon ");
SpiSerial.println(LINKMON);
Serial.print("set Access point rescans to ");
Serial.println(LINKMON);
readFromWifly();
// Join wifi network <ssid>
SpiSerial.flush();
Serial.print("Joining '");
Serial.print(SSID);
Serial.println("'");
SpiSerial.print("join ");
SpiSerial.println(SSID);
delay(5000);
readFromWifly();
//ping PC IP Address (to check for connection
SpiSerial.print("ping ");
SpiSerial.println(PC_IP);
Serial.print("\nping ");
Serial.println(PC_IP);
readFromWifly();
delay(2000);
//save config
SpiSerial.println("save");
//show network details
SpiSerial.println("show net");
readFromWifly();
SpiSerial.println("get uart");
readFromWifly();
SpiSerial.println("exit");
}
void loop()
{
// read the state of the switch into a local variable:
int reading = digitalRead(buttonPin);
// If the switch changed, due to noise or pressing:
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
buttonState = reading;
if(buttonState==HIGH){
if(buttonPush!=1){
beforeFill=millis();
//Serial.println(beforeFill);
buttonPush=1;
digitalWrite(ledPin, HIGH);
}
}
else if(buttonState==LOW){
if(buttonPush!=0){
afterFill=millis();
//Serial.println(afterFill);
currentFillTime=afterFill-beforeFill;
totalFillTime+=currentFillTime;
buttonPush=0;
digitalWrite(ledPin,LOW);
}
}
}
// save the reading. Next time through the loop,
// it'll be the lastButtonState:
lastButtonState = reading;
if (millis() - lastDataSend >= dataSendInterval)
{
Serial.println(totalFillTime);
SpiSerial.println(totalFillTime); //send fill time to Wi-Fi
transmissionNumber++;
// store recent fill time into old time and once more
// old into extra old, for redundancy and backup
oldFillTime2 = oldFillTime1;
oldFillTime1 = totalFillTime;
totalFillTime = 0;
lastDataSend = millis();
}
}
Please note that to use this over WPA, you’ll need to change the command from "set wlan key " to "set wlan phrase ". If using over OPEN (unprotected) network, just set AUTH_LEVEL to “0”.
i’ve gotten the WIFLY up and running at home with my airport express (WPA2), but am needing to transfer my whole setup to work, where I also have a secure WPA/WPA2 network, but am having trouble connecting to it. I’m using the library designed for it and it just hangs. so i thought i’d try your troubleshooting sketch, but am not able to get into command mode at all. in fact, following is what i see, with no response from the IDE when i enter $$$:
This is a tool to help you troubleshoot problems with the WiFly shield.
For consistent results unplug & replug power to your Arduino and WiFly shield.
(Ensure the serial monitor is not open when you remove power.)
Attempting to connect to SPI UART…
Connected to SPI UART.
Use $$$ (with no line ending) to enter WiFly command mode. (“CMD”)
Then send each command followed by a carriage return.
I’m having a tricky problem with the WiFly Library. The WiFly are connecting beautifully at home (airport express, WPA2) but not at my studio (WPA mixed). It doesn’t error out or associate, it just sits on the begin() call. I tested it out with the SpiUartTerminal sketch, and it looked good. I got this:
Method’s ssid is showing up at WPA mixed - so it seems like all should be good. Any thoughts? I’m super stuck and really want to get this working at this location. Thanks so much in advance!
Gary_BSEE:
So after about 7 hours of troubleshooting I’ve configured my Wifly via Arduino UNO on a static IP etc to send data over TCP connection. Here is my code, I hope it helps some peoples’ problems!
Gary, thank you very much! Your code is a great rosetta stone for me. Most appreciated.
I’m a little confused about the relationship between Arduino and the WiFly shield. I’m developing an application to monitor my boat and most importantly the level of water, in case the automatic pumps stop working for some reason. It works as expected, but if I telnet into the WiFly the sketch stops running. If I reboot the WiFly, only the shield reboots, not the Arduino Uno. Do I really have to connect some kind of relay to the WiFly itself to be able to power cycle the whole thing and get the Arduino Uno to reboot and rerun the sketch?
I am having the same problem, instead of all that what u r getting, i am getting only one symbol which jus keeps on repeating while the tx on my arduino never stops blinking. can anybody help?
i’ve gotten the WIFLY up and running at home with my airport express (WPA2), but am needing to transfer my whole setup to work, where I also have a secure WPA/WPA2 network, but am having trouble connecting to it. I’m using the library designed for it and it just hangs. so i thought i’d try your troubleshooting sketch, but am not able to get into command mode at all. in fact, following is what i see, with no response from the IDE when i enter $$$:
This is a tool to help you troubleshoot problems with the WiFly shield.
For consistent results unplug & replug power to your Arduino and WiFly shield.
(Ensure the serial monitor is not open when you remove power.)
Attempting to connect to SPI UART…
Connected to SPI UART.
Use $$$ (with no line ending) to enter WiFly command mode. (“CMD”)
Then send each command followed by a carriage return.
I’ve been battling the entire weekend with the WiFly shield (Connected to a Arduino UNO). I know think I’ve exhausted all possible steps in debugging this issue. I have also tried this with all versions and some forks of the code and version 0022 and version 1.0 of the IDE.
After uploading and running SpiUartTerminal.pde or the HardwareFactoryReset.pde, the serial monitor just hangs after outputting “Waiting for input:” and doesn’t allow me to enter the command line application ($$$). I’ve tried unix screen, coolterm and the standard IDE serial monitor. I’ve also tested the pins to ensure everything is connected correctly (I finally soldered them to the header pins) and I’m sure it is.
I would really appreciate some help if possible. I’m now suspecting that it is in fact a hardware issue.
I had no trouble using the wifly shield until it started behaving weirdly (thats what i thought).It will go on for a while then off completely. I have done hardware reset through uploading the hardwareReset.pde or by sending factory reset command through serial monitor/tera term. It was fully functional before as I was able to associate to any network then two days ago this happened. Does this mean the device is defective and I have to get a new one or its some modification somewhere that is needed…I havent soldered anything on the prototyping area…please help!!!..