Weather Logging with Arduino and RasPi (The Sensor Side)

In this post I will shortly present how I implemented the data taking sensor with an Arduino, a Bosch BME280 (humidity, pressure and temperature), a DS18B20 (temperature) and a cheap 433MHz OOK (on-off keying) transmitter.

The Arduino

As I do not need a lot of processing power, I use an Arduino Pro Mini clone with 8MHz clock and 3.3V. With the proper configuration (using the Low-Power library) and removal of the power LED, it can be run with less than 100µA in sleep mode. Actually, the Arduino itself needs less than 10µA but the additional circuit elements need the rest.

DS18B20

The DS18B20 is a One-Wire temperature sensor. There are ready-to-use libraries available and multiple descriptions on the web how to read data from this sensor.

BME280

The BME280 is a pressure and humidity sensor by Bosch that has an integrated temperature sensor for temperature compensation of the measurements. It can be read by SPI or I2C bus and there are multiple libraries available. I tested the ones from Adafruit and SparkFun. Currently I use the SparkFun library (Github link) because if offers a function for direct register level access. This is vital for using the “Forced Read” mode which is significantly more power efficient than the “Normal” mode. Currently the forced read mode is not in the library but there is already a pull request that implements it.

433MHz Communication

433MHz transmitters are available for little money. The ones I use have three input pins: 5V, GND and Data. Essentially, the transmitter is an oscillator that is switched on and off by the data signal. Because of that, all intelligence is inside the library. I use the discontinued Virtual Wire library because it has a Python receiver available I can use on the RasPi side. I also added AES encryption using this library.

The Power Supply

For the power supply I use an LTC3105 step-up converter. It has two outputs:

LTC3105 DC/DC converter

LTC3105 DC/DC converter

The main output and an auxillary LDO. The LDO delivers 6mA which is enough for the Arduino and the sensors running at 3.3V. The main output is configured for 5V and provides power for the 433MHz transmitter. With this setup, the current consumption at a 1.2V NiMH accumulator is about 300µA in sleep mode.

Weather Logging with Arduino and RasPi (Overview)

My current project is a small weather station with distributed sensors. The setup is shown in the block diagram below.

Block diagram of one weather sensor together with the receiver and the associated sensors and functions.

Block diagram of one weather sensor together with the receiver and the associated sensors and functions.

The general idea is quite simple. The Arduino takes measurements roughly every 30 seconds and transmits them to the RaspPi. There, the raw measurements together with the ID of the Arduino (there may be more than one sensor) are collected in a raw data table inside a SQL database. The measurements from the raw data table are read by a CRON job every five minutes to generate average values (5min, 1h and 24h) for each sensor. The results are again stored in different tables. These tables are used by the web pages to show the course of the weather over the last few days. I plan to write a short post on each part of the chain during the next weeks.

Compressed File Upload with PHP and cURL

For a small web project I regularly have to upload new data files. I did this using FTP which is somewhat tricky to automate as I learned from a short search. In addition, compressing files for faster upload is also not supported (at least to my knowledge). The solution I finally decided to use is the following:

  1. Compress the files I want to upload using zip.
  2. Upload the files using cURL and a PHP script.
  3. Unzip the uploaded file in the script.

The method itself is VERY insecure because anyone knowing the server side location of the script (i.e. anyone) can upload files to the server. So additional security measures are necessary to prevent this. As I am no security expert, I do not give any recommendations how to do this because the probability of giving bad hints is very high (~1).

The Client Side
In order to upload two files fileA.ext and fileB.ext, two shell commands are necessary (I use Linux and assume the PHP script is named upload.php):

zip -9 upload.zip fileA.ext fileB.ext
curl form uploadfile=@upload.zip http://serverURL/upload.php

The Server Side
The server side PHP script (I use PHP 5.6) is quite simple:

$targetFolder = "/path/to/data/files/on/server/";
$zip = new ZipArchive();
$zip->open($_FILES['uploadfile']['tmp_name'])
$zip->extractTo($targetFolder,array('fileA.ext','fileB.ext'));
$zip->close();

For a real life implementation some checks if all operations were successful are recommended but in principle this script is supposed to work as it is.

DB0SIG Refurbished

The Setting

DB0SIG has been running for some years on the same hardware setup. This setup consisted of an old Alinco mobile radio and a TNC with APRS-Digi firmware. In the beginning the TNC had occasional bit flips what did not strengthen my confidence in the system. So, as time allowed, I ordered some new parts to assemble a new and hopefully more reliable and flexible APRS digipeater.

The new Setup

The new setup consists of the following parts:

…and this is how it looks all glued together. Obviously I forgot to buy a box.

DB0SIG_final2

Setting up the TNC-Pi

I ordered the TNC-Pi as a kit which apparently gave the guys at the German customs a little headache. After tracking said the packet arrived at the customs, nothing happened for almost two weeks. When I had almost given up on the project, the post woman unexpectedly delivered the packet after all. Building the kit by the manual worked very well. The only deviation I had was the voltage at the PIC being only 3V, not the stated 3.3V. After powering up the TNC-Pi on the Raspberry Pi, one has to disable the serial console that supplies debug output on the device /dev/ttyAMA0. This is the port where the TNC-Pi connects. For this I removed all references to the device from the boot command line in /boot/cmdline.txt and added enable_uart=1 to /boot/config.txt. After that and configuring kiss as stated in the manual, kissattach still failed. Some research brought me to the solution that you have to remove the line

T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

from the file /etc/inittab. One reboot later, everything worked as expected.

Setting up the RS-UV3

The RS-UV3 required some minor modifications to run with the power amplifier. The more interesting part was powering up the device to see if it is really working. As I had no USB-to-serial adapter at hand, I used an Arduino with the soft serial example as a simple interface and Minicom as the terminal.

The Software

On the Raspberry Pi, Raspbian was already installed. On the APRS side, I use APRX which can be downloaded here. OH2MQK provides .deb packages ready for the Pi. These can be identified by the armhf (instead of the i386) in the filename. When the file has been downloaded onto the Pi, the installation reduces to a simple dpkg -i aprx_2.08.593-1_armhf.deb. The final task was to adapt the configuration in /etc/aprx.conf to my needs. As the file is very well commented, it is easy to come to a working setup. In the long run some parameters may need some fine tuning. For example, I activated the telemetry but it generates a lot of traffic so I will probably deactivate it once the setup has been running stable for some weeks.