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
Diff: getweather.cpp
- Revision:
- 0:f46e4f26425a
- Child:
- 1:35888a9f0a48
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getweather.cpp Mon Aug 09 14:12:07 2010 +0000 @@ -0,0 +1,75 @@ +#include "mbed.h" +#include "EthernetNetIf.h" +#include "HTTPClient.h" + +EthernetNetIf eth; +HTTPClient http; + +HTTPResult result; +bool completed = false; +void request_callback(HTTPResult r) { + result = r; + completed = true; +} + +void checkweather(HTTPStream &stream); + +char * location; +char temperature[3]; +char humidity[3]; +char BigBuf[512 + 1] = {0}; + +int main() { + printf("Start\n"); + printf("Setting up...\n"); + EthernetErr ethErr = eth.setup(); + if (ethErr) { + printf("Error %d in setup.\n", ethErr); + return -1; + } + printf("Setup OK\n"); + HTTPStream stream; + stream.readNext((byte*)BigBuf, 512); + + checkweather(stream); + + + while (1) { + + } + 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 + while (!completed) { + Net::poll(); //Polls the Networking stack + if (stream.readable()) { + BigBuf[stream.readLen()] = 0; //Transform this buffer in a zero-terminated char* string + + // look for key words in the html text + location = strstr(BigBuf,"Temperature"); + if (location != NULL) { + strncpy(temperature,location+13,2); + location = NULL; + } + + location = strstr(BigBuf,"Humidity"); + if (location != NULL) { + strncpy(humidity,location+10,2); + location = NULL; + } + + stream.readNext((byte*)BigBuf, 512); //Buffer has been read, now we can put more data in it + } + } + printf("\n--------------\n"); + if (result == HTTP_OK) { + printf("Read completely\n"); + printf("Temperature: %s deg F \n",temperature); + printf("Humidity: %s percent \n",humidity); + + } else { + printf("Error %d\n", result); + } +} \ No newline at end of file