5 Steps to Post Your CR6 Data to Weather Underground

by Sam Utley | Updated: 03/23/2016 | Comments: 10

Search the Blog


Subscribe to the Blog

Get an email when a new article is posted. Choose the topics that interest you most.


Area / Application

Product Category

Activity

Corporate / News

Enter your email address:



Suggest an Article

Is there a topic you would like to learn more about? Let us know.

Leave this field empty

CR6 datalogger connected to Internet and Weather Underground

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.

  1. Instantaneous Wind Direction in degrees
  2. Instantaneous Wind Speed in miles-per-hour
  3. Wind Gust in miles-per-hour, calculated over a user-defined period
  4. Wind Gust Direction in degrees, calculated over a user-defined period
  5. 2 minute Average Wind Speed in mph
  6. 2 minute Average Wind Direction in degrees
  7. 10 minute Wind Gust in mph
  8. 10 minute Wind Gust Direction in degrees
  9. Percent Relative Humidity
  10. Dew Point Temperature in deg F
  11. Air Temperature #1 in deg F
  12. Air Temperature #2 in deg F
  13. Air Temperature #3 in deg F
  14. Air Temperature #4 in deg F
  15. Air Temperature #5 in deg F
  16. Hourly Rainfall in inches
  17. Daily Rainfall in inches
  18. Barometric Pressure in inches
  19. Soil Temperature #1 in deg F
  20. Soil Temperature #2 in deg F
  21. Soil Temperature #3 in deg F
  22. Soil Temperature #4 in deg F
  23. Soil Temperature #5 in deg F
  24. Percent Leaf Wetness #1
  25. Percent Leaf Wetness #2
  26. Solar Radiation in Watts/m2
  27. UV Index
  28. Visibility
  29. Indoor Temperature in deg F
  30. 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:

  1. The first parameter is the variable where a result code is placed. This code indicates if the post was successful or not.
  2. The second parameter is the PWS station ID as a quoted string.
  3. The third parameter is your account password as a quoted string.
  4. 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.
  5. 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.


Share This Article



About the Author

sam utley Sam Utley is the Vice President of Research and Development at Campbell Scientific, Inc. His deep understanding and appreciation for Campbell Scientific customers and their need for measurement and control solutions developed from his experience as a Campbell Scientific customer, sales and support engineer, and product manager. Sam is a University of Georgia Biological and Agricultural Engineer graduate.

View all articles by this author.


Comments

IslandMan | 12/15/2016 at 11:42 AM

Thanks Sam.

Link to my weather station.

https://www.wunderground.com/us/ny/kings-park/zmw:11754.1.99999?MR=1

gonzalig | 03/29/2017 at 10:53 AM

Sam

 

I thanks you for this post, Its really helpful. The sub was working great in my CR1000 Ver 30 until I upgrade OS to 32. Now the part for the UTC has commands that don’t compile under the new OS.

Can you help?

GaryTRoberts | 03/29/2017 at 01:00 PM

gonzalig,

Thank you for finding and reporting this bug.  We have fixed it and it will be part of a bug fix release we are planning in the very near future.  The fix will be included in CR6 OS 06.03 and CR1000/CR800/CR3000 OS 31.03.

gonzalig | 03/31/2017 at 10:41 AM

GaryTRoberts

Yes, I meant I upgraded to 31.02. I´ll look forward to get the new OS.

Perhaps it’s not as popular but is there a post like this to help us send data to CWOP / MADIS? Your colleagues from Au already help some, but not all the times my data gets received by MADIS.

cellectronic | 11/17/2017 at 11:49 AM

Hi Guys, 

I am wondering if the bugs got sorted ? I have an error when trying to compile and the offending line is 

Call wundergroundPWS(Result,"stationID","password",WxData,0)

with the error Undeclared variable Result,, Any ideas anyone  ? Please.

uplander | 11/28/2017 at 11:42 AM

This sounds like your program needs to have the variable 'result' declared.  Add the following line to the other Public declarations at the beginning of your program:

Public  Result

José Miguel Campillo Anguita | 07/04/2018 at 09:16 AM

hola muy buenas tardes utedes podrian poner ejemplos de programas para wunderground de los siguientes variables promediadas

3 Wind Gust en millas por hora, calculado durante un período definido por el usuario
4 Dirección de la ráfaga de viento en grados, calculada durante un período definido por el usuario
5 2 minutos Velocidad del viento promedio en mph
6 Dirección del viento promedio de 2 minutos en grados
7 10 minutos de ráfaga de viento en mph
8 10 minutos de dirección de ráfaga de viento en grados
16 Precipitación por hora en pulgadas
17 Lluvia diaria en pulgadas

ksandilands | 11/29/2018 at 03:01 PM

Thanks for doing this blog post!

Do we need to change anthing in the dld file before we load it to the logger's CPU? I just copied the text from the link to a new text file and called it "wuderground.dld"

I am using a CR1000, and the value I get for result is: -2 which whe I look in the .dld file means connected but not successful, did not receive "200 OK" from server and no data appear on my PWS.

any suggestions?

Robin D | 11/30/2018 at 11:19 AM

Thanks for your question. Unfortunately, our experts on this topic are out of the office currently. As soon as we have the answer for you, we'll post it. Thanks for your patience. 

GaryTRoberts | 12/10/2018 at 02:32 PM

Ksandilands,

You should not have to make any changes to the DLD file. Just place it on the CPU and make sure to reference it in your program using "Include". As for the -2 error, it something is amiss with the information being sent to the server. If you make this lines in the include file Public instead of Dims, they can help us get a clue as to what WeatherUndergrounds server isn't liking:

Dim http_get_head As String * 500
Dim http_get_resp As String * 50
Dim http_get_uri As String * 1100

It would be good to set what http_get_uri, http_get_head, and http_get_response say after the failer. We can then go from there.

Please log in or register to comment.