Running OTmonitor on a Raspberry Pi
Here are some basic instructions for people unfamiliar with linux who want
to run otmonitor on a Raspberry Pi:
- Step #1
- Download and install an OS onto the SD card, as explained on the
Raspberry
Pi web site. If you intend to use a monitor with your Raspberry Pi,
choose the "Raspberry Pi OS with desktop" image. If your Raspberry Pi is
supposed to run "headless", the "Raspberry Pi OS Lite" image suffices.
For a headless system, you may want to
enable ssh before booting the device.
If you don't have wired LAN available, you will also want to
preconfigure wifi for a headless system.
- Step #2
- Put the SD card into the Raspberry Pi. Attach a network cable, monitor,
mouse and keyboard, as necessary. Then power it up.
- Step #3
- Wait for the system to boot. This may take a while the first time, because
the file system will automatically be expanded and then the system boots again.
For a headless system, you'll need to
figure out which IP address has been assigned to the Raspberry Pi.
If necessary, connect to the device and log in as user "pi" with password
"raspberry".
- Step #4
- When running the Pi with a monitor, the system will have already prompted
you for some configuration settings. If not, or if you accidentally pressed
"Next" too quickly, or you want to change the choices you made, open a
terminal (Ctrl+Alt+T, if you don't have a mouse) and run the raspi-config
tool manually. This also needs to be done on a headless system:
sudo raspi-config
Use the cursor keys to go to "Localisation Options" and "Timezone". Select
the desired time zone.
If you are going to access the OTGW using the built-in serial port, navigate
to "Interface Options", "Serial Port", and choose "No" for a serial login shell
and "Yes" for the serial port hardware to be enabled.
This is not necessary when using a USB->Serial adapter or for the wifi or
ethernet versions of the gateway from the nodo shop.
Warning: The built-in serial port of the Raspberry Pi uses 3.3V logic.
You will damage the device if it is connected to the OTGW without proper level
shifters.
Make any other configuration changes you want, then exit the tool. If it
asks to reboot, choose "No".
- Step #5
- Actually install the otmonitor application using the following commands:
mkdir bin
cd bin
wget -O otmonitor http://otgw.tclcode.com/download/otmonitor-aarch64
chmod +x otmonitor
cd
If you installed a 32-bit OS (uname -m returns armv7l), specify
http://otgw.tclcode.com/download/otmonitor-ahf instead in the wget
command.
- Step #6
- The location where the application was installed did not exist before,
so it is not included in the current PATH environment variable. Either log
out and log back in to resolve that, or add it manually:
PATH=$HOME/bin:$PATH
- Step #7
- Run the application. On a desktop system, you can run the GUI version:
otmonitor
To run otmonitor without a GUI, you will need to enable the webserver to be
able to configure it:
otmonitor --daemon --webserver=8880
Now a browser can be pointed at http://<RaspberryPiIP>:8880/.
If you don't want to have to use a port number in the URL, the webserver must
be accessible on port 80. However, all ports below 1024 are reserved. So a
regular user is not allowed to use those ports.
There are two options:
- Run the application as root:
sudo otmonitor --daemon --webserver=80
- Set up port forwarding, so any access to port 80 is redirected to the
userland port configured in otmonitor. This one-time configuration does
require administrator rights.
First, enable and start the nftables service, if necessary:
sudo systemctl start nftables
sudo systemctl enable nftables
Next, create a nat table with prerouting and postrouting
chains, if necessary:
sudo nft add table ip nat
sudo nft add chain ip nat prerouting '{type nat hook prerouting priority -100;}'
Add the port forwarding rule:
sudo nft add rule ip nat prerouting tcp dport 80 redirect to :8880
After checking that port forwarding works as expected, save the firewall
configuration so it will survive a reboot:
sudo sh -c 'nft list ruleset > /etc/nftables.conf'
It is not advisable to run applications as root. So choose the second method
if at all possible.
- Step #8
- Now configure the application. At least the connection to the OTGW
needs to be specified. When configuring otmonitor via the web GUI, close the
tab when done to make sure the changes are saved.
Once the application has been configured, it may be convenient to start it
automatically on each boot. The two modes of operation require different
methods:
- GUI mode
-
The steps are:
- Create an autostart directory under .config in pi's home directory.
- Download
otmonitor.desktop into the newly created autostart directory.
From the command line, this can be done using these commands:
mkdir ~/.config/autostart
wget -P ~/.config/autostart http://otgw.tclcode.com/download/otmonitor.desktop
- Daemon mode
- The easiest way to automatically start an otmonitor daemon is via crontab:
crontab -e
Add the following line at the end:
@reboot /home/pi/bin/otmonitor --daemon
This can also be done without the need to use an editor:
(crontab -l;echo @reboot /home/pi/bin/otmonitor --daemon) | crontab
Alternatively, otmonitor can be managed by systemctl. Create a service file
for otmonitor:
sudo nano /etc/systemd/system/otmonitor.service
Paste in the following content
:
[Unit]
Description=otmonitor
Documentation=https://otgw.tclcode.com/otmonitor.html
After=multi-user.target
[Service]
Type=exec
User=pi
ExecStart=/home/pi/bin/otmonitor --daemon
StandardOutput=inherit
StandardError=inherit
Restart=always
[Install]
WantedBy=multi-user.target
Adjust the path and user name as needed.
Save the file (Ctrl-s) and exit nano (Ctrl-x).
Then start the service and enable it so it will restart after a boot:
sudo systemctl start otmonitor
sudo systemctl enable otmonitor
|