Remote Bifferboard powered weather station
So here’s the script. I have a Bifferboard, some USB wireless network devices, a W-8681 weather station, and a desire to capture the data remotely. I also have a VPN in which to transport it over, and some kind parents with a permanent network connection and wireless connectivity.
The Bifferboard has a somewhat unique bootloader, and the settings used are below. The firmware that’s been flashed on is the default from https://groups.google.com/forum/#!msg/bifferboard/HFjg0vd4iuI/WLYWcKnPAUYJ
bootsource: on-board flash
boottype: Linux 2.6 parameter block
cmndline: rootfstype=squashfs,jffs2 console=uart,io,0x3f8 init=/etc/preinit ubi.mtd=rootfs
If using the standard Biff image from http://sites.google.com/site/bifferboard/Home/factory-firmware then note the contents of http://sites.google.com/site/bifferboard/Home/howto/install-opkg-files
opkg install bash vim # Retain some sanity
Use ‘passwd’ to set a root password. This will disable telnet and automatically enable the dropbear SSH daemon.
uci set system.cfg1.hostname=weather1
For this task I was using a Ralink RT2870 USB device. This is normally supported by the kmod-rt2800-usb module. In my case, as I was building the firmware from scratch, I enabled it during the build process. It’s hidden in the Kernel Modules > Wireless subsection. Enable it as a kernel builtin, as making it a module just confuses matters.
opkg install wpad-mini # Handles WPA2
Execute the following command to generate a default config
wifi detect > /etc/config/wireless
Edit /etc/config/wireless to contain the following
config wifi-device radio0
option type mac80211
option channel 11
option macaddr 00:a1:b0:f2:14:da
option hwmode 11ng
option htmode HT20
list ht_capab GF
list ht_capab SHORT-GI-20
list ht_capab SHORT-GI-40
list ht_capab RX-STBC1
option device radio0
option network lan
option mode sta
option ssid Glasgownet
option encryption psk2
Execute ‘wifi’ to bring up the network
‘uci show wireless’ should also show the same settings.
I couldn’t be bothered finding out why wireless wasn’t automatically coming up at bootup, but I suspect it’s due to the USB devices being detected long after the network scripts are run.
To work around this, I used the @reboot function of cron. Use of cron was already on the cards, so it’s no extra work.
ln -sf /etc/crontabs/root /etc/crontab # For convenience
Execute ‘crontab -e’ and place the following line in it
@reboot sleep 60 ; /sbin/wifi
I tested it without the sleep 60, and it seemed to work. However, I’d rather be slow and confident rather than focus on speed. Better to let the system settle down for a minute before trying to bring up the interface.
Reboot to test, and be happy.
Bifferboard has no RTC, so an external time source is vital. However, as the network isn’t up immediately, the inbuilt rdate app fails to find anything. Easiest route around that is to install ntpclient and leave it to poll in the background. Once installed it will automatically use the uci configuration data for timeservers.
uci show timeserver
opkg install ntpclient
I have a VPN network in which to keep in touch with all my remote devices, be they phones, cars, weather stations, etc. As this weather station is going to be installed in a remote location behind a NAT router, by hooking it into the VPN I can access it remotely without having to worry about firewall tunnelling and other nastiness.
opkg install openvpn
Installing the packages sounded like an easy task, just opkg install openvpn and off you go, but sadly due to an ABI mismatch, the tun module oopses the kernel when the first packet arrives. Further info can be found at https://dev.openwrt.org/ticket/7511 The workaround for this was just to enable kmod-tun and openvpn in the menuconfig of the OpenWRT tree I was already building, and install those two ipk files that are generated.
Now that it’s installed, setting up OpenVPN is left as an excercise for the reader. You should just need a client configuration, 2 certificates, and keyfile. It may be worth noting that OpenWRT stores a lot of the OpenVPN settings in /etc/config/openvpn. I used my standard ‘client.conf’ that I use everwhere else, and modified /etc/config/openvpn to include /etc/openvpn/client.conf, and also enabled the instance so that it would be started automatically on boot. Both of those modifications are in the top 10 lines of the config file. If you’re setting up OpenVPN from scratch on the device, you really should just edit /etc/config/openvpn, or preferably use the uci set commands to configure it and then uci commit it at the end.
Once ready, enable it and start it
I had a spare 1GB memory stick that wasn’t really much use elsewhere. The hub also had 2 spare USB ports. Simple to use, just install the ext4 kernel module
opkg install kmod-fs-ext4
mount /dev/sda1 /mnt
Install fowsr on the Bifferboard, and periodically upload to server for processing
opkg install fowsr
Generate a SSH kay pair in order to provide passwordless uploads
dropbearkey -t rsa -f ~/.ssh/id_dsa
Copy and paste the public key output into id_dsa.pub for safe keeping
Stick the contents of id_dsa.pub into the authorized_keys2 file of the destination user on the destination machine
Grab the data with fowsr, and then upload it to the main server for processing.
cp /var/pywws.log /mnt/
rsync -avug /var/pywws.log firstname.lastname@example.org:weather_data/
BACKING IT UP
It might contain the tiniest of filesystems, at only 8MB, but there’s still a fair bit of work invested there. I may also have documented most of it here, but I’d rather not go through the entire process again!
For this I use rdiff-backup, which is documented elsewhere on the internet
Like this post? Tip me with bitcoin!
If you enjoyed reading this post, please consider tipping me using Bitcoin. Each post gets its own unique Bitcoin address so by tipping you're not only making my continued efforts possible but telling me what you liked.