SparkFun Forums 

Where electronics enthusiasts find answers.

All things pertaining to wireless and RF links
By follower
#101234
[Update: See WiFly Shield code library alpha 2 release (also SPI UART) for the latest release.]

Hi all,

I've been working on a library for the Arduino WiFly Shield for the folks at SparkFun.

The alpha 0 release of the WiFly library is now available for download and testing from: http://sparkfun.com/Code/wifly/WiFly-20 ... 023939.zip

The goal with this library is to make it--as much as possible--a "drop in" replacement for the official Arduino Ethernet library. Once a wireless network is joined the library should respond in the same way as the Ethernet library. This means you should be able to take existing Ethernet examples and make them work wirelessly without too many changes.

The library also provides a high-level interface for the "SC16IS750 I2C/SPI-to-UART IC" used in the shield but also available separately.


Usage

By way of example this is how you connect to a wireless network and use DHCP to obtain an IP address and DNS configuration:
Code: Select all
#include "WiFly.h"

void setup() {

  WiFly.begin();
  
  if (!WiFly.join("ssid", "passphrase")) {
     // Handle the failure
  }
  
  // Rejoice in your connection
}
From then on you can use the Client and Server classes (re-implemented for the WiFly) mostly as normal.

You can supply a domain name rather than an IP address for client connections:
Code: Select all
  Client client("google.com", 80);
You can also retrieve the current IP address with:
Code: Select all
  Serial.println(WiFly.ip());
This release of the library comes with three examples:
  • WiFly_Autoconnect_Terminal: reimplementation from tutorial
  • WiFly_WebClient: Ethernet WebClient demo with small WiFly changes
  • WiFly_WebServer: Ethernet WebServer demo with small WiFly changes
You need to modify the file "Credentials.h" to supply your network's name (SSID) and passphrase.


Known issues
This is an alpha release--this means it's non-feature complete and may not be entirely reliable. I've tested it with the shipped examples and it mostly works for me. There are some known issues:
  • Only supports WPA networks with passwords. If you have a network without a passphrase then it should work if you supply an empty string (or a dummy passphrase) but I have not tested this. If you have a WEP network you should probably use WPA instead. :) If that's not an option then it should be possible to change the library code to set the WEP key rather than a WPA passphrase.
  • Incomplete documentation
  • Only tested with WiFly firmware version 2.18--earlier or later versions may or may not have issues.
  • Only DHCP is supported--you can't specify an IP address and DNS configuration directly.
  • There are some situations (exact cause unknown but often it seems to be after initial programming) where the WiFly will fail to respond to requests. You may need to power-cycle the Arduino or try refreshing the page in your browser if it's acting as a server.
  • There's a limit to how quickly you can refresh a page when acting as a server--this is because the library doesn't handle dropped connections well at present. You can generally tell from the lights on the unit if it's busy. (This is particularly obvious when a using a web browser (rather than something like 'wget') because after the page is loaded the browser makes an immediate request for the favicon. Once every five seconds or so should be fine depending on how big the page is. (This seems worse with Safari than Chrome.)
  • None of the non-ethernet capabilities of the WiFly are yet exposed e.g. network scans, signal strength information etc.
  • The code isn't very robust for error states--in general it will hang rather than return useful information.
  • We only have a 9600 baud connection between the Arduino and WiFly it should in theory be possible to be much faster.
  • Passphrases or SSIDs that contain spaces or dollar signs ($) will probably not work.
License

The library is licensed under the LGPL.


What Next?

It would be great to hear back from people who have tested the code with what worked or didn't work for them. Please leave comments in this forum thread. Patches welcome. :) Further development is likely to be dependent on response so if this helps you, let us know!


Thanks for your attention.

--Philip;

P.S. I recommend hooking up a 9 volt battery to your Arduino and WiFly then wander around the house--just because you can. :)
Last edited by follower on Thu Dec 16, 2010 6:20 am, edited 2 times in total.
#101239
hi i just tryed your new library works as a charm even if i have WEP protection i needed to add to library Wiflydevice.cpp
Code: Select all
sendCommand("set w a 1");
and change
Code: Select all
  sendCommand("set wlan passphrase", true);
  sendCommand(passphrase);
