Skip to content | Skip to navigation
Powered by RSPowered by RSPowered by RS

mbed reads FTSE100 index

d_worrall

United Kingdom

The article relates to http://www.designspark.com/content/mbed-multipurpose-display-board-part-1

Now this is exciting and really demonstrates the power of the mbed as an intelligent interfacing device! In the office, I'm constantly checking the BBC headlines, the current FTSE100 data and all the real-time data that the internet has to offer. So wouldn't it be just brilliant to have it displaying on the dispBoB all the time, so that I don't have to distract myself from whatever I'm doing?

What you need

  • mbed
  • mbed 7 Segment Display Board aka dispBoB
  • Ethernet Cable (RJ45 jack etc.)
  • A website with PHP support (don't worry about this yet)
  • A spare Ethernet socket to the world wide web....

Ethernet Cable

What you DON'T need

  • PHP skillz
  • FTSE100 Knowledge

 

Unfortunately none of this

Unfortuanately none of this

A quick briefing on screen-scraping

In order to access the current FTSE100 index (it's actually 15mins delayed, but I mean 'current' to the outside world instead of to financiers working in the City) I need to first of all find a good reliable source of FTSE100 data.

Here seems fairly good. Now the data I really want is the number in the top right hand corner.

 

Yahoo Finance FTSE100

 

If you right click and select View Page Source the source code for the webpage should pop up and in here it should be possible to find the number I want...

...Some time later...

It happens to be placed between 2 html tags <span id="yfs_l10_^ftse"> and </span>. So what I want to do is get my mbed to scour through the source code, find these tags and strip out the important number in between (This is called screen-scraping). Then it can post it to the dispBoB to satisfy my addiction to real-time FTSE100 data.

But the mbed runs on C and string-handling would be done better in some other language. So I decide to get somebody else to do the donkey work. I'll offload the task of screen-scraping to some poor server out there in the cyber-world.

PHP Funtimes

I've never written a web application before and I managed this in one morning, so anyone reading this should be able to do it in no time at all. I signed up for free web-hosting with these people. After that, I created a new domain name http://mbed.net16.net and then through the helpful file manager application created a new .php file within the public_html directory. I called it dispBoBApp.php.

Being a PHP noob I then did a quick google search and read-up on all things PHP basic.

Here is the resulting webpage. If you access it during the week during working hours it should show the FTSE100 index. What's even more exciting, is that if you wait a couple of seconds and refresh the page, the number changes!! Perfect!

Next, all I have to do is connect the mbed to the web and stream off this number.

It actually reads off the source code for the webpage I just created, but 000webhost.com have stuck a bit of extra code on the end for their own purposes. I'll have to parse this out manually on the mbed.

So in my mbed code I'm going to still have to do a bit of parsing, just it will be much less labour intensive than had I just screen-scraped directly from yahoo finance. Well actually that's where I went wrong. If I use the sscanf() function from the stdio.h library I can tell my mbed to read off numbers until it sees something which isn't a number i.e. a line break, and then chuck everything it's just read into a new variable, say int value. Sorted!

mbed code

You can find my code here. It takes advantage of several other useful libraries written by other mbed users. The main advantage for this is that I can just plug-in and go. No faff or datasheets, just a list of the top functions and some code examples.

The FTSE100 just breaking 6000

The FTSE100 just breaking 6000

 

After a bit of HTTPClient fun and display board interfacing the mbed is ready. So now I have a real-time update of the FTSE100 right in front of me all day.

 

Comments

Boss

United Kingdom

21 weeks ago

Hey, this looks great, nice reporting. I look forward to trying something like this early next year.

Thanks.