Sensorlogger
Software requirements
A system with support for 64 bit integer datatypes (C++ uint64_t) must be used. Usually, this is also the case for 32 bit architectures such as the Raspberry Pi or the Tinkerforge Red Brick. If 64 bit integers are not supported, Sensorlogger will show undefined behavior, because UNIX time stamps are processed with millisecond resolution.
Known software requirements for Linux:
- C++17 compiler, such as GCC 7 or higher
- For the MQTT option: Paho MQTT C and C++ libraries (and their dependencies)
- For the HTTP option: Libcurl and its C++ developer tools
Download
The software is available on Github, or you can download the source code here.
The source code is available here under the MIT license. The following guide will give instructions on how to compile and run Sensorlogger.
sensorlogger.tar.gz Version 1.2 / 400 KB
There is no warranty given for correct operation of the software.
Compilation
The software can be compiled with support for several libraries or interfaces. You can decide which ones you need. The first lines in the makefile contain three options that you can activate (true) or deactivate (false) as you wish.
# Options to choose which interfaces and libraries should be supported: OPTION_CURL = true OPTION_MQTT = true OPTION_TINKERFORGE = true
- OPTION_CURL is needed for any HTTP(s) connections. This can be the case if JSON structures must be loaded from the internet or if you want to communicate with a HomeMatic CCU.
- OPTION_MQTT is needed if you want to communicate with an MQTT Broker.
- OPTION_TINKERFORGE activates support to communicate with a Brick Daemon to read Tinkerforge Bricklets.
Curl Support
If your Sensorlogger must connect to a HomeMatic CCU or if you want to load JSON information from the internet, you need to compile with support for libcurl. Make sure that it is installed:
apt-get install libcurl4
In addition, the developer tools for libcurl are required:
apt-get install libcurl-dev
The virtual package libcurl-dev offers different implementations. All of them should work, I have tested:
apt-get install libcurl4-gnutls-dev
MQTT Support
If you need support for MQTT, the Paho MQTT libraries for C and C++ must be installed. You can get packages for Arch-based distributions for the AUR: paho-mqtt-c-git and paho-mqtt-cpp-git. For Debian-based systems (e.g. Raspberry Pi, Tinkerforge Red Brick) we have to compile and install the libraries on our own. To do this, we need to make sure that we already have all the required packages installed:
apt-get install libssl-dev build-essential gcc make apt-get install cmake cmake-gui cmake-curses-gui
We now use git to download the Eclipse Paho MQTT C library, and compile and install it according to its documentation:
git clone https://github.com/eclipse/paho.mqtt.c cd paho.mqtt.c sudo make install cd ..
In the next step follows the Eclipse Paho MQTT C++ library. If you also want to install the documentation and compile the examples, set the corresponding flags in the following command in the third line to TRUE.
git clone https://github.com/eclipse/paho.mqtt.cpp cd paho.mqtt.cpp cmake -Bbuild -H. -DPAHO_BUILD_DOCUMENTATION=FALSE -DPAHO_BUILD_SAMPLES=FALSE sudo cmake --build build/ --target install sudo ldconfig cd ..
Tinkerforge Support
The necessary source code for the Tinkerforge C/C++ bindings is already included, no extra steps need to be followed if you want to compile with Tinkerforge support.
Compiling Sensorlogger
To compile Sensorlogger, run make. Take the source code either from GitHub or download it manually from this page.
git clone https://github.com/davidplotzki/sensorlogger cd sensorlogger make
Startup
To run Sensorlogger, you can pass the path to a configuration file:
./sensorlogger /home/username/my_sensors.json
If you don’t provide the path to a configuration file, Sensorlogger will look for one under the name sensorlogger.json in its current working directory. If it doesn’t find one, it will quit.
Sensorlogger as a service
It is recommended to run Sensorlogger with restricted privileges. The setup procedure for an automatic startup at boot time depends on the distribution. For Debian/Raspbian, I use a service file for systemd like the one shown below. It assumes that the executable file named sensorlogger is located in the user’s home directory at /home/username. The configuration file called config.json is also located there in this example.
# /etc/systemd/system/sensorlogger.service # ------------------------------------------ # systemctl daemon-reload # systemctl enable sensorlogger [Unit] Description=Sensorlogger [Service] WorkingDirectory=/home/username ExecStart=/home/username/sensorlogger /home/username/config.json User=username Group=users [Install] WantedBy=multi-user.target
You could then use the following two commands to load the service into systemd and enable its automatic startup:
systemctl daemon-reload systemctl enable sensorlogger