BackNext

OWW, PHP, mySQL

This is my attempt to document how I got Oww to send data to my web site and put it into a mySQL database there. This is a work in progress and is very crude at the moment. I have a test script that dumps the database into a web page at the moment. All the data runs together, so it is not of much use, but it shows the data is getting to the database. I hope to add some scripts to make use of the data in the near future.

OWW

First a bit about OWW. OneWireWeather is a program by Dr. Simon J. Melhuish to process and display weather data from a 1wire network. It can be downloaded from Sourceforge. It runs on Linux, BSD, and RISC operating systems.

OWW has an output parser that can send commands to the shell. There are several variables which can be inserted into the command line to send parameters to another program, etc. Information on the output parser can be found here. In the setup file, there are places where you can enter commands to be passed to the shell. The Idea is to send a command that puts the data you want to send into a query string appended to a URL, and have the shell send the URL to the server like at Weather Underground. I put this on the postupdate line in my setup file. It sends approximately every 9 seconds. If I put it on the postlog line, it would send every 100 seconds. Of course you can change the log interval, but since I want as many data points as possible, I went with postupdate.

Here are a list of the tokens supported by OWW, the sensors I am using, and the abbreviations I am using in my code. Not all of the supported tokens are in this list, you need to refer to the Oww setup guide at Sourceforge for that and the format modifiers. A "#" in the token name represents a number, for example t# could be t1, t2, etc. depending on how many temperature sensors you have on the 1wire net. If you only have one temp. sensor, it would be t1.

SensorParser TokenAbbreviationCommand line string
temperaturet#t1, t2t1=$t1$, t2=$t2$
humidity (dew point) dp# dp dp=$dp1$
humidity (relative humidity) rh# rh rh=$rh1$
barometric pressure bar# bp bp=$bar1$
anemometer (wind speed) wsp wdspd wdspd=$wsp$
anemometer (wind gust) wspmax gst gst=$wspmax$
weather vane wdrname wddir wddir=$wdrname$
rain gauge (total) rain rn rn=$rain$
rain gauge (daily) dailyrain drn drn=$dailyrain$
rain gauge (rate) rainrate rnrt rnrt=$rainrate$

There is one more parameter I am using, time. The token is mysqltime, the abbreviation is tm, and the string is tm=$mysqltime$. This is so I can create queries that can look up a specific time or period.

So now everything needed is ready to put into the command for Oww to pass to the shell. The external program "wget" is what will be used. The command line looks like this-

wget -O dump http://deanostoybox.com/weather/wxupdate.php?tm=$mysqltime$'&'t1=$t1$'&'t2=$t2$'&'dp=$dp1$'&'rh=$rh1$'&'bp=$bar1$'&'wdspd=$wsp$'&'gst=$wspmax$'&'wddir=$wdrname$'&'rn=$rain$'&'drn=$dailyrain$'&'rnrt=$rainrate$

Documentation on wget can be found here. The "-O" option sets the output file name to "dump" to prevent wget from downloading anything. The PHP file "wxupdate.php" does not return any data, but due to the query string, on every update wget writes an empty file with the URL as file name. Even though the files are empty, they can fill a directory in a short time, so it is desirable to set the output file name to something else so the same empty file gets overwritten every time.

The URL is "http://domain.tld/path_to_script/script_name.php" then a "?" and then everything after the "?" is viewed as a query string by PHP. PHP uses "&" as the default delimiter to separate parts of a query string. You will note that in the example above, all the "&" delimiters are escaped by enclosing them in single quotes. I guess that "&" must have some meaning in "C" because if you run wget from the command line in a shell console you do not need them, but if you run the command from inside Oww the query string will stop at the first encounter on an "&". Escaping them in quotes works as expected. The "&" get passed without the quotes.

That will get Oww to send the URL to the server with the data included as a query string. Now for the PHP script to parse the query string and load the data into the mySQL database.

BackNext