MX on Linux
Using MX on UNIX-derived Operating Systems
MX runs on various UNIX-derived operating systems (OS), including those found on Apple Mac computers, and those found on devices running Linux.
Introduction
This article focuses on a device called the Raspberry Pi. It is a small board of electronics that can actually run Windows, Mac OS, Chrome OS, various Linux distributions, or the Raspbian OS (based on Ubantu Linux). In this article, the focus is on the last OS, because that is easiest to install, so look elsewhere on the web for details of installing alternatives.
The article will give you some guidance on:
- Choosing a Pi model to buy
- Setting it up,
- either connecting it to a keyboard, mouse, and monitor (could be TV), and internet (wired Ethernet or wireless)
- or running it headless, where all instructions are typed into another device and the Pi has no keyboard, mouse, or monitor, but is connected to internet (wired Ethernet or wireless)
- Installing OS
- Installing Mono
- Installing Apache, PHP, MariaDB, PhpMyAdmin, and copying your database from another device
- Running MX
Which Raspberry Pi to buy
First make a list of what you need
- Do you want to use a mouse and key board?
- If so, a model with multiple USB sockets is advisable (like 3B+)
- This also applies if you want to be able to plug in a USB stick (perhaps for transferring files between devices, e.g. Cumulus configuration and data folder files)
- Do you want a wired connection to your hub or router?
- Maybe you are going to update external sites, a wired connection may provide a faster and more dependable communication than a wireless link
- If so, a model including an Ethernet socket is advisable (like 0W or 2B+)
- Remember that if you are operating the pi in headless mode, a wired or wireless connection to your LAN is needed for your other device to communicate with the Pi
- Will your MX need to update a database, feed data to a web site, upload to external sites, or control other devices?
- If so, a model Zero will have to do each task in turn, and you will see some delay in information updates, plus you will need to use a larger time between updates
- If so, a model Three (or Four) will be noticeably faster, and permit you to select more options in MX, and to update external sites more frequently
- What interface does your weather station use?
- If your station communicates to MX via wireless, then you choose a model that supports wireless at the right frequency
- If your station communicates via Ethernet, then either a wired or wireless connection is possible to Pi as the station will be plugged into your hub or router
- If your station communicates to MX via USB, then choose between the model 0W with one USB socket, and the model 3B+ with 4 USB sockets
- If your station uses another communication port (such as serial interface), then you need the components that support that interface
Now research how the various models relate to your needs
You can look up online what features are included in the various Pi models, and how they differ in power consumption, and cost. But your decision also needs to consider what you need. Here, I won't describe all the different models, but concentrate on just 2 for simplicity. The model Zero W is appealing as it has low power consumption, it is perfectly adequate for running MX (but has limited speed, it runs the various threads MX uses sequentially) especially if you only use standard MX functionality and don't ask MX to do all the optional extras, and has limited interfaces for peripherals. The model Three B plus is appealing as it has medium power consumption, but can cope better with the multiple threads that MX starts, and has more interfaces built in, such as 4 USB 2 ports.
- Raspberry Pi Zero W
- Pi Zero W has WiFi and one micro-USB port which is all that is needed for headless running.
- Installing onto a faster Pi might speed parts of the installation process, but for actual ‘production’ running this slower Pi will be perfectly adequate.
- It could run a web server, but that might really slow it down.
- If you run this headless, all updates are done remotely, so the connectivity and speed of the actual Pi are less important
- Raspberry Pi Three B Plus
- The faster speed of this Pi although NOT necessary for running Cumulus MX, will cope better if you are asking MX to do lots of processing (e.g. updating database tables or external sites as well as standard processing).
- Pi Three B Plus has a socket for an external power supply, Ethernet socket (supports wired link); a HDMI socket for audio/video to TV, or computer monitor; a standard audio socket for external microphone, or speakers; 4 standard USB 2 sockets for weather station, mouse, keyboard, USB stick, or other storage device; plus other connections (e.g. camera).
- This might be better if you also want to run a web server, or other tasks on the same Pi.
- Also consider this model if it is to be used on a remote site so when you visit it is useful to be able to plug in a monitor and other peripherals, and to spend as little time on updating as possible.
Other models are available, but you need to check their specification against your needs. For example, the current model Four has more capability, but is less appealing as it also consumes more power.
What else to buy
This obviously depends on your PI model and on your weather station connection type.
You may want to buy a case, that will protect your Pi from accidental damage. A case specifically designed for your Pi model will have cut-outs in the right place for each interface connection, and will have sufficient ventilation for the electrical components to not over-heat.
You may need a power supply. This could be an official Raspberry Pi power supply. Alternatively, any power supply unit that has a micro USB connector will do, the power consumption of a Pi (whichever model) is fairly small, but it will be powered on 24/7, so a low power consumption ‘switched mode’ type is preferred – i.e. one that does not become warm when plugged in with nothing attached. You may have a suitable one left over from an earlier mobile phone.
You may need to buy connection leads. You may need a HDMI lead to connect your PI to your TV or a spare computer monitor. You may need a USB lead to connect to your weather station (the Pi model Zero requires a micro USB, the Pi model 3 requires a standard A end USB) and your station probably has a USB A end connection. If your weather station connects by Ethernet, you will need one lead to connect the station to the router and possibly another to connect the hub or router to the Pi.
If you do choose a model 3, consider whether you do want a USB mouse and USB keyboard to use with it. This Pi also supports Bluetooth connections.
Finally, you may wish to buy a second micro-SD unit as a spare, or some other USB connected (or network connected) storage for back-ups and extra storage needs.
Setting up your Pi
You can find, online, instructions about setting up a Pi. The obvious place to look is the manufacturer's web site, or the same documentation on their github page. However, you might look at a supplier's web site, or various other sources of "how to" advice.
The Micro-SD card
A Pi requires either a class 4, or a class 10, micro-SD card (or whatever goes with your Pi model) with a minimum of 8 GB. Various suppliers offer cards of 16 to 64 GB with NOOBS pre-installed ready for use in a Pi. You may even buy a kit that includes a Pi board with components and interfaces on it, a power supply, a micro-SD card, some connection leads, and a case that you can fit the board into to protect it.
Setting up a Pi is simple assuming you have bought a micro-SD card that is, either pre-installed with NOOBS, or with the Raspbian Pi operating system pre-installed. NOOBS makes it easy to install (by default) Rasbian (insert the SD card into the Pi and when you power up the Pi, the operating system will be installed during that first boot. If you have a model with an Ethernet connection, and that is connected first, then NOOBS can offer a choice of other operating systems, or you can download another compatible operating system and install it on the micro-SD card.
If you want to be able to use the micro-SD card in other devices (like your PC), you may need to also buy an adapter which allows the micro-SD card to be plugged into a standard SD socket. This may be included if you buy a micro-SD card not sold specifically for the Pi.
The Operating System
As said before, a number of operating systems can be installed on your Pi, even Windows. I leave it to you to read, on-line, how to install the operating system you choose, normally the instructions will be found from where you download the system you have selected.
If you have a micro-SD card pre-installed with an operating system, you are ready to go!
If you have a micro-SD card pre-installed with NOOBS, as described above, the first boot will install the operating system. By default, it will be the latest Raspbian OS when the card was manufactured.
If you want to install Raspbian, and it is not pre-installed, download from https://www.raspberrypi.org/downloads. That imager is run on any device, say your pc, and then you select write to save it onto the micro-SD card (don't forget this overwrites anything already on the card). This should work without a need to format the card first,(but if you do need to format it, do so using a SD card formatter downloaded from https://www.sdcard.org/downloads/formatter_4/index.html, not the Windows format tool). After this image has been stored it will have created two partitions (one the boot partition can be accessed by Windows, but the larger partition is invisible to Windows).
Pre-configuring the Pi for headless operation
You can store files in the boot partition of the micro-SD card that can be accessed by Windows.
There are two key files that, as described in following sub-sections, should be created and added to the micro-SD card in advance on another device before the card is inserted into the PI. When the card is inserted in a Pi, these two files will be removed from that partition, one will switch on a setting that is by default off, the other file will be moved to a new location and enable wireless connection to your local network.
Secure Shell Home
Secure Shell (SSH) is a cryptographic network protocol for operating network services securely over an unsecured network. By default, this optional way for another device to see your PI is turned off. You can turn it on by the configuration application on your Pi, but you may want it turned on as your Pi boots up and you can do that by adding a file to your micro-SD card.
The file must be named "SSH" with those three letters in capitals, but with no file extension and no contents. On a Windows PC, if you right click (while viewing the boot directory on the card) there is an option called New and if you select a text file it will create an empty file with the extension .txt. (In windows there is an option to hide extensions which is on by default, so you may need to deselect this option [New menu -> Options] to see this extension). On Windows you can open the file using Notepad to verify it is empty, if you gave accidentally created a file of another type like word processing it will be full of characters some of which do not display. Anyway, you must remove any extension from the file name so it is really just SSH.
When the card is inserted into your Pi, on boot this file will be removed and the SSH option will be enabled.
Wireless Network
Again, create a new file, again if you are using Windows you can create it as a text file and then replace the .txt extension with a .conf extension, store it in the boot directory on your micro-SD card under the name wpa_supplicant.conf.
Using a text editor that won't add any unwanted control characters, add the following text using UTF-8 encoding:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=GB network={ ssid="YourNetwork" psk="YourNetworkPassword" key_mgmt=WPA-PSK }
- Obviously, if you are not in United Kingdom, you will replace GB by the country code that applies to you.
- Within the first set of quotes, replace YourNetwork by whatever Service Set Identifier is used for your wireless network. You may have typed this into your mobile phone. It may be shown on a card that slips into a slot on your hub or router. Whatever it is, and it can be up to 32 characters (letters, numbers, and symbols), type it within the double quotes. Some routers come with a default SSID that is the manufacturer's name, and leave it to you to pick a SSID that is unique to you using up to 32 characters to personalise it.
- Within the next set of quotes, which relate to the replace YourNetworkPassword by whatever Pre-Shared-Key (password) is used for your wireless network. You may have typed this into your mobile phone. Hopefully, you have changed it from whatever was shown as the initial password on the card that slips into a slot on your hub or router (even if all you have done is add a prefix or suffix that means something to you).
- Most wireless networks will use Wi-Fi Protected Access (WPA) or (from 2006) Wi-Fi Protected Access II (WPA2) protocols, so WPA-PSK is correct for you. Note that your Pi is only able to use these protocols. The earlier Wired Equivalent Privacy (WEP) was officially withdrawn in 2004 as too easy to crack, so it is not supported on a new Pi.
Should you wish to set up your Pi with several network definitions, please see Notes by ExperiMentor (a contributor to the Cumulus support forum in Switzerland).
Other configuration
There are various other configurations you need to do on your PI. Unlike SSH, these can't be done by storing files on the micro-SD card. You need to use the raspbian configuration tool raspi-config, and this can be accessed on your Pi either in a Graphical User Interface (GUI), or by running a command in Terminal. The same command can be run from a remote device if you successfully have SSH running. On a Windows pc, this will typically involve use of PuTTY software (an SSH client for Windows) downloaded from https://www.putty.org/. In both cases the command to use is sudo raspi-config.
Mandatory
When you use SSH for the first time to connect to your Pi, you will see a warning that SSH is enabled but the password has not been changed, which is a security risk. So it is mandatory to change the network password for your Pi from the default raspberry to something that you can remember but makes life hard for anybody trying to hack into your system with malicious intent.
Within the Raspberian configuration utility, you will see an option to change password. You will need to enter the new password twice before it replaces the old one.
The default network (host) name for your Pi is raspberrypi, obviously we need to replace that as well with a name that personalises it to you and does not make it easy for a hacker to know what device is represented by that network name. The name can most easily be changed within the Raspberian configuration utility, but it can also be edited by opening the file where it is stored using sudo nano /etc/hostname. Once we rename this hostname, if we are working headless, we will see an error message: sudo: unable to resolve host raspberrypi, appearing when we leave the configuration utility. These can be safely ignored (it's just because you renamed the Pi) and will disappear after next reboot of your Pi.
Within the Raspberian configuration utility, you will see a Network Options option, it is there that you change the network name. Network options can also be configured by clicking an icon on the Pi (this icon might be two red crosses if network settings are missing, two parallel arrows if the network settings are not correctly set, or the wireless symbol if your wireless network is working). Hopefully, for you the WiFi network and password have already been set by the wpa-supplicant.conf file added to micro-SD card earlier.
Recommended
If you are going to use the Pi in headless mode, you must select this next configuration. In Boot Options, Desktop / CLI, select Console Autologin.
The default locale for a Pi is normally en_GB.UTF-8. Whatever locale you use, if you have already been using Cumulus (1 or MX), you need to ensure the locale matches the one used for your log files. The versions of MX released in the middle of 2020 are very fussy that all dates use the same delimiter, so you need to check the chosen locale continues to use the same date separator as before. The locale is affected by the version of Mono you install and whether you use the locale parameter when starting MX, so I cannot cover all options.
Anyway, the default locale is fine if you are in the UK, you use decimal points for real numbers, you use commas for list separators, and you don't have dates with month first!
To change the locale, enter Localisation Options. Note that there is a Wi-Fi network country, but that has already been set by the wpa-supplicant.conf file added to micro-SD card earlier. In the same option area, there are some more options:
- Change Time-zone, by default UTC is used all year round. In the UK if your Cumulus is set to roll over at 10am in summer, you will wish to change the time-zone to UK time.
- Change Keyboard Layout if needed, keyboards can support different numbers of characters, and can have different currency symbols, so select whatever is relevant to you
To leave configuration
Select ‘Finish’.
Installing Mono
Sponsored by Microsoft, Mono is an open source implementation of Microsoft's .NET Framework based on the ECMA standards for C# and the Common Language Runtime.
Preparing for Mono installation
Quite often when we try to install, or update, packages on our Pi we will see messages about dependencies, and in some cases error messages saying the installation has failed or been aborted. Before we can install Mono, there are other packages required and these depend upon which Raspbian operating system we have installed, see Mono instructions for Raspberian. Here are 2 of the options (if your Mono installation fails, then you selected wrong one):
For Raspberian 9 (stretch):
sudo apt install apt-transport-https dirmngr gnupg ca-certificates sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF echo "deb https://download.mono-project.com/repo/debian stable-raspbianstretch main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list sudo apt update
For Raspberian 10 (buster):
sudo apt install apt-transport-https dirmngr gnupg ca-certificates sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF echo "deb https://download.mono-project.com/repo/debian stable-raspbianbuster main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list sudo apt update
Checking all packages are up to date
Either type:
sudo apt-get update sudo apt-get upgrade
or to insert in single line sudo apt-get update && sudo apt-get upgrade.
Installing Mono
Assuming you have now got all the pre-requisites correct as in previous steps, you now need to install mono with sudo apt-get install -y mono-complete. It is important to note that MX requires the complete edition of mono as there is also a cut-down developer edition of Mono that can be downloaded/installed.
Completing Package Installation
As the Pi does not know exactly which components are needed when multiple packages are installed with various dependencies, sometimes extra components are installed which in the end are not needed when you complete all your installations. To clear up, delete any components that are not included in dependencies by typing sudo apt autoremove.
Installing (or updating) MX
MX Distribution
Download whatever version of MX you have decided to install (sometimes the latest version has bugs that might cause a problem for your station or the functionality you use) from CumulusMX/releases
If you are doing this on your Pi, you will need to click extract and choose where the files go.
If you are download on your PC, then you will probably unzip the distribution there and use a tool like FileZilla to copy the installation to your Pi. First of all you need to configure FileZilla Client, unless you have done that previously and saved the configuration:
- Host - this is the IPv4 address of your Pi, I can't tell you what it is, but it is likely to be 192.168.z.xy where the z is likely to be a single figure like 0 or 1, and the xy is two figures you can find out by looking for "pi" (or whatever host username you have set on your Pi) in the admin interface for your hub or router. (It can also be found out by typing hostname -I). Most networks are setup in a way that the subnet range is from 192.168.1.0 to 192.168.1.255.
- Username - the default for this is raspberrypi (although on older Pi it might be Pi), but you can may have changed this (as described earlier). (It can be found by typing hostname) or by looking at the contents of the file /etc/hostname.
- Password - again the default for this is raspberry but we changed it as one of the mandatory configurations earlier.
- Port - 22 is the default, and I have not said how you can change this!
Click QuickConnect and you should see the local files in the left frame and your Pi files in the right frame. The easiest way is to find the folder called CumulusMX in the distribution on the left and drag it to the correct position in the right hand frame. Then all you need to do is watch the progress until it successfully finishes.
Configuration files
If you have used Cumulus before, but this is first installation on Pi, then you need to copy some files from old installation to your Pi, here are a couple but you may have further configuration files to copy across:
- Cumulus.ini
- Strings.ini
The two examples above are in same folder as Cumulus.exe or CumulusMX.exe. You also may have configuration files in a mqtt folder, or elsewhere (for example I store some batch files that Cumulus runs for me in a batch folder).
data and Reports files
The entire content of your existing data and Reports folder should also be copied across to your Pi or transferred across using FileZilla or a similar tool. The same settings as for the distribution can be used, but you will have a different starting point in your left frame.
Running Cumulus
The simplest command to start Cumulus is sudo mono CumulusMx.exe, but you may wish to add Optional_parameters.
In the Cumulus Support forum, there are articles about a stop/start routine, a backup routine, and how to run MX as a service. I will let you hunt for and read the relevant topics, as you may find details in more than one place. This article will avoid these and try to keep it simple.
Adding a web server
Ensuring up to date
As before, we run sudo apt update && sudo apt upgrade -y to ensure all packages are up to date before we attempt to add another package.
Install Apache 2
Apache is not the only web server software, but it is probably the most comprehensive, so if you have enough space on your Pi, install it using sudo apt install apache2 -y.
Install PHP Hypertext Pre-processor
PHP is not the only script language available, but it is quite comprehensive being able to be used either in a fairly simple way or in an object-oriented way for those trying to achieve more complex scripts. The instruction to install it is sudo apt install php -y.
You may wish to create a index.php web page at /var/www/html which is the web server root for browsing, or of course you may wish to copy or FTP here all your existing web pages.
Install Maria database
Since MySQL database is controlled by Oracle, Maria is an alternative that has largely similar command syntax so is likely to work with code (like MX) designed to work with MySQL. Since the MX developer (Mark Crossley) actually uses Maria DB we can have plenty of confidence it is suitable. To install it we type sudo apt install mariadb-server php-mysql -y.
Restarting Apache
After all these installs, we need to restart Apache (so it loads the PHP and MariaDB), by typing sudo service apache2 restart.
Making your database secure
We need to assign passwords to control access to the database by typing into terminal sudo mysql_secure_installation. That brings up a screen:
- where we are asked to type current password for the root (as no password has yet been set, simply press Enter),
- next type Y to signify we are going to set a new password for root,
- next type in a new password that you will not forget,
- next as explained on the screen we are going to say whether users must select a user name as well as a password, type Y to Remove anonymous users
- next we have to decide whether we will only be logging into the database on our Pi (using Localhost) or we might be logging in remotely; type Y or N respectively, but if you choose N remember someone other than you might guess there is a root user and might guess the password you set,
- next we have another option of whether to retain or delete a test database, answer N or Y respectively, I would keep the test database for now as you can play with it and then remove it later,
- finally you type in another Y as that will Reload the privilege tables and ensure all is set up for your access to the database later.
The message when the process sucessfully completes is "Thanks for using MariDB".
Installing PHPMyAdmin
PHPMyAdmin is not the only tool that can be used to manipulate your MySQL like database (that is the significance of the "My" bit in the middle of the tools's name), and you may prefer to load a different tool, perhaps one that works using a drill down approach. However, let me assume that you are happy to use PHPMyAdmin and I will describe how to install that. Start the install with sudo apt install phpmyadmin -y.
The installer will ask some questions. Use your tab key to select <Yes> when it asks whether you want to configure with dbconfig-common. We need to add the mysqli module to our php install, to restart apache, and to move the phpadmin to the server web root so it can be seen in our browser:
sudo phpenmod mysqli sudo service apache2 restart sudo in -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
You can view any index.php or PHPMyADmin web page in your browser by prefixing the address with your Pi URL e.g. http://192.168.1.xy/phpmyadmin where x and y are digits you look up as mentioned before where FTP of MX distribution was described. In this case you will see a PHP MyAdmin log on page where you type username and password (as you may not have added any other user yet, the user will be root).