SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
By follower
#115230
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.

This tool requires the WiFly Shield code library alpha 1 release is installed.

The tool provides some instructions on how to use the tool when run.

The steps you should follow are:
  • Upload SpiUartTerminal.pde sketch.
  • 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.

--Philip;

Update: Fixed link.
Last edited by follower on Wed Dec 15, 2010 8:46 pm, edited 1 time in total.
By zaktux
#117659
i have configure my linksys router (WRT54G2) whit "mixed band" (g+b) and doesn't work. Only work fine over B mode.

the error was:
2.21> Disconn from myssid, AUTH-ERR

solved changing the confing to B mode only.


(sorry for my english)
By follower
#117673
zaktux wrote:i have configure my linksys router (WRT54G2) whit "mixed band" (g+b) and doesn't work. Only work fine over B mode.
Sorry, I'm not sure what would be causing that issue. Maybe you could check if the router has error logs that give you more information?

--Philip;
By amirahmed123
#122081
Hi all.
I am using a Wifly shield from sparkfun and adruino UNO.
i m able to get into command mode. but not able to connect to wifi network.
is there some specific setting to be done for creating wifi network. confused over WEP/WPA. Which one to choose?
i use a netgear WG602 access point
By amirahmed123
#122172
hi, til now i was not able to connnect to available wify network with my wifly shield.
i tried to connect mannually from command mode
and it associated.
but i m not able to connect by my sketch
is there some problem with the library?
By Gary_BSEE
#124750
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!
Code: Select all
/*
  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".

Take care,

Gary
By cbernett
#128670
hello!

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.

Waiting for input.

WG÷·—77÷·Ø@'÷7o¶Þw·˜@774Á緟`±·ßG·±yç¶6¶¡@g¶ ‘Ƕ¡ˆ×0ÁWG÷·—77÷·Ø@'÷7o¶Þw·˜@774Á緟`±·ßG·±yç¶6¶¡@g¶ ‘Ƕ¡ˆ×0ÁWG÷·—77÷·Ø@'÷7o¶Þw·˜@77¶Á緟`±·ßG·±yç¶6¶¡@g¶ ‘Ƕ¡ˆ×0ÁWG÷·—77÷·Ø@'÷7o¶Þw·˜@774Á緟`±·ßG·±yç¶6¶¡@g¶ ‘Ƕ¡ˆ×0ÁWG÷·—77÷·Ø@'÷7o¶Þw·˜@774Á緟`±·ßG·±yç¶6¶¡@g¶ ‘Ƕ¡ˆ×0ÁWG÷·—77÷·Ø@'÷7o¶Þw·˜@77¶Á緟`±·ßG·±yç¶6¶¡@g¶ ‘Ƕ¡ˆ×0ÁWG÷·—77÷·Ø@'÷7o¶Þw·˜@77¶Á緟`±·ßG·±yç¶6¶¡@g¶ ‘Ƕ¡ˆ×0ÁWG÷·—77÷·Ø@'÷7o¶Þw·˜@774Á緟`

This goes on for as long as I let it run. Any ideas?

Thank you so much!
c
By cbernett
#128689
Hello!

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:

<2.21> set wlan ssid Method
AOK
<2.21> set wlan phrase xxxxxxxx
AOK
<2.21> set wlan auth 4
AOK
<2.21> scan
<2.21>
SCAN:Found 7
Num SSID Ch RSSI Sec MAC Address Suites
1 SmartFi 01 -67 WPAv1 74:91:1a:0f:7e:a9 AESM-TKIP 3104 0
2 MuseGames 02 -69 WPA_Mix 00:24:01:6f:8a:bd AES/TKIPM-TKIP 3104 0
3 shadygoliath1 06 -73 WEP 00:26:62:0d:1a:f6 1104 2
4 M3 Entertainment 09 -69 WPA_Mix 0c:d5:02:1e:42:b5 TKIPM-TKIP 1104 6
5 Method 11 -55 WPA_Mix 00:26:b0:fe:8b:a3 AES/TKIPM-TKIP 3100 0
6 DHAwifi 11 -62 WPAv1 00:21:29:ae:62:8e TKIPM-TKIP 1104 0
7 DHAguest 11 -74 WEP 00:15:e9:1e:d2:f8 3104 0
join # 5

DeAuth
Auto-Assoc Method chan=11 mode=MIXED SCAN OK
Joining Method now..
<2.21> Associated!
DHCP: Start

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!

Claudia
By k_san88
#130404
Gary_BSEE wrote: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.
By jasel
#132907
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?
By asifnadeem
#135613
Cbernet!
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?