ハイパー・マイコン mbedでインターネット 電子工作 5章 リスト5-3 SPXmlWeather

Dependencies:   EthernetInterface HTTPClient TextLCD mbed-rtos mbed spxml

Files at this revision

API Documentation at this revision

Comitter:
sunifu
Date:
Sun Jul 13 11:31:43 2014 +0000
Commit message:
2014.7.13

Changed in this revision

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
HTTPClient.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-rtos.lib 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 798ebca9033c EthernetInterface.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Sun Jul 13 11:31:43 2014 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/EthernetInterface/#9b2d10dc0392
diff -r 000000000000 -r 798ebca9033c HTTPClient.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPClient.lib	Sun Jul 13 11:31:43 2014 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/donatien/code/HTTPClient/#1f743885e7de
diff -r 000000000000 -r 798ebca9033c TextLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Sun Jul 13 11:31:43 2014 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/simon/code/TextLCD/#44f34c09bd37
diff -r 000000000000 -r 798ebca9033c main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Jul 13 11:31:43 2014 +0000
@@ -0,0 +1,102 @@
+#include "mbed.h"
+#include "rtos.h"
+
+#include "TextLCD.h"
+
+#include "EthernetInterface.h"
+#include "HTTPClient.h"
+
+#include "spdomparser.hpp"
+#include "spxmlnode.hpp"
+#include "spxmlhandle.hpp"
+
+TextLCD lcd(p24, p26, p27, p28, p29, p30);
+char buf[3000];
+
+int main() {
+    EthernetInterface eth;
+    int retEth;
+    HTTPClient http;  
+    int retHttp;
+    SP_XmlDomParser parser;
+        
+    printf("Setting up ...\r\n");
+    lcd.cls();
+    lcd.locate(0,0);
+    lcd.printf("Setting Up...");
+    
+    eth.init();
+    retEth = eth.connect();
+    
+    lcd.locate(0,0);
+    if (!retEth) {
+        printf("Network Setup OK\r\n");
+        lcd.printf("Network Setup OK");
+    } else {
+        printf("Network Error %d\r\n", retEth);
+        lcd.printf("Network Error %d");
+        return -1;
+    }
+         
+    while(true)
+    {
+        retHttp = http.get("http://weather.yahooapis.com/forecastrss?w=28426187&u=c", buf, sizeof(buf));
+    
+        lcd.locate(0,1);
+        switch(retHttp){
+        case HTTP_OK:
+            printf("Read completely\r\n");
+            lcd.printf("Read completely ");        
+            break;
+        case HTTP_TIMEOUT:
+            printf("Connection Timeout\r\n");
+            lcd.printf("Timeout         ");            
+            break;
+        case HTTP_CONN:
+            printf("Connection Error\r\n");
+            lcd.printf("Connection Error");
+            break;
+        default:
+            printf("Error\r\n");
+            lcd.printf("Error           ");                           
+        }        
+
+        parser.append( buf, strlen(buf)); // stream current buffer data to the XML parser
+        wait(5.0);    
+        printf("\r\n----------%s----------\r\n",buf);
+        
+        SP_XmlHandle rootHandle( parser.getDocument()->getRootElement() );
+
+        /*        
+        SP_XmlCDataNode * title = rootHandle.getChild( "channel" ).getChild("title").getChild(0).toCData();
+        printf("\r\n === Title:%s === \r\n",title->getText());
+        SP_XmlCDataNode * title1 = rootHandle.getChild( "channel" ).getChild("image").getChild("title").getChild(0).toCData();
+        printf("\r\n === Title:%s === \r\n",title1->getText());
+        SP_XmlCDataNode * title2 = rootHandle.getChild( "channel" ).getChild("item").getChild("title").getChild(0).toCData();
+        printf("\r\n === Title:%s === \r\n",title2->getText());
+        */
+        
+        SP_XmlElementNode * location = rootHandle.getChild( "channel" ).getChild( "yweather:location" ).toElement();
+        if (location) {
+            printf("\r\n === Location:%s === \r\n",location->getAttrValue("city"));
+        }
+                     
+        SP_XmlElementNode * forecast;
+        
+        forecast = rootHandle.getChild( "channel" ).getChild("item").getChild( "yweather:forecast",0).toElement();
+        if (forecast) {
+            printf("\r\n ----- Date:%s(%s) ----- \r\n",forecast->getAttrValue("date"),forecast->getAttrValue("day"));
+            printf("Condition:%s \n",forecast->getAttrValue("text"));
+            printf("Temp:Low%sC High%sC\n",forecast->getAttrValue("low"),forecast->getAttrValue("high"));
+        }        
+        
+        forecast = rootHandle.getChild( "channel" ).getChild("item").getChild( "yweather:forecast",1).toElement();    
+        if (forecast) {
+            printf("\r\n ----- Date:%s(%s) ----- \r\n",forecast->getAttrValue("date"),forecast->getAttrValue("day"));        
+            printf("Condition:%s \n",forecast->getAttrValue("text"));
+            printf("Temp:Low%sC High%sC\n",forecast->getAttrValue("low"),forecast->getAttrValue("high"));
+        }        
+        
+        wait(120.0);
+    }  
+}
diff -r 000000000000 -r 798ebca9033c mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Sun Jul 13 11:31:43 2014 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed-rtos/#db1fc233faa9
diff -r 000000000000 -r 798ebca9033c mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Jul 13 11:31:43 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/b3110cd2dd17
\ No newline at end of file
diff -r 000000000000 -r 798ebca9033c spxml.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spxml.lib	Sun Jul 13 11:31:43 2014 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/hlipka/code/spxml/#3fa97f2c0505