Tuesday, October 9, 2012

Stock ticker with Wise Clock 4 and WiFly

I should have titled this "Adventures in WiFly land - Part 2", a continuation of this post, but really there was no adventure. Things worked smoothly from the start. The main "challenge" was parsing the http response on the fly, since the (truncated) response string itself is about 1500 bytes (3/4 of the RAM in a 328), which is the size of WiFly's receiving buffer.

The code (download from here) performs these steps:
  • send http request to yahoo site, specifying the stock symbol;
  • read the http response and find the token that identifies the stock price, in this case "last:";
  • read the next few characters that represent the stock price;
  • display the symbol and the price on the 3216 display.

This crude version is based on the WiFly_WebClient sample code from sparkfun. For display, it uses the HT1632 (header and c) files that are part of Wise Clock 4 library (but also supplied in the zip file). The software should work with any Arduino connected to a serial WiFly and a 3216 display from Sure Electronics.

The plan is to integrate this code as a new application in the Wise Clock 4 software. Stock symbols should be user-configurable and read from the SD card (as opposed to being hardcoded as they are now).
Also, the direction of the stock move, read from the http response as well (after the token "change"), could be shown in red for "down" and in green for "up".

No comments:

Post a Comment