Introduction
One of the roles covered by the Raspberry PIRaspberry PI SBC in this project is the IoT gateway controlling the EnOcean sensors network. As the IoT sensors are based on the enOcean technology adopting of the enOceanPIenOceanPI gateway on the Raspberry PI some C++ programs are needed to get the control of the IoT architecture running on a headless environment; the web based approach e.g. with Fhem is a problem and the better solution requires working directly with the EnOcean libraries and APIs.
In particular enOcean provides the EnOcean Link library (very well documented). This library exposes a number of APIs to easily manage the sensors network through the ESP3 proprietary protocol.
The EnOcean Link library need to be compiled from sources; managing this complex IoT network other C++ programs will be written for the project: it is expected to develop a number of command line programs, mostly based on this library APIs.
It is possible to develop and compile the entire system on the Pi platform but it is the worth work with the code in a more comfortable environment: a IDE is more than a simple editor. It helps documenting the code, editing more proficiently the sources, make a good code analysis, manage efficiently a source versioning (e.g. GitHub or GIT, Mercurial, SVN etc.) and so on. This is the reason that I setup a Ubuntu VirtualBox VM for cross-compiling the Raspberry PI C++ programs that will be part of the project.
Setup the EnOcean Pi cross compiling environment
The EnOcean Link library (aka EOLink) does not provide direct sources of documentation and after a long search on the official enocean.com site I have not found nothing related to the EOLink library. Exploring the sources I have appreciated the availability of the entire library manual and API documentation in Doxygen format; a navigable version with internal search features as a static html site has been compiled and it is attached to this post. Together with the EnOcean Link User Manual (also attached as Product Information Sheet EnOcean Link pdf file) the scenario is almost complete.
Remain a problem: what about the Raspberry PI usage ?
Searched again on the enocean.com site ("enocean pi" keywords) and found the abstract of a webinar:
Smart Home with Raspberry Pi and EnOcean
Nice, I suggest to read it but unfortunately also this documentation dates June 2014.
Where to find more ?
Definitely the solution was googling. Searching EnOcean Link Manual keywords I have finally found a useful document integrating very well the included information with the documentation in the library sources. But more important than the downloadable pdf is the online documentation: https://www.enocean.com/fileadmin/redaktion/support/enocean-link/index.html It is very similar to the Doxygen version including one more chapter: a step by step EnOcean PI library installation. Unfortunately also these instructions are out of date and need to be reviewed before making them working in the actual scenario.
What we have one is merging some of the information included in the chapter Compile for Raspberry PI and the Step by step section about Eclipse installation and cross-compiling with other sources.
Step1 - Ubuntu + Eclipse environment
First of all, we should install Eclipse on the desktop machine that will cross-compile the Raspberry PI software. In the Step by step section ignore the chapter Installing Eclipse as you risk to download and install a too old version of the C/C++ development environment. Eclipse is available on any platform but accordingly with the guide I have setup a VirtualBox Virtual Machine running Ubuntu 16.04LTS 32 bit. After some previous experiments the 32 bit version seems the most reliable installation.
To install Eclipse instead I suggest the Last distributed version, Eclipse neon choosing the flavour C/C++ Better if you include in the installation the options for the source version control GIT. At the end of the installation process we are ready to start the cross-compiling setup.
Don't forget to install also the last version of the JRE (Java Runtime Environment, supposed to be JRE 8) required by Eclipse to run. The actual date last version of the JRE is accessible from the Oracle website but you can install it also directly from Ubuntu via the Synaptic user interface or the command line apt-get install. JRE is one of the default packages available from the Ubuntu standard repositories.
Step2 - Cross compiler for Raspberry PI
Now we should install the Official Raspbian cross compiling toolchain for the Eclipse for C/C++ for developers under Linux. The most reliable how-to I found is the Development Environment for the Raspberry Pi using a Cross Compiling Toolchain and Eclipse article. We will follow only the first part of this tutorial related to the cross compiler setup; to make the things easier the relevant steps and terminal commands are reported below:
Install the GIT control version build essentials
sudo apt-get install build-essential git
We need this setup to install the cross compiler, downloadable from the GitHub repository available here;
Install the Raspberry PI compiler toolchain
From the terminal, in your home directory create an rpi folder (the name is just an example, you can name it with your preferred mnemonic folder name) then clone inside this folder the toolchain components. It needs some minutes to complete the repository cloning.
cd ~ mkdir rpi cd rpi git clone git://github.com/raspberrypi/tools.git
When it has finished go to the following folder
cd ~/rpi/tools/arm-bcm2708
where you can see these four folders:
enrico@BalearicDynamics:~/rpi/tools/arm-bcm2708$ ls arm-bcm2708hardfp-linux-gnueabi gcc-linaro-arm-linux-gnueabihf-raspbian arm-bcm2708-linux-gnueabi gcc-linaro-arm-linux-gnueabihf-raspbian-x64 arm-rpi-4.9.3-linux-gnueabihf
with the command uname -a you see the current linux OS information:
enrico@BalearicDynamics:~/rpi/tools/arm-bcm2708$ uname -a Linux BalearicDynamics 4.4.0-31-generic #50-Ubuntu SMP Wed Jul 13 00:06:14 UTC 2016 i686 i686 i686 GNU/Linux
Setup the right system path update and test the toolchain running
As mentioned before as here it is running Ubuntu 16.04LTS 32 bit the processor is i686. If instead you read something like x86-64 or amd64 you are running a 64 bit operating system.
- For 32 bit OS we need the toolchain in gcc-linaro-arm-linux-gnueabihf-raspbian
- For 64 bit OS we need the toolchain in gcc-linaro-arm-linux-gnueabihf-raspbian-x64
So in this particular case the first option will be used. At this point remain only to add the toolchain path folder to the system path. Edit the ~/.bashrc configuration file:
enrico@BalearicDynamics:~$ gedit .bashrc
And to the bottom of the file the export path in the as shown below:
# add the Raspbian official GCC toolchain to the system path
export PATH=$PATH:$HOME/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin
Save the edited file and update the bash setting with the command
source .bashrc
This should be executed once avoiding the system reboot for the changes make effect.
Check if everything is ok with the command arm-linux-gnueabihf-gcc -v that should produce an output similar to the one shown below:
enrico@BalearicDynamics:~$ arm-linux-gnueabihf-gcc -v Using built-in specs. COLLECT_GCC=arm-linux-gnueabihf-gcc COLLECT_LTO_WRAPPER=/home/enrico/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../libexec/gcc/arm-linux-gnueabihf/4.8.3/lto-wrapper Target: arm-linux-gnueabihf Configured with: /cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/src/gcc-linaro-4.8-2014.01/configure --build=i686-build_pc-linux-gnu --host=i686-build_pc-linux-gnu --target=arm-linux-gnueabihf --prefix=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/install --with-sysroot=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/install/arm-linux-gnueabihf/libc --enable-languages=c,c++,fortran --disable-multilib --enable-multiarch --with-arch=armv6 --with-tune=arm1176jz-s --with-fpu=vfp --with-float=hard --with-pkgversion='crosstool-NG linaro-1.13.1-4.8-2014.01 - Linaro GCC 2013.11' --with-bugurl=https://bugs.launchpad.net/gcc-linaro --enable-__cxa_atexit --enable-libmudflap --enable-libgomp --enable-libssp --with-gmp=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-mpfr=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-mpc=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-isl=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-cloog=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-libelf=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --enable-threads=posix --disable-libstdcxx-pch --enable-linker-build-id --enable-plugin --enable-gold --with-local-prefix=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/install/arm-linux-gnueabihf/libc --enable-c99 --enable-long-long --with-float=hard Thread model: posix gcc version 4.8.3 20140106 (prerelease) (crosstool-NG linaro-1.13.1-4.8-2014.01 - Linaro GCC 2013.11)
If so, we are now ready to move to the next step.
Step3 - Setting up Eclipse for cross compiling
We should setup the Eclipse IDE to cross compile programs for the Raspberry PI. We can use Eclipse in future also for other kind of development, not necessarily for the Raspberry PI platform we will create a new simple project and set the cross compiler options at a project level. The same settings will be applied to any future project we need to be cross compiled for the Raspberry PI
Launch the Eclipse IDE creating a new workspace. Here a ~/Desktop/raspi workspace folder has been created.
From the Eclipse main window create a new C++ project as shown in the images below
Here we have created a HelloRasPi project based on a GCC toolchain. After confirming the other stpes with Next button you reach the GCC cross-compile settings dialog.
In the cross compiler prefix insert the prefix string arm-linux-gnueabihf- and in the path field insert the toolchain full path. See the images below for the described example
Press the Finish button and let's go coding. Create a new .cpp source file as in the example images below
Complete the source file creation with the Finish button and copy and paste the following simple source:
/* * helloraspi.cpp * Raspberry PI cross-compiler test prgoram */ #include <iostream> using namespace std; int main (void) { cout << "Hello Raspberry PI cross compiles program :)"<< endl; return 0; }
Build the project as shown in the images below
At this point in the Workspace project folder we should have a Debug folder with the compiled executable.
Step4 - Check the Raspberry PI compiled file
As shown in the images below, if you try to launch the HelloRaspPi program from the Ubuntu terminal you get an Exec format error This is normal, because we have cross compiled the program for the Arm Raspberry PI platform and not for the Intel Linux Ubuntu platform! Instead if you type the command file HelloRaspPi you can get information on the cross compiled application enabled to run on Arm Linux machines.
How can we run the program on the Raspberry PI ? The fastest way for now is copying the binary file on a USB pen and transfer it to the Raspberry.
After copying the complied program HelloRaspPi in a newly created folder on the Raspberry PI As you can see in the image below, after assigning the executable attributes with the chmod command the program executes correctly on the Raspberry PI.
Improving the cross compiling environment
Developing on a comfortable user environment like the Eclipse IDE supporting many language features like syntax checking, global searching, easy documentation and many other including a robust support for the version control (from GIT to SVN, Mercurial an others) obviously it is better than just editing files and compiling them on the Raspberry PI; with large and complex projects involving many sources the development environment can make the difference.
The very annoying and time consuming task is transferring the compiled executables to the destination machine, test them, identify the issues etc. But we can do something to dramatically improve this part: deploying remotely the complied programs directly on the target device.
Deploying the binaries remotely on the Raspberry PI
To setup the target Raspberry PI machine the only thing you need is to know the IP: the target device should be accessible by the desktop environment where the Eclipse cross compiler IDE runs via SSH.
All the other settings should be done in the Eclipse IDE environment.
Defining the remotes in Eclipse
The above images shows how to open the remote systems view in the Eclipse IDE perspective you are currently using. From the possible views, select the Remote Systems group and then Remote System Details. The Eclipse IDE at this point shows to the bottom a new view. The only element in the view is local corresponding to the computer running Eclipse. Right click the mouse on the list area and from the contextual menu select New - Connection.
Eclipse will show now the first dialog with the connection details. For the Raspberry PI we should select the following steps in the wizard:
When you press Finish a new device appears in the list.
Note that the Raspberry PI IP addrress and the remote connection name are referred to this example. You should insert the correct IP address of your remote Raspberry PI.
As explained by the above images, the first time you try to open the remote resource you are asked for the SSH user and password. It's up to you to save the user and/or the password for future uses or not.
Deplyoing the last compiled program remotely
When the environment settings are finished it is extremely easy to deploy the compiled programs to the raspberry PI, test them immediately and return to editing in seconds. Just compile and point-and-drag the binary in the desired remote folder. Then switch to the SSH terminal and run it.
Top Comments