One of the most useful features of WUHU is it has the ability to fire multiple actions by reading a action file. The action file is a plain text file with a list of commands that WUHU will perform in order. You can define this action file under any of the Sound/Action buttons. As an example you can perform the list of actions on every data update, a storm alert, high outdoor wind speed, or any of the other Sound/Action buttons.
Example of how to use an Action file
In this example we will show you how to perform multiple actions using a action file under the On Weather Update every 300 seconds to refresh weather data.
Once you have an action file, you can enter as many actions as you want. There is no limit.
You can have comment lines in the file by using a semicolon (;) or you can use the keyword REM.
We will solve the following:
Output weather data to a comma delimited file using a template
Create a Highs and Lows webpage using a template
Copy the comma delimited file to our web server directory
Copy our Highs and Lows html file that we produced with the template to our web server directory
Run an application, passing the current temperature into that application
Request a URL just like a web browser does to be consumed by that webpage
FTP the file using the built in FTP support of WUHU
So, Lets setup WUHU
Create a Action.txt file that WUHU will read the actions from.
We need to create a new Action.txt. Put the following lines in notepad and save it as Action.txt in C:\Program Files\WUHU\ActionFile\Action.txt:
template:"C:\Program Files\WUHU\templates\csv.txt" "C:\Program Files\WUHU\data\data.csv" template:"C:\Program Files\WUHU\templates\highsandlows.txt" "C:\Program Files\WUHU\data\HighsAndLows.htm" copy:"C:\Program Files\WUHU\data\data.csv" "C:\wwwroot\weatherdata\data.csv" copy:"C:\Program Files\WUHU\data\HighsAndLows.txt" "C:\wwwroot\weatherdata\HighsAndLows.htm" "C:\Program Files\My Application\WeatherReader.exe" "%OutdoorTempDegF%" http://www.someplace.com/webservice/collector.aspx?t=%OutdoorTempDegF%&h=%OutdoorHumidity% ftp://bob:firstname.lastname@example.org "C:\Program Files\WUHU\data\data.csv" "\data\data.csv" ftp://bob:email@example.com "C:\Program Files\WUHU\data\*.*" "\data\"
So lets explain each line of the Action.txt in detail:
Line 1 is read by WUHU as creating a template action. It will read the csv.txt template and create a new data.csv with the live values from your weather station.
It takes this:
And turns it into this:
Templates can contain lots of different variables.
Download an example of the csv.txt template
Line 2 is another template action, just like Line 1, except this time we are producing a html file from a text file template. This HighsAndLows.txt is really a html file that has replaceable variables in it.
Download an example of the HighsAndLows.txt template
Line 3 is a file copy action. It will copy the data.csv from C:\Program Files\WUHU\data\data.csv to our web server’s weather data directory.
Note: We could have just output the data.csv directly to the c:\wwwroot\weatherdata\data.csv directory in line 1. This is just to show the functionality of the copy command. It is redundant and a unnecessary step.
Line 4 is another copy action where we take the created HighsAndLows.htm and copy out to our web server’s weather data directory.
Line 5 is a run execute command line action. It is going to run the WeatherReader.exe (or any other executable, such as a batch file, FTP, or some other process) and pass in the %OutdoorTempDegF% variable into that application.
Line 6 is a request URL action. We are requesting a URL and passing the variables into the URL string. This can be useful if you need to transfer data to another computer that WUHU is not running on, useful for getting data into a web service or script that runs via a web server.
It takes this:
And requests the webpage just like a web browser would with:
Line 7 is a FTP put action. We are using the built in FTP function of WUHU to FTP the file to a FTP server.
ftp://user:password@server[:port] [ASCII | BINARY] "local file" "remote file" ["local file" "remote file"] ...
In this example we would transfer one file from the local drive to your server and store the file under the \data directory on the server. Beware that the remote file specification is probably case-sensitive, this includes path names (\data) as well as forward slashes OR backslashes depending on the type of FTP service that is receiving the file.
As with other actions, the double quotes are required when specifying paths and filenames in order to support long path names that can contains spaces. You must use the double quotes on both the local *and* the remote path and file specifications even if the server does not support long file names. Never use spaces in the filenames on the remote server if it does not support this. If you do use spaces in the filename where it is not allowed, the transfer will always fail.
The ASCII transfer mode is initially assumed. You can change from ASCII to binary mode transfers by placing the keyword ASCII or BINARY before the specified file pair.
ftp://bob:firstname.lastname@example.org BINARY "C:\Program Files\WUHU\data\data.csv" "\data\data.csv"
You can switch modes between transfers like this:
ftp://bob:email@example.com BINARY "C:\Program Files\WUHU\data\data.csv" "\data\data.csv" ASCII "C:\Program Files\WUHU\data\anotherdata.csv" "\data\anotherdata.csv"
You can specify the port to be used for FTP transfers. By default most servers use port 21. You can override this by specifying the port after the server name (in this case, port 22):
ftp://bob:firstname.lastname@example.org:22 "C:\Program Files\WUHU\data\data.csv" "\data\data.csv"
You can enable passive mode by using the ‘P’ flag immediately after the port number. This example uses port 21 with passive mode:
ftp://bob:email@example.com:21P "C:\Program Files\WUHU\data\data.csv" "\data\data.csv"
There is a new option on the log screen for monitoring FTP transfers. To watch the details of the transfer, un-check ‘Only Errors’ and all of the other upload types except the FTP uploads.
Note: If you want the action to be performed every time the weather data is received from the console, leave the On Update Seconds unchecked. Just make sure that the actions with in the Action.txt can complete in time before the next update is received.
File copies happen in a matter of seconds, but a FTP might time out.
If your uploads fail and your FTP server is a Unix system, it might require a forward slash ”/” instead of a back slash “\” on the destination file.
ftp://bob:firstname.lastname@example.org:21 "C:\Program Files\WUHU\data\data.csv" "/data/data.csv"
Line 8 is a FTP put wild card action. We are using the built in FTP function of WUHU to FTP all files in the C:\program files\wuhu\data\ to a FTP server.
ftp://bob:email@example.com "C:\Program Files\WUHU\data\*.*" "\data\"
This would upload all files from the local directory (C:\program files\wuhu\data\) that match the filespec of *.* using binary mode and passive transfers. WUHU will then upload those files to the remote directory (\data\) on your server. If the local file string contains a ? or a *, then it is assumed that you are performing a wildcard upload. When you are performing a wildcard upload, the meaning of the destination (/data/) is changed from destination file to destination directory.
If the remote directory doesn’t exist WUHU will create it.
Create the template files
Put the csv.txt template and HighsAndLows.txt template in the C:\Program Files\WUHU\templates directory. Modify them as necessary.
Get to the Alerts/Actions configuration dialog
Click on the Alerts/Action button on the WUHU main dialog.
Enable the Sound/Action.
Select the check box to enable On Weather Update, as well as the On Update Seconds. This will enable WUHU to perform the Sound/Actions every 300 seconds.
Note: If you want the action to be performed every time the weather data is received from the console, leave the On Update Seconds unchecked. Just make sure that the actions with in the Action.txt can complete in time before the next update is received. File copies happen in a matter of milliseconds, but a FTP transfer takes longer.
Define where the action file is
Now that we have our Action.txt, templates, and destinations setup (and yes the source and destination files/directories have to exist, as well as having the correct rights to write to them) we can configure WUHU to perform the Sound/Actions with in the action file we just created.
From the main WUHU screen, click on the Sound/Action button next to the On Weather Update.
Define where you saved the Action.txt
Click on browse
Change the file type to Action Files (*.txt) and select the Action.txt, then click Open
Your Action on Activation now should look like below, Click OK to save and exit
Click Save Changes to exit. WUHU will run the Action.txt file every 300 seconds.
Note: For testing purposes you might want to uncheck the On Update Seconds and check your output files for real data. If you uncheck the On Update Seconds, this will cause WUHU to run the action file defined under Sound/Action every time data is received.