Skip to content

Building and Installing

Paolo Bosetti edited this page Jul 15, 2024 · 15 revisions

Linux Local Hub

Networking

The mads-broker machine has the following Ethernet interfaces:

  • Intel Internet - Local one (mads-broker.local in MFJA)
  • 192.168.1.100 Ip4 (bottom plate on the MFJA Linux machine)
  • Realtek internet - Outside (MFJA Network)

Open a terminal and type sudo nano /etc/avahi/avahi-daemon.conf, then scroll down and replace no with yes in the lines starting with publish-hinfo and publish-workstation. This will broadcast on the local network the machine with the hostname mads-broker.local.

Install linux packages

Run the following:

sudo apt update
sudo apt upgrade -y
sudo apt install build-essential cmake cmake-curses-gui git gh clang libmosquitto-dev libmosquittopp-dev openssl libcurl4-openssl-dev figlet clang-format libgpiod-dev

Now:

sudo update-alternatives --all

and always pick clang or clang++ when asked. For the remaining choices, keep the default.

Visual Studio Code

Install Visual Studio Code, using Ubuntu App Center

Within VSCode, install a few extensions as gitgraph, CMake, CMake Tools, figlet, clang-format

Docker

Follow instructions on Docker website to install Docker, then also follow the post-installation steps.

Test if it works with:

docker run hello-world

It must work without asking you any password.

Network time protocol

On the broker

The broker shall also provide a Network Time Protocol service (ntp) to the local network. Proceed as follows:

sudo apt install chrony

Then edit the file /etc/chrony/chrony.conf and add the following lines at the end of it:

# Serve NTPD on the local network
allow 192.168.1.0/16

Then restart the service:

sudo systemctl restart chrony.service

See also here: https://ubuntu.com/server/docs/how-to-serve-the-network-time-protocol-with-chrony.

On other devices

Use the broker IP (192.168.1.100) as NTP Server address on other devices. On Raspberry, edit the file /etc/systemd/timesyncd.conf and change the [Time] section like this:

[Time]
NTP=192.168.1.100

Then restart the service:

sudo systemctl restart systems-timesyncd.service

Mongo DB

Run the following for creating a MongoDB instance. The database files will be created within the db folder in the directory where you issue the command:

docker run --name mads-mongo --restart unless-stopped -v ${PWD}/db:/data/db -p27017:27017 -d mongo

You can check if it is running with docker ps, stop it with docker stop mads-mongo, restart it with docker start mads-mongo.

Install Mongo Compass in Linux from website using Ubuntu: download it from https://www.mongodb.com/try/download/compass, then install it from the terminal:

sudo dpkg -i Downloads/mongo(complete the name pressing tab)

Open Compass and connect local database. If it won't work, check that docker ps returns a line with a running MongoDB instance.

Clone repositories

To manage the repositories, we use the gh command, which makes it easier to perform some operations (namely cloning and authenticating). First of all, the user needs to authenticate on GitHub. Type the following:

gh auth login

then follow the instructions.

Now you can clone the two repositories:

mkdir Level && cd Devel
gh repo clone <you_github_account>/MADS
gh repo clone <you_github_account>/mads_plugins

MADS repository

Configure and compile it:

cd MADS 
ccmake —BBuild # pick the proper CMAKE_INSTALL_PREFIX, typ. /usr/local, then type 'c' to configure and `g` to generate files
cmake --build build -j8

When you are done with the first compilation, you can enable the options MADS_SKIP_EXTERNALS and FETCHCONTENT_FULLY_DISCONNECTEDin ccmake, to speed-up further compilations.

Then you can install the results:

sudo cmake --build build -t install
mads

The last command shall give you the list of the available MADS commands.

You can test each agent with the corresponding commands, e.g. mads broker launches the broker, mads feedback opens the feedback agent, etc.

To create a service, so that an agent can run automatically on boot, you have to create a service file. The command mads service helps you in doing that. For example, to create a service for the broker, type:

mads service broker broker -d

where the first broker is going to become the name of the service, the second one is just the command (with possible options as -d).

Have a look at the result (it is just a printout), then repeat the last command with sudo:

sudo mads service broker broker -d

Now the Mads-broker.service is available and you can start, stop, check its status with:

sudo systemctl <start|stop|status> mads-broker.service

To have it run all the time and automatically (activate service) or to disable that behavior:

sudo systemctl <enable|disable> mads-broker.service

mads_plugin repository

As usual:

cd mads_plugins
ccmake -Bbuild # Set the CMAKE_INSTALL_PREFIX to /usr/local
cmake --build build -j8
cmake --build build -t install

Now the plugins are installed on /usr/local/lib. This is also the default search path for the source|filter|sink agents.

Check if everything works by opening two terminals. On one terminal run mads feedback to have a trace of network traffic. On the other terminal type:

mads source clock.plugin -p 500 # run clock.plugin within a source agent and set 500 ms as sampling rate

Note that to make this a service, the command would be:

sudo mads service clock source clock.plugin -p 500

then start and enable it as explained above.

Raspberry connection

When you configure the raspberry with the hostname <raspi_name> and enable the Avahi broadcasting of hostname, the raspi can be reached as <raspi_name>.local. To connect to it via ssh and log into the <username> account:

ssh <username>@<raspi_name>.local 

Only specify the username if it is different from the one on your current host.

You can avoid typing the password at each connection by way of secure certificates. First you have to create the certificate for the broker host:

ssh-keygen -t rsa

Then copy the certificate on Raspberry:

scp .ssh/id_rsa.pub <username>@<raspi_name>.local:.ssh/id_rsa.broker.pub

Then login into the Raspberry:

ssh <username>@mads-pi.local
cat .ssh/id_rsa.broker.pub >> authorized_keys

Log out and log in again: the password won't be needed anymore.

GUI compiling

The GUI MadsMetadata app can be also be compiled. It needs QT6 libraries:

sudo apt install qt6-base-dev

Then you have to enable the CMake option MADS_ENABLE_GUI:

cmake -Bbuild -DMADS_ENABLE_GUI=ON
cmake --build build -j8

The compiled app will be under build/GUI/MADSMetadata/MadsMetadata.

Clone this wiki locally