Device-WxM2
view release on metacpan or search on metacpan
The only parameter to &new is the port to which your weather station is
connected. The constructor initializes all the class variables and
configures the Device::SerialPort parameters for the Davis Weather
Station.
Note: I found that I had to fiddle with a parameter in the SerialPort,
called 'read_const_time', which is like a timeout value when waiting for
read data. I found that the value needed to be increased significantly
for the WxM2. I use 5000 (units are milliseconds) and this is the
default setting in this package. Should you need to change it, use
&setSerialPortReadTime(time_in_millseconds). Then call &configPort,
which puts the new setting into effect.
If you want to change to archive period, use &setArchivePeriod and
&getArchivePeriod. Just remember that if you screw up the values, you
station's archive will behave strangely until you fix it.
Use &getLastArcTime and &setLastArcTime to establish the time at which
the archives are captured into the weather station's archive memory.
Individual Access Functions
There are a bunch of individual functions that retrieve one weather
value from the weather station, such as b<&getOutsideTemp>. These are
fairly self-explanatory.
Archive Retrieval and Logging Functions
There are 2 primary archive retrieval functions:
&getArcImg - get Archive Image
&getSensorImage - get the "live" sensor data image
&getArcImg retrieves the archive image at the address given to it as a
parameter. To retrieve the most recent archived image, use this:
my $lastPtr = $ws->getLastPtr;
my @archiveData = $ws->getArcImg($lastPtr);
&getArcImg takes the archive data, reformats it where necessary, stores
the results in class variables, and returns an array of the data.
@array= ($avgInsideTempInArchivePeriod,
$averageOutsideTempInArchivePeriod,
$outsideTempMaximumInPeriod,
$outsideTempMinimumInPeriod,
$barometricPressure,
$avgWindSpeedInPeriod,
$avgWindDirInPeriod,
$maxWindGustInPeriod,
$rainInPeriod,
$insideHumidity,
$outsideHumidity,
$monthOfSample,
$dayOfSample,
$hourOfSample,
$minuteOfSample,
$outsideTempHumIndex,
$outsideTempHumIndexMaximum,
$avgWindChill,
$windChillMinimum);
&getSensorImage enables a continuous streaming of "live" weather data
from the Davis Wx Station. I've found this stream to be very easy to get
out of sync, so this funcion reads a single block, stops the streaming,
and flushes the serial receive buffer. The data returned by this
function are the current values and not average values within a sample
period, like &getArcImg returns. The array returned is as follows:
@array = ($insideTemp,
$outsideTemp,
$windSpeed,
$windDirection,
$barometricPressure,
$insideHumidity,
$outsideHumidity,
$totalRainfallToday);
There are 4 configuration functions for logging the archive data:
&setArchiveLogFilename - set the name of the log file to write
archive data
&getArchiveLogFilename - returns the name of the log file
&setStationDescription - sets the station description text (used by
&printRawLogHeader)
&getStationDescription - returns the station description string
Use &setArchiveLogFilename to set the log file name. It is used by all
logging function calls in the class.
There are two logging functions:
&archiveCurImage - Writes the periodic data samples to a file
&printRawLogHeader - Prints Header for the periodic samples log file
&archiveCurImage writes the data samples held in the class variables to
a filename passed in as its only parameter. For example,
$ws->archiveCurImage();
will write the data samples as 1 line of data in the file
&getArchiveLogFilename.
&printRawLogHeader writes a header for the data samples into the
filename in &getArchiveLogFilename. The second line of the header for
your weather station description. Set it with
&setStationDescription("description"). Typically it contains the name
and location of the weather station.
The function &batchRetrieveArchives is handy for retrieving multiple
archived images from the WxM2's archive memory. I use it primarily after
an extended power outage, but there are lots of other reasons to use it.
Us is at follows:
$ws->batchRetrieveArchives($number, $filename);
where $number is the number of archives to retrieve starting with the
most recent and counting back. And $filename is the string for the file
to write all the archive to.
The function &updateArchiveFromPtr is a low-level function that
retrieves archives from an initial pointer value. &batchRetrieveArchives
is a user-friendly front-end for this funtion. In most all cases
&batchRetrieveArchives should be used. Just in case, you can use
&updateArchiveFromPtr as follows:
( run in 0.885 second using v1.01-cache-2.11-cpan-39bf76dae61 )