Live RSS news feeds are displayed on a basic text LCD See http://mbed.org/users/4180_1/notebook/news-lcd-display/
Dependencies: NetServices TextLCDfor mbed spxml
Fork of News_LCD_display by
Reads the RSS-Fedd of the ZVV and prints the current state of the public transports on a LCD
Diff: main.cpp
- Revision:
- 1:27033a7fe75c
- Parent:
- 0:582c6436e759
- Child:
- 2:6aaaf927e994
diff -r 582c6436e759 -r 27033a7fe75c main.cpp --- a/main.cpp Tue Apr 24 02:27:43 2012 +0000 +++ b/main.cpp Sat Feb 22 22:19:53 2014 +0000 @@ -4,22 +4,21 @@ #include "TextLCD.h" //CNN Tech News RSS Feed - get web page with XML // displays titles on LCD from XML "<title>....title text...</title>" -TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d0-d3 +TextLCD lcd(p26,p25,p24,p23,p22,p20,p19,TextLCD::LCD20x4); // rs, e, d0-d3 EthernetNetIf eth; HTTPClient http; HTTPResult result; bool completed = false; -void request_callback(HTTPResult r) { +void loadZVVNews(); +void request_callback(HTTPResult r) +{ result = r; completed = true; } -int main() { - char *tstartXML = "<title>"; //RSS XML start title - char *tendXML ="</title>"; //RSS XML end title - char *tsptr; - char *teptr; - int i=0,j=0; +int main() +{ + // the eth and HTTP code has be taken directly from the HTTPStream documentation page // see http://mbed.org/cookbook/HTTP-Client-Data-Containers lcd.cls(); @@ -30,11 +29,78 @@ return -1; } lcd.printf("\n\r net ok"); + wait(0.5); + lcd.cls(); + /* HTTPStream stream; + char BigBuf[2048 + 1] = {0}; + stream.readNext((byte*)BigBuf, 2048); //Point to buffer for the first read + //CNN Tech News RSS Feed - get web page with XML + HTTPResult r = http.get("http://online.fahrplan.zvv.ch/bin/help.exe/dn?tpl=rss_feed_VBZ", &stream, request_callback); + while (!completed) { + Net::poll(); // Polls the Networking stack + if (stream.readable()) { // check for end of file + BigBuf[stream.readLen()] = 0; // Transform this buffer in a zero-terminated char* string + tsptr = BigBuf; + // displays titles on LCD from XML "<title>....title text...</title>" + do { + tsptr = strstr(tsptr,tstartXML); // find <title> in string - NULL if not + teptr = strstr(tsptr,tendXML); // find <\title> in string - NULL if not + if (tsptr!=NULL) tsptr = tsptr + strlen(tstartXML);// move to char after "<title>" + if ((tsptr!=NULL)&&(teptr!=NULL)) { + //i=0; + // loop to scroll characters slowly across LCD + for (j=0; j<(strlen(tsptr)-strlen(teptr)); j++) { + //lcd.cls(); // clear screen before writing a new line + // loop to output a line on the LCD + for (i=0; ((i<16)&&(tsptr[i+j-1] != '<')); i++) { + lcd.putc(tsptr[i+j]); + } + lcd.putc(tsptr[j]); + //if (j==0) wait(1.2); //add first line delays for scroll timing + wait(.1); //delay for charcter scroll timing + } + wait(.4); + lcd.cls(); //clear LCD between news items + wait(.2); + } + } while (tsptr!=NULL); // No more "<title>"s in BigBuf to display + stream.readNext((byte*)BigBuf, 2048); //Buffer has been read, now we can put more data in it + } + }*/ + loadZVVNews(); + while(true) { + completed = false; + if (result == HTTP_OK) { + + lcd.printf("Reload in 5 sec\n"); + + wait(5); + lcd.cls(); + loadZVVNews(); + + //lcd.cls(); + //lcd.printf(" Read complete\n\r"); + } else { + lcd. printf(" Error %d\n", result); + wait(1.2); + lcd.cls(); + loadZVVNews(); + } + } +} + +void loadZVVNews() +{ + char *tstartXML = "<title>"; //RSS XML start title + char *tendXML ="</title>"; //RSS XML end title + char *tsptr; + char *teptr; + int j=0; HTTPStream stream; - char BigBuf[2048 + 1] = {0}; - stream.readNext((byte*)BigBuf, 2048); //Point to buffer for the first read + char BigBuf[4096 + 1] = {0}; + stream.readNext((byte*)BigBuf, 4096); //Point to buffer for the first read //CNN Tech News RSS Feed - get web page with XML - HTTPResult r = http.get("HTTP://rss.cnn.com/rss/cnn_tech.rss", &stream, request_callback); + HTTPResult r = http.get("http://online.fahrplan.zvv.ch/bin/help.exe/dn?tpl=rss_feed_VBZ", &stream, request_callback); while (!completed) { Net::poll(); // Polls the Networking stack if (stream.readable()) { // check for end of file @@ -46,31 +112,25 @@ teptr = strstr(tsptr,tendXML); // find <\title> in string - NULL if not if (tsptr!=NULL) tsptr = tsptr + strlen(tstartXML);// move to char after "<title>" if ((tsptr!=NULL)&&(teptr!=NULL)) { - i=0; + //i=0; // loop to scroll characters slowly across LCD - for (j=0; (j+15)<(strlen(tsptr)-strlen(teptr)); j++) { - lcd.cls(); // clear screen before writing a new line + for (j=0; j<(strlen(tsptr)-strlen(teptr)); j++) { + //lcd.cls(); // clear screen before writing a new line // loop to output a line on the LCD - for (i=0; ((i<16)&&(tsptr[i+j-1] != '<')); i++) { + /*for (i=0; ((i<16)&&(tsptr[i+j-1] != '<')); i++) { lcd.putc(tsptr[i+j]); - } - if (j==0) wait(1.2); //add first line delays for scroll timing - wait(.2); //delay for charcter scroll timing + }*/ + lcd.putc(tsptr[j]); + //if (j==0) wait(1.2); //add first line delays for scroll timing + //delay for charcter scroll timing } - wait(.4); + wait(2.5); lcd.cls(); //clear LCD between news items - wait(.2); + } } while (tsptr!=NULL); // No more "<title>"s in BigBuf to display - stream.readNext((byte*)BigBuf, 2048); //Buffer has been read, now we can put more data in it + stream.readNext((byte*)BigBuf, 4096); //Buffer has been read, now we can put more data in it } } lcd.cls(); - if (result == HTTP_OK) { - lcd.cls(); - lcd.printf(" Read complete\n\r"); - } else { - lcd. printf(" Error %d\n", result); - return -1; - } -} +} \ No newline at end of file