You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
3.8 KiB

+++
title = 'Moving WeeWX to OpenBSD'
aliases = '/posts/2023-05-27-moving-weewx-to-openbsd'
summary = '''I moved my WeeWX setup to my new server, which is running OpenBSD
7.3.'''
date = '2023-05-27T23:19:53+02:00'
# lastmod = ''
categories = [ 'amateur-radio' ]
tags = [ 'wx', 'weewx', 'netatmo', 'aprs', 'openbsd', 'server', 'selfhost' ]
+++
I've moved my server to a new provider and changed the OS within this task from
[Rocky Linux](https://rockylinux.org/) to [OpenBSD](https://www.openbsd.org/).
## Installation of WeeWX
The [Installation Guide](http://weewx.com/docs/setup.htm) is very useful and
you should follow its procedure.
I installed WeeWX into `/home/weewx`. I also created a new user named _weewx_.
```
weewx:*:999:999:WeeWX Daemon:/home/weewx:/sbin/nologin
```
Also install some prerequisites:
```
pkg_add py3-configobj py3-serial py3-pyusb py3-pip py3-cheetah py3-jplephem py3-pymysql
```
```console
$ python3 ./setup.py build
$ doas python3 ./setup.py install
```
Optionally install ephem:
```console
$ doas -u weewx pip install ephem
```
You may want to change owner of the installed files (in case you didn't create
the weewx user beforehand and used the root user for that before).
```console
# cd /home/weewx
# chown -R weewx:weewx .
# cd /var/www/weewx
# chown -R weewx:weewx .
```
### Finally installed python stuff
```console
# pkg_info | grep py3 | awk '{ print $1 }'
py3-chardet-5.1.0
py3-cheetah-3.2.6p3
py3-configobj-5.0.6p7
py3-jplephem-2.18p0
py3-numpy-1.24.1
py3-pip-23.0.1
py3-pymysql-1.0.2p2
py3-pyusb-1.2.1
py3-serial-3.4p5
py3-setuptools-64.0.3p1v0
py3-six-1.16.0p2
```
```console
$ doas -u weewx pip list
Package Version
---------- -------
chardet 5.1.0
Cheetah3 3.2.6
configobj 5.0.6
ephem 4.1.4
jplephem 2.18
numpy 1.24.1
pip 23.0.1
PyMySQL 1.0.2
pyserial 3.4
pyusb 1.2.1
ranger-fm 1.9.3
setuptools 64.0.3
six 1.16.0
```
## Setting up the start script
I've put the following file into `/etc/rc.d/weewx`:
```sh
#!/bin/sh
# Start script for FreeBSD, contributed by user Fabian Abplanalp
# Put this script in /usr/local/etc/rc.d then adjust WEEWX_BIN and
# WEEWX_CFG values in /etc/defaults/weewx
# some small modifications by Dominic Reich “OE7DRT”
WEEWX_BIN="/home/weewx/bin/weewxd"
WEEWX_CFG="/home/weewx/weewx.conf"
#WEEWX_PID="/var/run/weewx/weewx.pid"
WEEWX_PID="/home/weewx/weewx.pid"
DOAS="/usr/bin/doas -u weewx"
# Read configuration variable file if it is present
#[ -r /etc/defaults/weewx ] && . /etc/defaults/weewx
[ -r /home/weewx/defaults ] && . /home/weewx/defaults
case "$1" in
"start")
echo "Starting weewx..."
${DOAS} ${WEEWX_BIN} ${WEEWX_CFG} --daemon --pidfile ${WEEWX_PID} &
#echo $! > ${WEEWX_PID}
echo "done"
;;
"stop")
echo "Stopping weewx..."
if [ -f ${WEEWX_PID} ] ; then
kill `cat ${WEEWX_PID}`
rm ${WEEWX_PID}
echo "done"
else
echo "not running?"
fi
;;
"restart")
echo "Restarting weewx..."
$0 stop
sleep 2
$0 start
;;
*)
echo "$0 [start|stop|restart]"
;;
esac
```
Add `weewx` to `pkg_scripts=` in `/etc/rc.conf.local` and start it with
```console
$ doas rcctl start weewx
```
## Status text for APRSWXNET (aprs.fi)
I do also send a status message which adds a nice link back to my weather
website on
[aprs.fi](https://aprs.fi/#!call=a%2FOE7DRT-13&timerange=3600&tail=3600).
This is basically done with a python script run by cron every hour.
```python
#!/usr/bin/env python3
"""sending aprs status packets for my weather station"""
import aprslib
def main():
"""main func"""
AIS = aprslib.IS("OE7DRT-13", passwd="*****", port=14580)
AIS.connect()
AIS.sendall("OE7DRT-13>APRS,TCPIP*:>Weatherpage: https://wx.oe7drt.com\r\n")
if __name__ == "__main__":
main()
```
```console
$ crontab -l
57 * * * * python3 /home/dominic/bin/aprs_sendstatus.py
```