to
Code: Select all
  sendCommand("set wlan key ", true);
  sendCommand(passphrase);
and i am connected cant test WAP connection coz i am using hotels internet and even that i can accses router settings cant change them coz to many ppl using it.
And thank you for you hard work hope to see some updates :)
By kevinlouie
#101284
Thanks for the great work!

But I'm having a few problems connecting to a network. My WiFly is running the 2.18 firmware and my wifi network was WPA, but I've tried to connect it using no encryption too, but I still get nothing. It seems to get hung up at
Code: Select all
  if (!WiFly.join(ssid, passphrase)) {
    Serial.println("Association failed.");
    while (1) {
      // Hang on failure.
    }
  }
  
  Serial.println("Associated!");
}
I can see all the Serial.println's that occur before this call, but after it, nothing, I don't get confimation of weither or not Association failed, or worked. The strangest part of it all is that I when I look at my router logs, I can see a device that is connected with a 0.0.0.0 IP address...I'm assuming that's the WiFly, but I don't get any response from the terminal.

I've also tried using the WiFly Transparent Terminal Sketch http://www.sparkfun.com/commerce/images ... rminal.zip, Whenever I pull up the terminal and enter in the $$$ it doesn't return the CMD line. I just wanted to see if you guys think this is hardware related or if it's software?
By follower
#101316
LMas wrote:hi i just tryed your new library works as a charm
Great! Pleased to hear it--thanks for trying the library out.
even if i have WEP protection i needed to add to library Wiflydevice.cpp
Code: Select all
sendCommand("set w a 1");
According to my understanding you shouldn't need to do that--that information is only used for a mode of the WiFly we don't use.
Code: Select all
  sendCommand("set wlan key ", true);
  sendCommand(passphrase);
Cool, I'm glad you figured that out.
And thank you for you hard work hope to see some updates :)
Thanks for your prompt and helpful feedback.

--Philip;
By follower
#101318
LMas wrote:i had problem with terminal after i enter $$$ it do nothing unles i unchek ENTER KEY and all comand after with enter key checked worked for me
Is that with a standard version of the IDE or has it been modified to have an "ENTER KEY" checkbox?

--Philip;
By follower
#101320
kevinlouie wrote:Thanks for the great work!
Thanks for trying out the great work. :)
I can see all the Serial.println's that occur before this call, but after it, nothing, I don't get confimation of weither or not Association failed, or worked.
That means that the code hasn't made it past the association stage.
I've also tried using the WiFly Transparent Terminal Sketch http://www.sparkfun.com/commerce/images ... rminal.zip, Whenever I pull up the terminal and enter in the $$$ it doesn't return the CMD line. I just wanted to see if you guys think this is hardware related or if it's software?
What Operating System are you using? As far as I can tell the Arduino Serial Monitor isn't very useful for communicating with the WiFly because it doesn't send newline characters.

On OS X I use "screen" as a terminal program but it's not graphical. Windows people seem to use HyperTerminal or TeraTerm I think.

To get the same effect as the Transparent Terminal Sketch you can comment out the code "join" section of the code in the WiFly_Autoconnect_Terminal example that ships with the library. (I've discovered that a configuration change that the library makes seems to make the module no longer work with the Transparent Terminal. Which also reminded me that I forgot to mention the library makes a change to the configuration to enable hardware flow control and saves the change (unfortunately it won't work without it being saved). To reverse the change you need to "set uart flow 0" and save the configuration again--it is best to do this after a reboot so other configuration changes don't get saved.) (But if this configuration change was made it means that some successful communication happened!)

I suggest removing the join code and trying with a separate terminal program initially. At the moment there's not enough detail to know if it's hardware or software related.

Thanks for your persistence with this.

