Sunday, January 15, 2012

Adventures in WiFly land - Part 1

This was a bit of a struggle, working with the XBee-footprinted WiFly RN-XV module from Roving Networks.

The goal was to get some data from the RSS feeds, kind of what this project had achieved.

First, I tried to set up the RN-XV module following this crash course (and using ladyada's XBee adapter with the FTDI cable). Everything went fine except connecting to my home WiFi network: I kept getting "AUTH-ERR". Eventually, after many tries, the module joined the network. I thought this is caused by the weak WiFi signal and other people may experience a similar scenario (which should be dealt with by the software).
Then I found with this software library, which, of course, did not work in my special case. After I started tweaking it and read the RN-XV manual once again, I found the explanation: WPA (which I am currently using) handshaking takes more than 1,000ms (1 second), which is the default timeout for the module. The solution was to increase this timeout (to 5000ms) with the command

set opt jointmr 5000

I ended up writing this sketch that makes requests to Yahoo's weather and stock quotes RSS feeds. It should work with the mentioned WiFly library (if they don't keep changing it).
Actually, I had to modify the library a bit too, to include my own specific commands in the initialization procedure. So I created this new function

boolean WiFlyDevice::myInit()
  if (!enterCommandMode())
    DEBUG_LOG (1, "Failed to enter command mode");
    return false;

  // turn off remote string;
  sendCommand("set com remote 0", false, "AOK");

  return sendCommand("set opt jointmr 5000", false, "AOK");

then modified begin() to look like this:

void WiFlyDevice::begin() 
  DEBUG_LOG(1, "Entered WiFlyDevice::begin()");

  if (!bDifferentUart) SPIuart.begin();

Another detail worth mentioning is the tuning of the delay between sending the request and reading the response. If this delay is too long, the response buffer gets overwritten, so response data is lost. If the delay is too short, the response is not there yet. Similar consideration while retrieving the response data from the buffer: we need to wait a bit for more data to come before we can say (kind-of) for sure that all data was received.

Next step (Part 2) is to parse the responses to find the correct values we are looking for, temperature and stock price, respectively, then to display them on Wise Clock 4.

Note: The RSS feeds I used are 
They could be custom-replaced with any other URL that returns a small(ish) set of XML data for easy parsing.


  1. Nice project, glad that you found my WiFi enabled ICE clock worthy to read... :)


  2. Thank you, trandi.
    "If I have seen further it is only by standing on the shoulders of giants."

  3. Good stuff, working on something similar but have not been able to figure out how to parse yet. How is part 2 of your adventures in wifly land coming along?

  4. sp, thanks.
    I should continue on that path, indeed. I just need to find some time (and energy). Keep an eye on the blog, I will write that up soon.

  5. Nice.
    I've been tinkering in the mean time, getting closer I think. Excited to see your approach, will probably end up being much cleaner solution than the mess of code im dealing with right now... =P

  6. Thanks! The bit of about 'set opt jointmr' fixed my auth_err issue.

  7. Sketch Arduino WiFi for Wifly modem configuration without library and
    with front-end: