Live RSS news feeds are displayed on a basic text LCD See http://mbed.org/users/4180_1/notebook/news-lcd-display/

Dependencies:   NetServices TextLCD mbed spxml HTTPClient_ToBeRemoved

Files at this revision

API Documentation at this revision

Comitter:
4180_1
Date:
Tue Apr 24 02:27:43 2012 +0000
Commit message:

Changed in this revision

HTTPClient.lib Show annotated file Show diff for this revision Revisions of this file
NetServices.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
spxml.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 582c6436e759 HTTPClient.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPClient.lib	Tue Apr 24 02:27:43 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/HTTPClient/#d0be6af2d1db
diff -r 000000000000 -r 582c6436e759 NetServices.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NetServices.lib	Tue Apr 24 02:27:43 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/segundo/code/NetServices/#966a0265edfc
diff -r 000000000000 -r 582c6436e759 TextLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Tue Apr 24 02:27:43 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#44f34c09bd37
diff -r 000000000000 -r 582c6436e759 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Apr 24 02:27:43 2012 +0000
@@ -0,0 +1,76 @@
+#include "mbed.h"
+#include "EthernetNetIf.h"
+#include "HTTPClient.h"
+#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
+EthernetNetIf eth;
+HTTPClient http;
+HTTPResult result;
+bool completed = false;
+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;
+    // 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();
+    lcd.printf("net setup");
+    EthernetErr ethErr = eth.setup();
+    if (ethErr) {
+        lcd.printf("\n\r net error");
+        return -1;
+    }
+    lcd.printf("\n\r net ok");
+    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://rss.cnn.com/rss/cnn_tech.rss", &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+15)<(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]);
+                        }
+                        if (j==0) wait(1.2); //add first line delays for scroll timing
+                        wait(.2); //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
+        }
+    }
+    lcd.cls();
+    if (result == HTTP_OK) {
+        lcd.cls();
+        lcd.printf(" Read complete\n\r");
+    } else {
+        lcd. printf(" Error %d\n", result);
+        return -1;
+    }
+}
diff -r 000000000000 -r 582c6436e759 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Apr 24 02:27:43 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e
diff -r 000000000000 -r 582c6436e759 spxml.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spxml.lib	Tue Apr 24 02:27:43 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/hlipka/code/spxml/#3fa97f2c0505