A class to gather weather data from an NWS server.

Committer:
WiredHome
Date:
Sat Feb 23 18:01:39 2019 +0000
Revision:
20:29257dc4c7aa
Parent:
18:699590fd8856
Modify return code on failure to indicate the cause.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 1:e077d6502c94 1 /// @file NWSWeather.h
WiredHome 1:e077d6502c94 2 /// This file contains the interface for gathering forecast from NWS.
WiredHome 1:e077d6502c94 3 ///
WiredHome 17:99f09cc697fb 4 /// @attention This program is copyright (c) 2014 - 2019 by Smartware Computing, all
WiredHome 1:e077d6502c94 5 /// rights reserved.
WiredHome 1:e077d6502c94 6 ///
WiredHome 1:e077d6502c94 7 /// This software, and/or material is the property of Smartware Computing. All
WiredHome 1:e077d6502c94 8 /// use, disclosure, and/or reproduction not specifically authorized by Smartware
WiredHome 1:e077d6502c94 9 /// Computing is prohibited.
WiredHome 1:e077d6502c94 10 ///
WiredHome 1:e077d6502c94 11 /// This software may be freely used for non-commercial purposes, and any
WiredHome 1:e077d6502c94 12 /// derivative work shall carry the original copyright. The author of
WiredHome 1:e077d6502c94 13 /// a derivative work shall make clear that it is a derivative work.
WiredHome 1:e077d6502c94 14 ///
WiredHome 1:e077d6502c94 15 /// @author David Smart, Smartware Computing
WiredHome 1:e077d6502c94 16 ///
WiredHome 0:4435c965d95d 17 #ifndef NWSWEATHER_H
WiredHome 0:4435c965d95d 18 #define NWSWEATHER_H
WiredHome 0:4435c965d95d 19 #include "mbed.h"
WiredHome 0:4435c965d95d 20 #include "HTTPClient.h"
WiredHome 0:4435c965d95d 21
WiredHome 17:99f09cc697fb 22 // Set one of these to a 1, depending on your data source.
WiredHome 17:99f09cc697fb 23 #define WEATHER_GOV 0 // www.weather.gov (which went from http to https Jan 2019
WiredHome 17:99f09cc697fb 24 #define OPEN_WEATHER 1 // openweathermap.org (which so far remains http)
WiredHome 17:99f09cc697fb 25
WiredHome 17:99f09cc697fb 26
WiredHome 17:99f09cc697fb 27 #if WEATHER_GOV == 1
WiredHome 17:99f09cc697fb 28 static const char DEF_URL[] = "http://www.weather.gov/data/current_obs/";
WiredHome 17:99f09cc697fb 29 #elif OPEN_WEATHER == 1
WiredHome 17:99f09cc697fb 30 static const char DEF_URL[] = "http://api.openweathermap.org/data/2.5/weather?mode=xml&units=imperial&";
WiredHome 17:99f09cc697fb 31 #endif
WiredHome 17:99f09cc697fb 32
WiredHome 17:99f09cc697fb 33 /// Weather Service
WiredHome 0:4435c965d95d 34 ///
WiredHome 0:4435c965d95d 35 /// This class will fetch and parse weather data from an XML feed
WiredHome 17:99f09cc697fb 36 /// using a URL such as
WiredHome 17:99f09cc697fb 37 /// + https://www.weather.gov/data/current_obs/KALO.xml
WiredHome 17:99f09cc697fb 38 /// + http://api.openweathermap.org/data/2.5/weather?mode=xml&units=imperial&id=<Loc_ID>&APPID=<User_ID>
WiredHome 0:4435c965d95d 39 ///
WiredHome 17:99f09cc697fb 40 /// @attention Proper use of this should follow the guideline,
WiredHome 1:e077d6502c94 41 /// which is to not request this data from the server more often than
WiredHome 17:99f09cc697fb 42 /// necessary, and if available to recognize and use the suggested_pickup
WiredHome 1:e077d6502c94 43 /// parameter for subsequent updates of the weather information. This
WiredHome 1:e077d6502c94 44 /// class does not monitor the RTC so is unaware of the time of day. It
WiredHome 1:e077d6502c94 45 /// is therefore up to the user to manage this recommended practice.
WiredHome 1:e077d6502c94 46 ///
WiredHome 0:4435c965d95d 47 /// Only the essential parameters are gathered, which is generally those
WiredHome 0:4435c965d95d 48 /// from which you can derive others. It turns out this is also most of the
WiredHome 0:4435c965d95d 49 /// parameters.
WiredHome 1:e077d6502c94 50 ///
WiredHome 17:99f09cc697fb 51 /// From weather.gov
WiredHome 1:e077d6502c94 52 /// \li observation_time_rfc822 - "Sun, 16 Mar 2014 09:54:00 -0500"
WiredHome 1:e077d6502c94 53 /// \li suggested_pickup - "15 minutes after the hour"
WiredHome 1:e077d6502c94 54 /// \li suggested_pickup_period - 60 (minutes)
WiredHome 0:4435c965d95d 55 /// \li location
WiredHome 0:4435c965d95d 56 /// \li weather
WiredHome 0:4435c965d95d 57 /// \li temp_f
WiredHome 0:4435c965d95d 58 /// \li temp_c
WiredHome 0:4435c965d95d 59 /// \li relative_humidity
WiredHome 0:4435c965d95d 60 /// \li wind_degrees
WiredHome 0:4435c965d95d 61 /// \li wind_mph
WiredHome 0:4435c965d95d 62 /// \li pressure_mb
WiredHome 0:4435c965d95d 63 /// \li pressure_in
WiredHome 0:4435c965d95d 64 /// \li dewpoint_f
WiredHome 0:4435c965d95d 65 /// \li dewpoint_c
WiredHome 0:4435c965d95d 66 /// \li windchill_f
WiredHome 0:4435c965d95d 67 /// \li windchill_c
WiredHome 0:4435c965d95d 68 /// \li visibility_mi
WiredHome 1:e077d6502c94 69 /// \li icon_url_base - http://forecast.weather.gov/images/wtf/small/
WiredHome 1:e077d6502c94 70 /// \li icon_url_name - ovc.png (changes based on forecast)
WiredHome 0:4435c965d95d 71 /// \li latitude
WiredHome 0:4435c965d95d 72 /// \li longitude
WiredHome 0:4435c965d95d 73 ///
WiredHome 17:99f09cc697fb 74 /// From openweathermap.org
WiredHome 17:99f09cc697fb 75 /// \li <current>
WiredHome 17:99f09cc697fb 76 /// \li <city id="4880889" name="Waterloo">
WiredHome 17:99f09cc697fb 77 /// \li <coord lat="42.49" lon="-92.34"/>
WiredHome 17:99f09cc697fb 78 /// \li <country>US</country>
WiredHome 17:99f09cc697fb 79 /// \li <sun set="2019-01-08T22:54:13" rise="2019-01-08T13:38:34"/>
WiredHome 17:99f09cc697fb 80 /// \li </city>
WiredHome 17:99f09cc697fb 81 /// \li <temperature unit="fahrenheit" max="36.68" min="33.26" value="34.92"/>
WiredHome 17:99f09cc697fb 82 /// \li <humidity unit="%" value="93"/>
WiredHome 17:99f09cc697fb 83 /// \li <pressure unit="hPa" value="1009"/>
WiredHome 17:99f09cc697fb 84 /// \li <wind>
WiredHome 17:99f09cc697fb 85 /// \li <speed name="Gale" value="18.34"/>
WiredHome 17:99f09cc697fb 86 /// \li <gusts value="10.8"/>
WiredHome 17:99f09cc697fb 87 /// \li <direction name="North-northeast" value="340" code="NNW"/>
WiredHome 17:99f09cc697fb 88 /// \li </wind>
WiredHome 17:99f09cc697fb 89 /// \li <clouds name="scattered clouds" value="40"/>
WiredHome 17:99f09cc697fb 90 /// \li <visibility value="16093"/>
WiredHome 17:99f09cc697fb 91 /// \li <precipitation mode="no"/>
WiredHome 17:99f09cc697fb 92 /// \li <weather value="scattered clouds" icon="03n" number="802"/>
WiredHome 17:99f09cc697fb 93 /// \li <lastupdate value="2019-01-08T12:15:00"/>
WiredHome 17:99f09cc697fb 94 /// \li </current>
WiredHome 17:99f09cc697fb 95 ///
WiredHome 0:4435c965d95d 96 class NWSWeather
WiredHome 0:4435c965d95d 97 {
WiredHome 0:4435c965d95d 98 public:
WiredHome 1:e077d6502c94 99 /// Return code interpretation.
WiredHome 1:e077d6502c94 100 typedef enum
WiredHome 1:e077d6502c94 101 {
WiredHome 1:e077d6502c94 102 noerror, ///< no error, or parameter has been updated.
WiredHome 1:e077d6502c94 103 nomemory, ///< insufficient memory to complete operation.
WiredHome 1:e077d6502c94 104 noresponse, ///< no response from server.
WiredHome 1:e077d6502c94 105 badparameter, ///< bad parameter to function (typically out of range value).
WiredHome 1:e077d6502c94 106 noupdate, ///< no update available.
WiredHome 1:e077d6502c94 107 noparamfound ///< no parameter found.
WiredHome 1:e077d6502c94 108 } NWSReturnCode_T;
WiredHome 1:e077d6502c94 109
WiredHome 1:e077d6502c94 110 /// Identifies the type of a parameter.
WiredHome 1:e077d6502c94 111 typedef enum
WiredHome 1:e077d6502c94 112 {
WiredHome 1:e077d6502c94 113 isFloat, ///< this parameter is a floating point value.
WiredHome 1:e077d6502c94 114 isInt, ///< this parameter is an integer.
WiredHome 1:e077d6502c94 115 isString ///< this parameter is a string value.
WiredHome 1:e077d6502c94 116 } TypeOf_T;
WiredHome 1:e077d6502c94 117
WiredHome 1:e077d6502c94 118 /// The union of available types.
WiredHome 1:e077d6502c94 119 typedef union
WiredHome 1:e077d6502c94 120 {
WiredHome 1:e077d6502c94 121 float fValue; ///< the floating point value
WiredHome 1:e077d6502c94 122 int iValue; ///< the integer value
WiredHome 1:e077d6502c94 123 char * sValue; ///< the string value
WiredHome 1:e077d6502c94 124 } Value_T;
WiredHome 1:e077d6502c94 125
WiredHome 18:699590fd8856 126 /// The array that defines what XML information to extract.
WiredHome 18:699590fd8856 127 ///
WiredHome 18:699590fd8856 128 /// It will not honor heirarchical XML tagging, each parsed
WiredHome 18:699590fd8856 129 /// tag must be in the same text line.
WiredHome 18:699590fd8856 130 ///
WiredHome 18:699590fd8856 131 /// Given two types of XML structure:
WiredHome 18:699590fd8856 132 /// 1) <sunrise>6:45 am</sunrise>
WiredHome 18:699590fd8856 133 /// 2) <sun rise="6:45 am" set="4:52 pm">
WiredHome 18:699590fd8856 134 ///
WiredHome 18:699590fd8856 135 /// The key-value pairs can be defines to support either:
WiredHome 18:699590fd8856 136 /// "sunrise", NULL, NWSWeather::isString
WiredHome 18:699590fd8856 137 /// "sun", "rise", NWSWeather::isString
WiredHome 18:699590fd8856 138 ///
WiredHome 18:699590fd8856 139 /// @code
WiredHome 18:699590fd8856 140 /// static NWSWeather::XMLItem_T WeatherData[] = {
WiredHome 18:699590fd8856 141 /// {"weather", "value", NWSWeather::isString}, //<weather number="802" value="scattered clouds" icon="03n"/>
WiredHome 18:699590fd8856 142 /// {"temperature", "value", NWSWeather::isFloat}, //<temperature value="27.3" min="21.2" max="32" unit="fahrenheit"/>
WiredHome 18:699590fd8856 143 /// {"sun", "rise", NWSWeather::isString},
WiredHome 18:699590fd8856 144 /// {"sun", "set", NWSWeather::isString},
WiredHome 18:699590fd8856 145 /// };
WiredHome 18:699590fd8856 146 /// @endcode
WiredHome 1:e077d6502c94 147 typedef struct
WiredHome 1:e077d6502c94 148 {
WiredHome 18:699590fd8856 149 const char * key; ///< pointer to the XML key of interest
WiredHome 18:699590fd8856 150 const char * param; ///< pointer to the parameter, or NULL if the key defines it
WiredHome 18:699590fd8856 151 TypeOf_T typeis; ///< the type of data
WiredHome 1:e077d6502c94 152 bool updated;
WiredHome 1:e077d6502c94 153 Value_T value;
WiredHome 1:e077d6502c94 154 } XMLItem_T;
WiredHome 1:e077d6502c94 155
WiredHome 0:4435c965d95d 156
WiredHome 0:4435c965d95d 157 /// Constructor.
WiredHome 0:4435c965d95d 158 ///
WiredHome 0:4435c965d95d 159 /// Create the object to acquire the weather information from NOAA.
WiredHome 0:4435c965d95d 160 /// The full form of a valid url to acquire the data from is:
WiredHome 0:4435c965d95d 161 /// "http://www.weather.gov/data/current_obs/SITE.xml", where SITE
WiredHome 0:4435c965d95d 162 /// is replaced by the proper site location code.
WiredHome 0:4435c965d95d 163 ///
WiredHome 0:4435c965d95d 164 /// location codes are available at http://weather.noaa.gov/data/nsd_bbsss.txt,
WiredHome 0:4435c965d95d 165 /// and you can use the http://forecast.weather.gov/zipcity.php search tool
WiredHome 0:4435c965d95d 166 /// to search based on either zip code or city, state.
WiredHome 0:4435c965d95d 167 ///
WiredHome 0:4435c965d95d 168 /// It is possible to construct the NWSWeather object with an alternate
WiredHome 17:99f09cc697fb 169 /// base url, but this is only useful if the alternate site is xml format
WiredHome 0:4435c965d95d 170 /// compatible.
WiredHome 0:4435c965d95d 171 ///
WiredHome 17:99f09cc697fb 172 ///
WiredHome 0:4435c965d95d 173 /// @code
WiredHome 0:4435c965d95d 174 /// NWSWeather wx;
WiredHome 17:99f09cc697fb 175 /// #if WEATHER_GOV == 1
WiredHome 0:4435c965d95d 176 /// wx.get("KALO"};
WiredHome 17:99f09cc697fb 177 /// #elif OPEN_WEATHER == 1
WiredHome 17:99f09cc697fb 178 /// wx.get(4880889, "user_id");
WiredHome 17:99f09cc697fb 179 /// #endif
WiredHome 0:4435c965d95d 180 /// wx.PrintAllWeatherRecords();
WiredHome 0:4435c965d95d 181 /// @endcode
WiredHome 0:4435c965d95d 182 ///
WiredHome 0:4435c965d95d 183 /// @code
WiredHome 0:4435c965d95d 184 /// NWSWeather wx("http://some.alternate.site/path/");
WiredHome 0:4435c965d95d 185 /// wx.get("KALO"};
WiredHome 0:4435c965d95d 186 /// wx.PrintAllWeatherRecords();
WiredHome 0:4435c965d95d 187 /// @endcode
WiredHome 0:4435c965d95d 188 ///
WiredHome 9:fcd83b2bd0cd 189 /// @param[in] baseurl is an optional parameter to set the base url. If this
WiredHome 17:99f09cc697fb 190 /// is not set a default is used.
WiredHome 0:4435c965d95d 191 /// If it is set, that alternate base url is used.
WiredHome 17:99f09cc697fb 192 /// #ifdef WEATHER_GOV
WiredHome 17:99f09cc697fb 193 /// http://www.weather.gov/data/current_obs/
WiredHome 17:99f09cc697fb 194 /// appended are two parameters
WiredHome 17:99f09cc697fb 195 /// <loc_code>
WiredHome 17:99f09cc697fb 196 /// ".xml"
WiredHome 17:99f09cc697fb 197 /// #elif OPEN_WEATHER == 1
WiredHome 17:99f09cc697fb 198 /// http://api.openweathermap.org/data/2.5/weather?mode=xml&units=imperial
WiredHome 17:99f09cc697fb 199 /// appended are two parameters
WiredHome 17:99f09cc697fb 200 /// &id=<loc_code>
WiredHome 17:99f09cc697fb 201 /// &APPID=<user_id>
WiredHome 17:99f09cc697fb 202 /// #endif
WiredHome 5:f3ae5160977e 203 /// for future forecast
WiredHome 5:f3ae5160977e 204 /// http://forecast.weather.gov/MapClick.php?lat=42.47508&lon=-92.36704926700929
WiredHome 5:f3ae5160977e 205 // &unit=0&lg=english&FcstType=dwml
WiredHome 5:f3ae5160977e 206 ///
WiredHome 18:699590fd8856 207 NWSWeather(XMLItem_T * pList, int count);
WiredHome 0:4435c965d95d 208
WiredHome 0:4435c965d95d 209 /// Destructor.
WiredHome 0:4435c965d95d 210 ~NWSWeather();
WiredHome 17:99f09cc697fb 211
WiredHome 0:4435c965d95d 212 /// set an alternate base url after construction of the NWSWeather object.
WiredHome 0:4435c965d95d 213 ///
WiredHome 9:fcd83b2bd0cd 214 /// @param[in] alternateurl is the new url to replace the baseurl.
WiredHome 9:fcd83b2bd0cd 215 /// @returns success/failure code. @see NWSReturnCode_T.
WiredHome 0:4435c965d95d 216 ///
WiredHome 0:4435c965d95d 217 NWSReturnCode_T setAlternateURL(const char * alternateurl);
WiredHome 0:4435c965d95d 218
WiredHome 17:99f09cc697fb 219
WiredHome 17:99f09cc697fb 220 #if WEATHER_GOV == 1
WiredHome 3:41504de1f387 221 /// get the current conditions weather data from the specified site.
WiredHome 0:4435c965d95d 222 ///
WiredHome 17:99f09cc697fb 223 /// This does the work to fetch the weather data from weatherdata.gov,
WiredHome 17:99f09cc697fb 224 /// for the site of interest.
WiredHome 0:4435c965d95d 225 ///
WiredHome 9:fcd83b2bd0cd 226 /// @param[in] site is the site/location code of the site of interest.
WiredHome 9:fcd83b2bd0cd 227 /// @param[in] responseSize is optional but important. It defaults to 2500
WiredHome 2:eae60b64066e 228 /// and is intended to tell this method the size of a buffer it
WiredHome 1:e077d6502c94 229 /// should temporarily allocate to receive and process the data.
WiredHome 9:fcd83b2bd0cd 230 /// @returns success/failure code. @see NWSReturnCode_T.
WiredHome 0:4435c965d95d 231 ///
WiredHome 2:eae60b64066e 232 NWSReturnCode_T get(const char * site, int responseSize = 2500);
WiredHome 18:699590fd8856 233 #elif OPEN_WEATHER == 1
WiredHome 17:99f09cc697fb 234 /// get the current conditions weather data from the specified site.
WiredHome 17:99f09cc697fb 235 ///
WiredHome 17:99f09cc697fb 236 /// This does the work to fetch the weather data from openweathermap.org,
WiredHome 17:99f09cc697fb 237 /// for the site of interest.
WiredHome 17:99f09cc697fb 238 ///
WiredHome 17:99f09cc697fb 239 /// @param[in] site is the site/location code string of the site of interest.
WiredHome 17:99f09cc697fb 240 /// @param[in] userid is the code string registered with the site to access the data.
WiredHome 17:99f09cc697fb 241 /// @param[in] responseSize is optional but important. It defaults to 2500
WiredHome 17:99f09cc697fb 242 /// and is intended to tell this method the size of a buffer it
WiredHome 17:99f09cc697fb 243 /// should temporarily allocate to receive and process the data.
WiredHome 17:99f09cc697fb 244 /// @returns success/failure code. @see NWSReturnCode_T.
WiredHome 17:99f09cc697fb 245 ///
WiredHome 18:699590fd8856 246 NWSReturnCode_T get(const char * site, const char * userid, int responseSize = 1000);
WiredHome 17:99f09cc697fb 247 #endif
WiredHome 18:699590fd8856 248
WiredHome 0:4435c965d95d 249 /// get the count of the number of weather parameters.
WiredHome 0:4435c965d95d 250 ///
WiredHome 0:4435c965d95d 251 /// @returns the count of the number of parameters for which
WiredHome 0:4435c965d95d 252 /// data is expected.
WiredHome 0:4435c965d95d 253 uint16_t count(void);
WiredHome 0:4435c965d95d 254
WiredHome 0:4435c965d95d 255 /// determines if a specific parameter was updated from the last
WiredHome 0:4435c965d95d 256 /// acquisition.
WiredHome 0:4435c965d95d 257 ///
WiredHome 9:fcd83b2bd0cd 258 /// @param[in] i is the item of interest.
WiredHome 1:e077d6502c94 259 /// @returns noerror if the parameter is up to date. @see NWSReturnCode_T.
WiredHome 0:4435c965d95d 260 ///
WiredHome 0:4435c965d95d 261 NWSReturnCode_T isUpdated(uint16_t i);
WiredHome 0:4435c965d95d 262
WiredHome 2:eae60b64066e 263 /// determines if a specific parameter was updated from the last
WiredHome 2:eae60b64066e 264 /// acquisition.
WiredHome 2:eae60b64066e 265 ///
WiredHome 9:fcd83b2bd0cd 266 /// @param[in] name is the item of interest.
WiredHome 2:eae60b64066e 267 /// @returns noerror if the parameter is up to date. @see NWSReturnCode_T.
WiredHome 2:eae60b64066e 268 ///
WiredHome 2:eae60b64066e 269 NWSReturnCode_T isUpdated(const char * name);
WiredHome 2:eae60b64066e 270
WiredHome 0:4435c965d95d 271 /// get one of the weather parameters.
WiredHome 0:4435c965d95d 272 ///
WiredHome 1:e077d6502c94 273 /// This fetches one of the available weather parameters by setting
WiredHome 1:e077d6502c94 274 /// user supplied pointers to reference the parameter.
WiredHome 1:e077d6502c94 275 ///
WiredHome 0:4435c965d95d 276 /// @code
WiredHome 0:4435c965d95d 277 /// // Iterate over each of the parameters
WiredHome 0:4435c965d95d 278 /// for (i=0; i<wx.count(); i++) {
WiredHome 0:4435c965d95d 279 /// char * name; TypeOf_T type; char * value;
WiredHome 0:4435c965d95d 280 /// if (wx.getParam(i, name, &type, value)) {
WiredHome 0:4435c965d95d 281 /// // print the values
WiredHome 0:4435c965d95d 282 /// }
WiredHome 0:4435c965d95d 283 /// }
WiredHome 0:4435c965d95d 284 /// @endcode
WiredHome 0:4435c965d95d 285 ///
WiredHome 0:4435c965d95d 286 /// @code
WiredHome 0:4435c965d95d 287 /// // Get the names of the available parameters.
WiredHome 0:4435c965d95d 288 /// for (i=0; i<wx.count(); i++) {
WiredHome 2:eae60b64066e 289 /// char *name;
WiredHome 2:eae60b64066e 290 /// if (wx.getParam(i, name) == noerror) {
WiredHome 0:4435c965d95d 291 /// // print the names of the parameters
WiredHome 0:4435c965d95d 292 /// }
WiredHome 0:4435c965d95d 293 /// }
WiredHome 0:4435c965d95d 294 /// @endcode
WiredHome 0:4435c965d95d 295 ///
WiredHome 9:fcd83b2bd0cd 296 /// @param[in] i is index of the parameter of interest.
WiredHome 9:fcd83b2bd0cd 297 /// @param[in] name is a pointer that is set to point to the name of parameter i.
WiredHome 9:fcd83b2bd0cd 298 /// @param[out] value is an optional pointer that is then set to point to the value of parameter i.
WiredHome 9:fcd83b2bd0cd 299 /// @param[out] typeis is an optional pointer that is set to indicate the type of the value.
WiredHome 9:fcd83b2bd0cd 300 /// @returns success/failure code. @see NWSReturnCode_T.
WiredHome 0:4435c965d95d 301 ///
WiredHome 2:eae60b64066e 302 NWSReturnCode_T getParam(uint16_t i, char *name, Value_T *value = NULL, TypeOf_T *typeis = NULL);
WiredHome 0:4435c965d95d 303
WiredHome 18:699590fd8856 304
WiredHome 18:699590fd8856 305 /// get one of the weather parameters.
WiredHome 18:699590fd8856 306 ///
WiredHome 18:699590fd8856 307 /// This searchs the parameter set for the named parameter, and if found
WiredHome 18:699590fd8856 308 /// it will set the user supplied pointers to the value and type information
WiredHome 18:699590fd8856 309 /// for that parameter.
WiredHome 18:699590fd8856 310 ///
WiredHome 18:699590fd8856 311 /// @code
WiredHome 18:699590fd8856 312 /// char sunrise[30]; TypeOf_T type;
WiredHome 18:699590fd8856 313 /// if (wx.getParam("sun", "rise", &sunrise, &type) == noerror) {
WiredHome 18:699590fd8856 314 /// // print the values
WiredHome 18:699590fd8856 315 /// }
WiredHome 18:699590fd8856 316 /// @endcode
WiredHome 18:699590fd8856 317 ///
WiredHome 18:699590fd8856 318 /// @param[in] name is a const pointer to a string naming the parameter of interest.
WiredHome 18:699590fd8856 319 /// @param[in] param is the secondary part of the parameter.
WiredHome 18:699590fd8856 320 /// @param[out] value is a pointer that is set to point to the value of parameter i.
WiredHome 18:699590fd8856 321 /// @param[out] typeis is a pointer that is set to indicate the type of the value.
WiredHome 18:699590fd8856 322 /// @returns success/failure code. @see NWSReturnCode_T.
WiredHome 18:699590fd8856 323 ///
WiredHome 18:699590fd8856 324 NWSReturnCode_T getParam(const char *name, const char * param, Value_T *value, TypeOf_T *typeis = NULL);
WiredHome 18:699590fd8856 325
WiredHome 0:4435c965d95d 326 /// get one of the weather parameters.
WiredHome 0:4435c965d95d 327 ///
WiredHome 1:e077d6502c94 328 /// This searchs the parameter set for the named parameter, and if found
WiredHome 1:e077d6502c94 329 /// it will set the user supplied pointers to the value and type information
WiredHome 1:e077d6502c94 330 /// for that parameter.
WiredHome 1:e077d6502c94 331 ///
WiredHome 0:4435c965d95d 332 /// @code
WiredHome 2:eae60b64066e 333 /// float value; TypeOf_T type;
WiredHome 2:eae60b64066e 334 /// if (wx.getParam("temp_f", &value, &type) == noerror) {
WiredHome 0:4435c965d95d 335 /// // print the values
WiredHome 0:4435c965d95d 336 /// }
WiredHome 0:4435c965d95d 337 /// @endcode
WiredHome 0:4435c965d95d 338 ///
WiredHome 9:fcd83b2bd0cd 339 /// @param[in] name is a const pointer to a string naming the parameter of interest.
WiredHome 9:fcd83b2bd0cd 340 /// @param[out] value is a pointer that is set to point to the value of parameter i.
WiredHome 9:fcd83b2bd0cd 341 /// @param[out] typeis is a pointer that is set to indicate the type of the value.
WiredHome 9:fcd83b2bd0cd 342 /// @returns success/failure code. @see NWSReturnCode_T.
WiredHome 0:4435c965d95d 343 ///
WiredHome 0:4435c965d95d 344 NWSReturnCode_T getParam(const char *name, Value_T *value, TypeOf_T *typeis = NULL);
WiredHome 0:4435c965d95d 345
WiredHome 0:4435c965d95d 346 /// Print to stdout the specified weather record.
WiredHome 0:4435c965d95d 347 ///
WiredHome 1:e077d6502c94 348 /// Prints the specified record as a "Parmeter = value\r\n" string, formatted
WiredHome 1:e077d6502c94 349 /// so that subsequent prints line up at the '=' sign.
WiredHome 0:4435c965d95d 350 ///
WiredHome 9:fcd83b2bd0cd 351 /// @param[in] i specifies the record.
WiredHome 0:4435c965d95d 352 ///
WiredHome 0:4435c965d95d 353 void PrintWeatherRecord(uint16_t i);
WiredHome 0:4435c965d95d 354
WiredHome 9:fcd83b2bd0cd 355 /// Print all the records to stdout.
WiredHome 0:4435c965d95d 356 ///
WiredHome 1:e077d6502c94 357 /// calls PrintWeatherRecord for each available parameter.
WiredHome 0:4435c965d95d 358 ///
WiredHome 0:4435c965d95d 359 void PrintAllWeatherRecords(void);
WiredHome 6:cf96f2787a4e 360
WiredHome 6:cf96f2787a4e 361 /// Clear all the data and free allocated memory.
WiredHome 6:cf96f2787a4e 362 ///
WiredHome 6:cf96f2787a4e 363 void ClearWeatherRecords(void);
WiredHome 6:cf96f2787a4e 364
WiredHome 0:4435c965d95d 365 private:
WiredHome 0:4435c965d95d 366 char * m_baseurl;
WiredHome 0:4435c965d95d 367 NWSReturnCode_T ParseWeatherRecord(char * p);
WiredHome 18:699590fd8856 368 NWSReturnCode_T ExtractParam(int i, char * pValue, char * pEnd);
WiredHome 0:4435c965d95d 369 void ParseWeatherXML(char * message);
WiredHome 18:699590fd8856 370
WiredHome 18:699590fd8856 371 XMLItem_T * WeatherData;
WiredHome 18:699590fd8856 372 int WeatherItemCount;
WiredHome 18:699590fd8856 373
WiredHome 0:4435c965d95d 374 };
WiredHome 0:4435c965d95d 375 #endif // NWSWEATHER_H