Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: NetServices TextLCD mbed spxml
Fork of News_LCD_display by
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetNetIf.h" 00003 #include "HTTPClient.h" 00004 #include "TextLCD.h" 00005 //CNN Tech News RSS Feed - get web page with XML 00006 // displays titles on LCD from XML "<title>....title text...</title>" 00007 TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d0-d3 00008 EthernetNetIf eth; 00009 HTTPClient http; 00010 HTTPResult result; 00011 PwmOut speaker(p21); 00012 bool completed = false; 00013 void request_callback(HTTPResult r) 00014 { 00015 result = r; 00016 completed = true; 00017 } 00018 00019 int main() 00020 { 00021 //while(1) { 00022 char *tstartXML = "<title>"; //RSS XML start title 00023 char *tendXML ="</title>"; //RSS XML end title 00024 char *tsptr; 00025 char *teptr; 00026 int i=0,j=0,t=0,c=0,d=0; 00027 lcd.cls(); 00028 lcd.printf("net setup"); 00029 EthernetErr ethErr = eth.setup(); 00030 if (ethErr) { 00031 lcd.printf("\n\r net error"); 00032 return -1; 00033 } 00034 lcd.printf("\n\r net ok"); 00035 HTTPStream stream; 00036 char BigBuf[2048 + 1] = {0}; 00037 stream.readNext((byte*)BigBuf, 2048); //Point to buffer for the first read 00038 //CNN Tech News RSS Feed - get web page with XML 00039 HTTPResult r = http.get("http://alerts.weather.gov/cap/wwaatmget.php?x=GAC121&y=0", &stream, request_callback); 00040 while (!completed) { 00041 c=0; 00042 Net::poll(); // Polls the Networking stack 00043 if (stream.readable()) { // check for end of file 00044 BigBuf[stream.readLen()] = 0; // Transform this buffer in a zero-terminated char* string 00045 tsptr = BigBuf; 00046 // displays titles on LCD from XML "<title>....title text...</title>" 00047 do { 00048 tsptr = strstr(tsptr,tstartXML); // find <title> in string - NULL if not 00049 teptr = strstr(tsptr,tendXML); // find <\title> in string - NULL if not 00050 if (tsptr!=NULL) tsptr = tsptr + strlen(tstartXML);// move to char after "<title>" 00051 if ((tsptr!=NULL)&&(teptr!=NULL)) { 00052 i=0; 00053 // loop to scroll characters slowly across LCD 00054 for (j=0; (j+15)<(strlen(tsptr)-strlen(teptr)); j++) { 00055 lcd.cls(); // clear screen before writing a new line 00056 // loop to output a line on the LCD 00057 for (i=0; ((i<16)&&(tsptr[i+j-1] != '<')); i++) { 00058 c++; 00059 } 00060 i=0; 00061 if (t>0 && c> 51 && d==0 && c!=108) { 00062 speaker.period(1.0/500.0); // 500hz period 00063 speaker =0.5; //50% duty cycle - max volume 00064 wait(2.5); 00065 speaker=0.0; // turn off audio 00066 wait(1); 00067 speaker =0.5; //50% duty cycle - max volume 00068 wait(2.5); 00069 speaker=0.0; // turn off audio 00070 wait(1); 00071 i=0; 00072 d=1; 00073 } 00074 for (i=0; ((i<16)&&(tsptr[i+j-1] != '<')); i++) { 00075 lcd.putc(tsptr[i+j]); 00076 } 00077 if (j==0) wait(1.2); //add first line delays for scroll timing 00078 wait(.25); //delay for charcter scroll timing 00079 } 00080 wait(.4); 00081 lcd.cls(); //clear LCD between news items 00082 wait(.2); 00083 00084 } 00085 00086 } while (tsptr!=NULL); // No more "<title>"s in BigBuf to display 00087 stream.readNext((byte*)BigBuf, 2048); //Buffer has been read, now we can put more data in it 00088 c=0; 00089 t++; 00090 } 00091 } 00092 lcd.cls(); 00093 if (result == HTTP_OK) { 00094 lcd.cls(); 00095 lcd.printf(" Read complete\n\r"); 00096 00097 } else { 00098 lcd. printf(" Error %d\n", result); 00099 return -1; 00100 } 00101 // } 00102 }
Generated on Wed Jul 13 2022 03:01:29 by
1.7.2
