Installing pywws and running it as a Daemon

I have been using pywws for a number of years to download the data from my weather station and it simply just works.  There is good support from the author though there are some gaps in the documentation.  Moving pywws to the new Pi gave me the opportunity to update the package which had not been done for a while (ain’t broke don’t fix).

The weather station is a WH1080 compatible system from Maplin.  It is often on offer for about £60 and you can buy spares for all the external parts including the transmitter at a very reasonable price which is a major bonus.

Installing pywws via pip is relatively painless but what I would urge, is that you check out the dependencies first and get them installed before the main package.  It is easy to miss or skip over this step.  There are 2 options for USB libraries and I plumped for the libsub pip install libusb1 .

One of the beauties of this weather station and pywws combination is that the weather station itself stores data so you can disconnect the USB from the base station to play and not lose any data as it just catches up once reconnected.

Once installed, I plugged in the weather station to the new pi to check that it was communicating – I had to do the changes suggested as it would only work as sudo otherwise. Doing this test also created some of the system files.

I then pulled across all the data files using rsync plus a couple of system files I had modified.  These modifications allowed pywws to communicate to EmonCMS and to put data out on mqtt. The way this is setup is a little convoluted (to my mind), not that well documented, and it had taken me a while previously to work it out. To do it you need to create a new ‘service’.

New pywws service

To create a new pywws service you need to create 2 files in the service folder(/usr/local/lib/python2.7/dist-packages/pywws/services), a service file and a template.  The template is used to create the format of the message you wish to send and the service file defines some of the parameters that the template may use.  By defining the parameters correctly, you can also change these in the main configuration file weather.ini in the data folder.

I have created a GitHub repository for the new service files for EmonCMS.  I am using the http API for pushing the data to EmonCMS. One of the problems I had in setting this up is that EmonCMS does not accept valid JSON so it took a bit of time to get the template right.

Running pywws live-logger as a Daemon

Pywws has a daemon version of the main logging script using python-daemon. I have never felt completely comfortable with this as it seems to me that by following the instructions, you can end up with a daemon starting a daemon. The original install was Wheezy based so I had created a file for init.d to use (available from the GitHub repository) but on the newer Jessie based system, I thought I’d try a systemd setup.

After reading this excellent guide on systemd, I generated the following service file and placed it in the systemd folder (/etc/systemd/system).  After a couple of minor teething problems, I got it running and it has just worked since.  This seems a better solution.

Monitoring pywws

On the old Wheezy system, I used Monit to monitor both the daemon and a specific folder.  For a while, pywws had a habit of just stopping the writing of data.  The daemon was still running just no data appeared. I therefore set Monit up to monitor a specific folder to check it was modifed regularly.  As I have installed Monit I brought this across (also on the GitHub repository).

However, one of the advantages of systemd is that it has built-in monitor and restart functionality so Monit cannot be used to monitor the daemon itself.

Final Steps

Once I was happy that the system was working fine, I plugged the weather station back into the original Pi, restarted it and left it running for a while to catch up.  I then stopped the daemon, used rsync to copy across the files again (I blatted that data on the new Pi first just to be sure) and plugged the station into the new Pi.  A quick reboot and it all seems very happy.

All that remained was to set up some web access but that is another blog.

Facebooktwitterby feather
This entry was posted in Technical - General. Bookmark the permalink.

Leave a Reply