BRIGADOON

Backyard Meteorological Instrumentation

Raspberry Pi 4 Set Up

Installing the Qt Enviroment and Database

While it is possible to use a cross-compiler for all development on the Raspberry Pi, this project installs the Qt Development Environment on the Raspberry Pi so that small developments and updates can be done directly on the Raspberry either locally with a keyboard and monitor or via VNC using just about any computer. In most cases, small bug fixes are done using the command line, rather than using the Qt Creator program locally.

The build requirements can be installed using the following commands:

$
sudo apt install clang

This will install the clang compiler and related development files. This will probably suggest the removal of unused packages such as
libfuse2 and suggested additional installations such as clang-11-doc, ncurses-doc, libpomp-11-doc, llvm-11-doc. Whether you take these suggestions is up to you.

The next step is to install the Qt Creator program. This provides the basics that are required to develop and compile Qt based programs, even if you don't intend to use the graphical Qt Creator.

$
sudo apt install qtcreator

Running this command will result in the installation of over 50~60 packages, so will take some time. Note that there are also about a half dozen suggest packages. The command below installs those suggestions, but this may vary for you.

$
sudo apt install qtbase5-dev clazy cmake meson subversion valgrind

Running this command will result in about 30~40 packages being installed and, or course, additional suggest packages. This time, I chose not to install the recommended files as I'm not interested in the documentation and subsequent installations will provide the other packages that may be useful.

Now it is time to install additional Qt5 libraries that will be most likely used in the current project. Replace the
libqt5sql5-mysql entry with libqt5sql5-sqlite if you intend to use the lower overhead SQLite.

$
sudo apt install libqt5serialport5 libqt5serialport5-dev libqt5sql5-mysql libqt5sensors5 libqt5sensors5-dev

$
sudo apt install libqt5remoteobjects5 libqt5remoteobjects5-dev libqt5texttospeech5 libqt5texttospeech5-dev

$ sudo apt install libqt5systeminfo5

The next part installs the MariaDB database. This database is selected purely because it is used on the main Linux server, otherwise a lower overhead database like SQLite would have been selected.

$
sudo apt install mariadb-client mariadb-server libmariadb-dev

When that has been installed connected to the database using the following command:

$
sudo mariadb -u root

Now create the database that you are going to use for the projects.

MariaDB [(none)]>
CREATE DATABASE YOUR_DATABASE_NAME;

Where
YOUR_DATABASE_NAME is the name of the database that you wish to create. For this project, the database is called WeatherStation, but change to suit your own requirements.

Confirm that your database has been created. The name of your database should be in the table called 'Database'.

MariaDB [(none)]>
SHOW DATABASES;

Now create a user for your database.

NOTE
: If you wish to grant all nodes access to the database, remove the '@localhost' from the commands but before you give this access, you will need to edit the configuration file from the command line;

$
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Find the line
bind-address = 127.0.0.1 and comment it out with a leading #. CAUTION: This represents a potential security risk if your LAN is not isolated from the Internet as external site will be able to attempt to access your database. Make sure that your firewall protects access to the database.

After that you can go back into the database.

MariaDB [(none)]>
CREATE USER 'username'@localhost IDENTIFIED BY 'password';

where '
username' is the user's name, and 'password' the access password. Note localhost means that the user needs to be logged into the node.

Confirm that your user has been created by entering the following command and confirming the username is in the table called 'User'.

MariaDB [(none)]>
SELECT USER FROM mysql.user;

Since we are looking to have an account that can control all databases, not just this one, global privileges are granted to the user just created. If you only want to give privileges to the database we just created, change *.* to YOUR_DATABASE_NAME.* - substitution your database name for YOUR_DATABASE_NAME. Also replace username and password as required.

MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* to 'username'@localhost IDENTIFIED BY 'password';

Now ensure the privileges are propagated through the system use the following command:

MariaDB [(none)]>
FLUSH PRIVILEGES;

Confirm the privileges are as expected by entering:

MariaDB [(none)]> SHOW GRANTS FOR 'username'@localhost;

The result table will be slightly different to what you entered the a command, as the password shown will be an encrypted version of the entered password.

This project provides access to this database to other nodes on the LAN as the gateway to the portion of the LAN providing access to the Internet is normally disabled unless the nodes are having their software updated. The Firewall to the Internet is set to prevent incoming connections on port 3306 (database port), so the risk of providing other nodes to access the database is low.

Allowing this access lets the Database Manager on the main node to manage this database and can easily be turned off, if necessary.


Licenced under Creative Commons Attribution Share Alike 4.0 International or better by Mark Little (2022 - 2023)