mbed publishes real time up-to-date FTSE100 index data and posts it to a 7 segment multipurpose mbed breakout board

Dependencies:   EthernetNetIf dispBoB mbed

Revision:
3:4ccc72cfec87
Parent:
2:0fa458722bc3
Child:
4:eaed26093c4c
--- a/FTSE100.cpp	Thu Jul 07 08:39:50 2011 +0000
+++ b/FTSE100.cpp	Thu Jul 07 14:36:39 2011 +0000
@@ -2,49 +2,37 @@
 #include "EthernetNetIf.h"
 #include "HTTPClient.h"
 #include "dispBoB.h"
+#include "stdio.h"
 
 EthernetNetIf eth; 
 HTTPClient http;
-Serial pc(USBTX, USBRX);
 dispBoB db(p28, p27, p26);
   
 int main() {
 
-    printf("Start\n\r");
-    printf("\r\nSetting up...\r\n");
-    
-    EthernetErr ethErr = eth.setup();                   //Setup ethernet connection
-    if(ethErr) { 
-        printf("Error %d in setup.\n\r", ethErr);
-        return -1;
-    }
-    printf("\r\nSetup OK\r\n");
-    
-    db.init();                                          //initialise screen
+    EthernetErr ethErr = eth.setup();           //Setup ethernet connection
+    if(ethErr) return -1;
+  
+    db.init();                                  //initialise screen
     db.cls();
     
-    HTTPText txt;                                       //instantiate HTTPStream object
+    HTTPText txt;                               //instantiate HTTPStream object
     while(1){
-        HTTPResult r = http.get("http://www.mbed.webatu.com/dispBoBApp.php", &txt);   //load page into buffer
+        HTTPResult r = http.get("http://mbed.net16.net/v1/dispBoBApp.php", &txt);   //load page into buffer
         if(r==HTTP_OK){
-            string str = txt.gets();                    //fetch string and store in str
-             
-            size_t length;                              //make some variables
-            char buffer[20];
-             
-            size_t found=str.find("<");                 //tell me where '<' first appears
-            if(found!=string::npos){   
-                length=str.copy(buffer,int(found),0);   //copy everything from start of string up until '<' character and return length
-                buffer[length]='\0';                    //null terminate my buffer
-                string dispString = buffer;             //convert buffer from type char* to string
-                db.scroll("FTSE100", 0.2);              //scroll "FTSE100" across the screen
-                db.locate(0);
-                db.printf("%s", dispString);            //then print FTSE100 value to screen
-            }   
-        } else {
-            pc.printf("Error\n\r");                     //just in case
+            string str = txt.gets();            //load web page intop string
+
+            char buf[10];                       //instantiate buffer and integer to store FTSE100
+            int value;                                  
+            str.copy(buf,9,0);                  //load buffer with chunk of web page
+
+            sscanf(buf, "%d", &value);          //scan until decimal point
+            
+            db.scroll("FTSE100", 0.2);          //print info to dispBoB
+            db.locate(1);
+            db.printf("%d", value);                    
         }
-        wait(2);                                        //wait 2 seconds before looping, so we don't pester the servers too much
+        wait(2);                                //wait 2 seconds before looping, so we don't pester the servers too much
     }
 }