
Note: It appears that after this blog article was written, Weather Underground has been phasing out the “PWS – Upload Protocol.” The following tutorial may or may not work currently or in the future. However, it continues to offer some insight into structuring a CRBasic program with Include() files, Sub() routine calls, and the use of the HTTPGet() instruction.
Over the years, you may have seen a number of Weather Underground PWS (personal weather station) discussions and solutions posted on the Campbell Scientific User Forum. In this article, I’ll show you how to post your data directly from an Internet-connected CR6 Measurement and Control Datalogger to Weather Underground.
Background
Weather Underground is a service that provides weather observations and forecasts via the Internet. Their data products use information collected from many sources, including over 180,000 personal weather stations.
Weather Underground provides a relatively simple web-based protocol for uploading data from a PWS. Their protocol is much simpler to use than many other hosted services you might find out there. The Weather Underground protocol requires only a simple HTTP GET request with the station, user, and sensor information embedded into the URL. This process can be quite easy for a Campbell Scientific data logger, such as a CR6, to perform using the HTTPGet() instruction and a few string operators.
| Recommended for You: For more detailed information about the protocol, read the “PWS – Upload Protocol” wiki entry. |
There are a number of Campbell Scientific-based personal weather stations in operation today. One example is KUTNORTH6, which is owned and operated by a Campbell Scientific employee in Logan, Utah. From the Weather Underground website, you can view the KUTNORTH6 PWS dashboard, which is an example of what your data might look like after you post it.
#1 - Create an account
To get started, you will need to make sure you’ve registered with Weather Underground, created a PWS, and made note of your PWS station ID and account password. (Currently, a basic account is free on their site.)
#2 - Create a weather station program
The easiest way to create your weather station program is to use the Short Cut Program Generator for Windows. Here is an example program I created that includes measurements for wind speed, wind direction, air temperature, and relative humidity:
Public WindSpeed_MPH, WindDir, TRHData(2)
Alias TRHData(1) = AirTemp_F, RH
BeginProg
Scan(1,Min,1,0)
'measure 05103 windspeed and direction;
'then measure cs215 temp/RH probe with SDI-12;
PulseCount(WindSpeed_MPH,1,U4,5,1,0.2192,0)
BrHalf(WindDir,1,mV5000,U2,U1,1,2500,True,20000,60,355,0)
If WindDir>=360 Or WindDir<0 then Winddir=0
SDI12Recorder(TRHData(),C1,"0","M!",1,0)
AirTemp_F=AirTemp_F*1.8+32
NextScan
EndProg
#3 - Download the file
Download the wunderground.dld file, and load it onto your data logger’s CPU drive. You will reference this file in your program using the Include() instruction. (Alternatively, you could copy the contents of the file into your program before the BeginProg statement. In this example, however, I’ll just use the Include() instruction method.)
#4 - Declare an array
Note: In the wunderground.dld file that you downloaded in the previous step, there is an instruction that I have named wundergroundPWS(). Using Include "CPU:wunderground.dld" makes the wundergroundPWS() instruction available for use within your CRBasic program.
You will need to declare an array that passes your data into the wundergroundPWS() instruction. The data in this array are organized in a very specific order, which must be followed.
- It’s OK to make the array smaller than its maximum size.
- It’s OK to not include all of the information.
- When you include information, it must be done in a very specific order.
The weather data array can hold 1 to 30 elements of data that may include those in the following list. For our example, we only need to use a subset of the weather data array. So I have declared the array in our example to a size of 11 (Dim WxData(11)), making it just large enough to allow me to specify our instantaneous wind direction, wind speed, relative humidity, and air temperature measurements.
- Instantaneous Wind Direction in degrees
- Instantaneous Wind Speed in miles-per-hour
- Wind Gust in miles-per-hour, calculated over a user-defined period
- Wind Gust Direction in degrees, calculated over a user-defined period
- 2 minute Average Wind Speed in mph
- 2 minute Average Wind Direction in degrees
- 10 minute Wind Gust in mph
- 10 minute Wind Gust Direction in degrees
- Percent Relative Humidity
- Dew Point Temperature in deg F
- Air Temperature #1 in deg F
- Air Temperature #2 in deg F
- Air Temperature #3 in deg F
- Air Temperature #4 in deg F
- Air Temperature #5 in deg F
- Hourly Rainfall in inches
- Daily Rainfall in inches
- Barometric Pressure in inches
- Soil Temperature #1 in deg F
- Soil Temperature #2 in deg F
- Soil Temperature #3 in deg F
- Soil Temperature #4 in deg F
- Soil Temperature #5 in deg F
- Percent Leaf Wetness #1
- Percent Leaf Wetness #2
- Solar Radiation in Watts/m2
- UV Index
- Visibility
- Indoor Temperature in deg F
- Indoor Percent Relative Humidity
Tip: If you’re interested in posting air-quality data, the wundergroundPWS() instruction also supports a second air-quality data array. The second array’s content and order can be found inside the wunderground.dld file you downloaded. Alternatively, you can find the information in the Pollution Fields section of the PWS wiki entry.
The wundergroundPWS() instruction accepts a number of parameters:
- The first parameter is the variable where a result code is placed. This code indicates if the post was successful or not.
- The second parameter is the PWS station ID as a quoted string.
- The third parameter is your account password as a quoted string.
- The fourth and fifth parameters are the arrays that contain your weather and air-quality data. If you are not using one or the other, simply enter a zero.
- There are also three optional parameters that most users do not use, and they aren’t used in our example. These optional parameters are used to specify the data timestamp in terms of seconds-since-1990, the desired UTC offset (difference in hours and minutes between Coordinated Universal Time and a location’s observed time), and an additional string-formatted diagnostics result field.
If you were to include all of the parameters, the instruction would look like this:
Call wundergroundPWS(Result,ID,Pass,Weather,AirQual,Timestamp,UTCOffset,ServerResponse)
#5 - Fill the array and call the instruction
The final step to post your data to the Weather Underground website is to put the data into your array and call the wundergroundPWS() instruction.
Tip: You can use the TimeIntoInterval() instruction to control how often data is posted over the Internet.
When you have completed the steps, your program might look similar to this:
'include the contents of wunderground.dld
'that has been placed on the datalogger cpu drive
Include "CPU:wunderground.dld"
Dim WxData(11)
Public Result
Public WindSpeed_MPH, WindDir, TRHData(2)
Alias TRHData(1) = AirTemp_F, RH
BeginProg
Scan(1,Min,1,0)
'measure 05103 windspeed and direction;
'then measure cs215 temp/RH probe with SDI-12;
PulseCount(WindSpeed_MPH,1,U4,5,1,0.2192,0)
BrHalf(WindDir,1,mV5000,U2,U1,1,2500,True,20000,60,355,0)
If WindDir>=360 Or WindDir<0 Then WindDir=0
SDI12Recorder(TRHData(),C1,"0","M!",1,0)
AirTemp_F=AirTemp_F*1.8+32
If TimeIntoInterval(0,10,Min) Then
'initialize array with NAN;
'then populate with data;
'then call our instruction
WxData() = NAN
WxData(1) = WindDir
WxData(2) = WindSpeed_MPH
WxData(9) = RH
WxData(11) = AirTemp_F
Call wundergroundPWS(Result,"stationID","password",WxData,0)
EndIf
NextScan
EndProg
Conclusion
By using the wunderground.dld file with the wundergroundPWS() instruction, along with the CRBasic Include() instruction, I hope you’re able to successfully post your data to the Weather Underground website. If it’s helpful to you, you can copy my example program file.
Be sure to post your Station ID below, so we can see your data display. Let us know if your experience went smoothly or if you have any questions.