--Philip;
#101351
what i ment you need to add security selection ai in WiFly documnetation is
Code: Select all
set wlan auth <value>
where walue is
Code: Select all
Value Authentication Mode
0 Open (Default)
1 WEP-128
2 WPA1
3 Mixed WPA1 & WPA2-PSK
4 WPA2-PSK
5 Not Used
6 Adhoc, Join any Adhoc network
its just make selection but if you have WEP security you
Code: Select all
set wlan phrase
becomes
Code: Select all
set wlan key <value>
And if you need some testing done find me on
skype by name LMas_ (or login name lmasss) so i will try to help you as much i can (sorry just a beginer in all this things :))
#101353
in wifly autoconect skech is thing like :
Code: Select all
char auth_level[] = "3";
char auth_phrase[] = "examplepassword";
char port_listen[] = "80";
char ssid[] = "SparkFunWireless";
then futher in the code in void autoconnect i found this
Code: Select all
  // Set authorization level to <auth_level>
  SPI_Uart_print("set w a ");
  SPI_Uart_println(auth_level); 
  delay(500);
  Serial.print("Set wlan to authorization level ");
  Serial.println(auth_level);

  // Set passphrase to <auth_phrase>
  SPI_Uart_print("set w p ");
  SPI_Uart_println(auth_phrase);
  delay(500);
  Serial.print("Set security phrase to ");
  Serial.println(auth_phrase);

just this part
Code: Select all
 // Set passphrase to <auth_phrase>
  SPI_Uart_print("set w p ");
  SPI_Uart_println(auth_phrase);
  delay(500);
  Serial.print("Set security phrase to ");
  Serial.println(auth_phrase);

i needed to change to
Code: Select all
 // Set passphrase to <auth_phrase>
  SPI_Uart_print("set w k ");
  SPI_Uart_println(auth_phrase);
  delay(500);
  Serial.print("Set security phrase to ");
  Serial.println(auth_phrase);

and just then i can connect to my hotels wireless which ssid is '3Com' auth is 1 (WEP) and auth_phrase is D004...

thats how it worked for me hope it will help.
P.S. Sorry for doble posting but i want this library working to its max for my project
By follower
#101506
LMas wrote:what i ment you need to add security selection ai in WiFly documnetation is
Code: Select all
set wlan auth <value>
I realise that's what you meant but--unlike the tutorial suggests--it's not actually necessary. The WiFly user guide describes that setting as:
Sets the authentication mode. Not needed unless using auto join
mode 2. i.e. set wlan join 2
We don't just auto join so it's not needed.
if you have WEP security you
Code: Select all
set wlan phrase
becomes
Code: Select all
set wlan key <value>
Yes, that's correct. The plan is to eventually handle that automatically.
by the way i used http://www.rovingnetworks.com/support/teraterm.zip pro verion which have enter key check box
Thanks for clarifying that.

--Philip;
By McCoder
#102261
when using the WiFly Shield with the Arduino Mega you need to reroute some pins

WiFly shield ------> Mega
D10 --------------> 53
D11 --------------> 51
D12 ---------------> 50
D13 ---------------> 52

Just remember that you still need D7 on the Mega

oh and if you use the Sparkfun WiFly library you need to edit spi.h from
Code: Select all
#define CS         10
#define MOSI       11
#define MISO       12
#define SCK        13
Code: Select all
#if defined(__AVR_ATmega1280__)
#define CS		   53 
#define MOSI	   51
#define MISO	   50 
#define SCK        52
#else
#define CS         10
#define MOSI       11
#define MISO       12
#define SCK        13
#endif
sorry for the double post, i just felt that people with Mega + WiFly shield problems would look here first.

And the WiFly library probably should be changed to reflect the Mega pins
By follower
#102384
Encryptic wrote:Have you considered making this available in a format other than just a zip file? Perhaps a GitHub repository?
I can make a mirror of the Mercurial repository available.

I'd appreciate it if you could tell me why that would be useful for you--I can guess but I wanted to make sure I understood the reasoning. :)

Thanks for your interest.

--Philip;