-
Notifications
You must be signed in to change notification settings - Fork 297
Raspberry Pi
Running WeeWX on a Raspberry Pi has become very popular. You'll have to look elsewhere for general instructions on setting up your RPi, but here are a few problems that are specific to WeeWX.
First, you simply must run a time synchronization service. It is not possible to create a dependable data logging system without an accurate source of time. See the Wiki article Time services.
Second, the RPi does not have an onboard battery-powered clock. Instead, by default, the software is configured with a "fake clock," which regularly records the time on the hard disk. If there is a power failure, then this time is used to set the clock during the reboot. Unfortunately, this time could be hours behind the real time, depending on how long the power was out.
Meanwhile, if you are running WeeWX as a daemon, WeeWX will also start up and try to run with this seriously out-of-date time. When it comes time to store a record to the database, it will either be stored under a too-old timestamp, or there may already be a record for that timestamp (duplicate primary key), left over from before the power outage.
Eventually, whatever time synchronization service you are using starts up, finds an authoritative time source, then sets the time correctly, but this could take several minutes and, by then, the damage has been done.
There are a number of solutions. Here are two.
The best solution is to add a real-time clock. They are inexpensive ($5-$15 USD) and solve the problem permanently. Users have had good luck with these clocks:
- Jameco Electronics
- SunFounder DS3231 on Amazon.
- Makerfire DS1307 on Amazon
- DS3231 module on Aliexpress. Under $1!
For Raspberry Pi-2 models, detailed RTC installation and Raspbian configuration instructions can be found from W0CHP's WX Station web site.
For Raspberry models running Jessie, see some hints on the page pi RTC with jessie.
As of Version 3.4, WeeWX will not start up until the system time is later than 1 January 2000. So, a simple solution is to remove the fake clock. Without the fake clock, the system time will literally start at "time zero," or unix epoch time zero, which is midnight 1-Jan-1970, far before what WeeWX is expecting. WeeWX detects this very early time and sleeps until NTP can set the true time. Then it proceeds.
Depending on what version of Raspbian your RPi is running, there will be one of two versions of fake clocks. Try this,
$ sudo apt-get purge fake-hwclock
If that doesn't work, then try this:
$ sudo systemctl stop systemd-timesyncd
$ sudo systemctl disable systemd-timesyncd
The article How can I delay the startup of systemd services until the datetime is set (no RTC on the Raspberry Pi) has some very useful hints on a more elegant solution.
The SD card supplied with most RPis seems to be of very low quality. Make sure you use a good, Class 10 card. User William Phelps reports, "You can usually spot a failing card by watching the kernel I/O wait time. Once the card starts to go, the I/O wait time will increase significantly."
Many users have had good luck with the better Sandisk SD cards. In increasing order of quality (and expense):
- Sandisk Extreme
- Sandisk Extreme Plus (what I use)
- Sandisk Extreme Pro
Historically there have been SD card issues on older pi. While this occurred most often on the old model-B pi, it does occur occasionally on the newer zero/zerow/pi3/pi3+/pi4 cards that use micro SD cards that have weak power supplies.
It is possible to tweak the operating system so that it does not write to the SD as much.
Detailed instructions are in the Wiki article about minimizing writes to disk.
Many Raspbian versions of Debian do not seem to include an FTP client. You may have to install this if you plan on using FTP.
$ sudo apt-get install ftp
A lot of problems with the RPi seem to center around inadequate power supplies. Many weather stations can demand a lot of current through their USB connection. Make sure your RPi can supply it, either by getting a good power supply, or, alternatively, by using a powered USB hub. I use an Innogear 1.5 A supply, which costs well under $10 USD from Amazon, but, unfortunately, it is not offered any more. This Samsung charger is essentially similar.
The RPi is astonishingly powerful for its size, but it does have its limitations. If you plan on running a webserver on it, perhaps to serve your home, then use a lightweight one, such as lighttpd, or nginx. Apache works, but it uses far more memory. In my tests:
Webserver | VIRT | RES |
Apache | 222 Mb | 3 Mb |
lighttpd | 7 Mb | 2 Mb |
nginx | 11 Mb | 1.7 Mb |