Skip to content

OpenDNP3 Raspbian Setup

Matt Magoffin edited this page Jan 24, 2024 · 7 revisions

Setting up OpenDNP3 on Raspbian

This guide outlines how we setup OpenDNP3 for use on Raspbian based SolarNodes. Currently Debian packages for OpenDNP3 are not available, so it needed to be compiled from source. To support SolarNode we need to include Java and SSL support. The target directory for the build is /home/solar so that it can be easily installed via a S3 Setup package. The /home/solar/lib directory is already part of the SolarNode library path.

Boot up a Raspbian SolarNode

First thing is to boot up a Raspbian based SolarNode. A Pi 3 or better will be helpful here, as we'll be compiling directly on the node and this is a lot slower on the older Pi hardware.

Install requirements

On the Pi SolarNode, the following software must be installed to build OpenDNP3:

$ sudo apt-get install git gcc g++ libc-dev cmake make patch libssl1.1 libssl-dev maven

Note that the 2.2.0 release will not compile with OpenSSL 1.1. See #227 (but it does with 1.0). Both 1.0 and 1.1 are available in Debian 9, so it's just a matter of making sure both the compilation and runtime environments have 1.0 available (libssl1.0-dev and libssl1.0.2, respectively).

$ sudo apt-get install git gcc g++ libc-dev cmake make patch libssl1.0.2 libssl1.0-dev maven

Note on other Debian systems, the openjdk-8-jdk (Debian 8) or openjdk-11-jdk (Debian 10) or openjdk-17-jdk (Debian 12) package should be installed as well:

$ sudo apt-get install openjdk-8-jdk

Checkout source, switch to release tag

Currently the release of OpenDNP3 used in SolarNode is version 2.3.2, so we'll use that:

$ git clone https://github.com/dnp3/opendnp3.git
$ cd opendnp3
$ git checkout 2.3.2
$ git submodule update --init

Debian 12 patch

The 2.3.2 source fails to compile on Debian 12 (GCC 12), without the following change in the cpp/libs/src/opendnp3/master/TypedCommandHeader.h file. Change the #include lines from

#include <>
#include <>

to

#include <>
#include <limits>
#include <>

Build

First build the C++ libraries:

$ mkdir -p build/native
$ cd build/native
$ cmake ../.. -DDNP3_JAVA=ON -DDNP3_TLS=ON -DDNP3_DECODER=ON \
	-DJAVA_HOME=/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt \
	-DCMAKE_INSTALL_PREFIX:PATH=/usr

$ make && make DESTDIR=$PWD/local install
[  6%] Built target openpal
[ 12%] Built target asiopal
[ 59%] Built target opendnp3
[ 60%] Built target dnp3decode
[ 67%] Built target asiodnp3
[100%] Built target opendnp3java
Install the project...

Note on other Debian systems, the cmake command would look more like:

# Debian 9
cmake ../.. -DDNP3_JAVA=ON -DDNP3_TLS=ON -DDNP3_DECODER=ON \
	-DJAVA_HOME=/usr/lib/jvm/java-8-openjdk-i386 \
	-DCMAKE_INSTALL_PREFIX:PATH=/usr

# or, Debian 10
cmake ../.. -DDNP3_JAVA=ON -DDNP3_TLS=ON -DDNP3_DECODER=ON \
	-DJAVA_HOME=/usr/lib/jvm/java-11-openjdk-i386 \
	-DCMAKE_INSTALL_PREFIX:PATH=/usr

Package for S3 Setup

Create a tarball for deploying with S3 Setup onto other nodes into the ~solar/lib directory:

$ tar czf opendnp3-debian9-armhf-2.2.0.tgz -C local/usr lib

Build Java bindings

Then build the Java bindings.

Note if trying to build the 2.3.0-M01 release, it fails to build. See #262. To work around, manually fix the bindings/src/main/java/com/automatak/dnp3/enums/IndexQualifierMode.java file by replacing the <= 255 with &lt;= 255.

$ cd ../../java

# Manually fix IndexQualifierMode.java here if building 2.3.0-M01...

# Manually fix the package version, if needed
$ mvn versions:set -DnewVersion=2.3.2

# May need to set JAVA_HOME
$ export JAVA_HOME=/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt

$ mvn install

The files are built to ~/.m2/repository/com/automatak/dnp3/opendnp3-bindings. For SolarNode, the opendnp3-bindings-2.2.0.jar file is necessary. It does not natively support OSGi, however, so it has been wrapped into the net.solarnetwork.external.opendnp3-bindings bundle.

Runtime

The OpenDNP3 libraries must be available to SolarNode. They can be copied into the ~solar/lib directory, or have them installed into a standard OS library location like /usr/lib. Copy the tarball created previously to those nodes, SSH to that node as the solar user, and extract it. Then make sure the libssl1.0.2 package is installed:

$ tar xf opendnp3-debian9-armhf-2.2.0.tgz
$ sudo apt-get install libssl1.0.2

The DNP3 port must be opened, which is 20000 by default. Add the following to /etc/iptables/iptables.rules:

# Allow DNP3
-A INPUT -p tcp --dport 20000 -j ACCEPT

The rule can be applied without restating via sudo iptables-restore /etc/iptables/iptables.rules.

Clone this wiki locally