Cairo Hacker Space

We were working on a home automation project, we used the wifly gsx in our project.
When we bought it, we thought it will be easy to communicate it like a serial modem between the arduino and PC, of course we are not noobs: goal every inch in the datasheet made us feel like one:.
And when we searched for a solution for even one of our countless problems we faced.... the result can be summarized in three words... WIFLY NOT WORKING or we are noobs: D

Of course i am kidding:, we are not noobs and wifly is WORKING: o, thanks to sparkfun wifly library and http://arduinology.tumblr.com/


We decided to start our new virtual hackerspace with this easy step by step tutorial for wifly:

Please post any problem you faced with wifly or arduino. 

First of all download the WiFly Serial Library from http://sourceforge.net/projects/arduinowifly/files/ credit goes Twaldock for making this library and examples, for more information go to http://arduinology.tumblr.com/, also download NewSoftSerial, Streaming, Time and PString libraries from http://arduino.cc/en/Reference/LibrariesAdd the WiFly and the other libraries to your Arduino library folder and restart your Arduino IDE, you should now see the library and examples.

To test the WiFly and library open one of the examples that came with the library, for this tutorial I will use the WebTime example, this one send html of the current time to your browser.

Now connect the WiFly to the Arduino board, connect the Tx of the WiFly to the Rx of the Arduino and the Rx of the WiFly to the Tx of the Arduino (don't use Pins 0 and 1 or any reserved Pins) for the sake of this example connect the Tx to the Pin 2 and Rx to Pin 3 on the Arduino. Connect the DIT-BATT on the WiFly to the 3 3V on the Arduino and the GND to GND.


Back to the WebTime sketch, modify the first couple of lines of code to your SSID and Passphrase if there's any, and modify the TX and Rx pins according to your setup.

now add this function to example, this function adjust the configuration of the WiFly in order to make it connect to your Access Point or Ad - Hoc connection

("WiFly.SendCommand("set_wlan_auth_ _","AOK"); //WiFly.SendCommand("set wlan key "," AOK "); WiFly.SendCommand("set_wlan_channel_ _","AOK");WiFly.SendCommand("set_wlan_join_ _","AOK");WiFly.SendCommand("set_dhcp_ _","AOK"); WiFly.SendCommand ("save", "aok");WiFly.SendCommand ("reboot", "aok");




instead of a real value should be enteredfor the first line of code WiFly.SendCommand("set_wlan_auth_ _","AOK") this is for the authentication type replace with0, Open1, WEP-1282, WPA13, Mixed WPA1 & WPA2-PSK4, WPA2-PSK5, Not Used6, Adhoc, Join any ad hoc network

You don't need to do this step unless you thing WEP-128 in the authentication type then you must enter this line WiFly.SendCommand("set_wlan_key_ _","AOK") where the value is the HEX key.
WiFly.SendCommand("set_wlan_channel_ _","AOK"), 1-13 is the valid range for a fixed channel. If 0 is set, then scan is performed, using the ssid.

The WiFly.SendCommand("set_wlan_join_ _","AOK") sets the policy for automatically joining/associating with network access points. This policy is used when the module powers up, including wake up from the sleep timer.0, Manual, do not try to join automatically.1, Try to join the access point that matches the stored SSID, channel and passkey. Channel can be set to 0 for scanning.2, Join ANY access point with security matching the stored authentication mode. This ignores the stored SSID and searches for the access point with the strongest signal.3, Reserved - Not used.4, Create an Adhoc network, using stored SSID, IP address and netmask. Channel MUST be set. DHCP should be 0 (static IP) or set to Auto-IP with this policy. (unless another Adhoc device can act as DHCP server) add the ip and netmaskWiFly.SendCommand("set_ip_address_169.254.1.1","AOK");WiFly.SendCommand("set_netmask_255.255.0.0","AOK");Also set to channel 1, WiFly.SendCommand("set_wlan_chan_1","AOK");

Last line in the configuration process WiFly.SendCommand ("set dhcp ", "aok"), which set the DHCP0, DHCP OFF, use stored static IP address1, DHCP ON, get IP address and gateway from AP2, Auto-IP, generally used with Adhoc networks3, DHCP cache mode, Uses previous IP address lease is not expired if (lease survives reboot)

You need to save and reboot each time you configure the WiFly Wlan options thus the WiFly.SendCommand ("save", "aok") and WiFly.SendCommand ("reboot", "aok");


Now add initSettings() as the first line of a function called Reconnect();

That's it, upload the WebTime Sketch to your Arduino and see if it works, if you connected the green, yellow, red LEDs to the PIO4, PIO5, PIO6 respectively of the WiFly you should see its statusRed LEDFast blinking, not connected to wireless networkOFF, ConnectedYellow LEDWith each blink it means its either sending or receiving data from Tx or RxGreen LEDON Solidconnected over TCPFast Blink, Blink addressSlow IP, IP address OK



After uploading the Sketch open the serial monitor to see the Arduino activity, it should display "starting webtime - please wait." and then "free memory = " and then stops for about 10 sec or more and the continuous, if it doesn't continue the means you have something wrong in your connection between the Arduino and WiFly and it's not receiving data


After it continues you should see quite a lot of lines coming up on your serial monitor if it connected successfully you should see your IP address that has been assigned to the WiFly and the Green LED is slowly Blinking while the RED LED is OFF, if you find your IP address to be 0.0.0.0 then the WiFly failed to connect to your wireless network and that you may have configured it wrong.


When you see ready for HTTP in the serial monitor, go to your browser and enter the IP address found in the serial monitor and add port 2000 to it (xxx.xxx.xxx .xxx: 2000).


You should see some activity in the serial monitor and the browser should show you some data about current time



If all works right for you, you can remove the initSettings() function as this is only need to be run once to configure the WiFly and you won't be needing it anymore

For more information about the commands that can be sent to the WiFly check the WiFly Command Reference Manual http://www.sparkfun.com/datasheets/Wireless/WiFi/WiFlyGSX-um2.pdf

Good Luck and Have Fun