checks http://wedgefest.wind.ttu.edu/obs/TTU_LBBW.html every 5 minutes and records the temperature and humidity values located in the webpage's text

Dependencies:   EthernetNetIf mbed

Files at this revision

API Documentation at this revision

Comitter:
elliotb
Date:
Tue Aug 10 14:37:02 2010 +0000
Parent:
0:f46e4f26425a
Commit message:

Changed in this revision

getweather.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r f46e4f26425a -r 35888a9f0a48 getweather.cpp
--- a/getweather.cpp	Mon Aug 09 14:12:07 2010 +0000
+++ b/getweather.cpp	Tue Aug 10 14:37:02 2010 +0000
@@ -4,21 +4,23 @@
 
 EthernetNetIf eth;
 HTTPClient http;
-
+HTTPStream stream;
 HTTPResult result;
+Ticker update;
+
+char * location;
+char temperature[3]; // two digit characters plus null terminating char
+char humidity[3];
+char BigBuf[512 + 1] = {0};
 bool completed = false;
+
 void request_callback(HTTPResult r) {
     result = r;
     completed = true;
 }
-
-void checkweather(HTTPStream &stream);
+void checkweather(void);
 
-char * location;
-char temperature[3];
-char humidity[3];
-char BigBuf[512 + 1] = {0};
-
+/* main */
 int main() {
     printf("Start\n");
     printf("Setting up...\n");
@@ -28,20 +30,16 @@
         return -1;
     }
     printf("Setup OK\n");
-    HTTPStream stream;
-    stream.readNext((byte*)BigBuf, 512);
-
-    checkweather(stream);
-
-
-    while (1) {
+    checkweather();                     // call check weather to start off
+    update.attach(&checkweather, 5*60); // check the weather every 5 mins
+    
+    while (1) { // forever loop...weather checking will be interrupt based
 
     }
-    return 0;
 }
-
-void checkweather(HTTPStream &stream) {
-    HTTPResult r = http.get("http://mobile.weather.gov/port_mp_ns.php?select=3&CityName=Lubbock&site=LUB&State=TX&warnzone=TXZ035", &stream, request_callback); //Load a very large page
+void checkweather(void) {
+    stream.readNext((byte*)BigBuf, 512);
+    HTTPResult r = http.get("http://wedgefest.wind.ttu.edu/obs/TTU_LBBW.html", &stream, request_callback); //Load a very large page
     while (!completed) {
         Net::poll(); //Polls the Networking stack
         if (stream.readable()) {
@@ -50,16 +48,14 @@
             // look for key words in the html text
             location = strstr(BigBuf,"Temperature");
             if (location != NULL) {
-                strncpy(temperature,location+13,2);
+                strncpy(temperature,location+43,2);
                 location = NULL;
             }
-
             location = strstr(BigBuf,"Humidity");
             if (location != NULL) {
-                strncpy(humidity,location+10,2);
+                strncpy(humidity,location+40,2);
                 location = NULL;
             }
-
             stream.readNext((byte*)BigBuf, 512); //Buffer has been read, now we can put more data in it
         }
     }
@@ -68,7 +64,7 @@
         printf("Read completely\n");
         printf("Temperature: %s deg F \n",temperature);
         printf("Humidity: %s percent \n",humidity);
-
+        completed = false; // allows the weather to be checked more than once
     } else {
         printf("Error %d\n", result);
     }