Stream messages which you type into an internet app straight to the dispBoB!

Dependencies:   EthernetNetIf dispBoB mbed

InternetDispBoB.cpp

Committer:
d_worrall
Date:
2011-07-07
Revision:
2:2707a70078ac
Parent:
1:ec03de8ed408
Child:
3:f4115ac66e09

File content as of revision 2:2707a70078ac:

#include "mbed.h"
#include "EthernetNetIf.h"
#include "HTTPClient.h"
#include "dispBoB.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
    db.cls();
    
    HTTPText txt;                                       //instantiate HTTPStream object
    while(1){
        HTTPResult r = http.get("http://mbed.net16.net/v1/messageEcho.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[100];
             
            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(dispString, 0.2);              //scroll "FTSE100" across the screen
            }   
        } else {
            pc.printf("Error\n\r");                     //just in case
        }
        wait(2);                                        //wait 2 seconds before looping, so we don't pester the servers too much
    }
}