Weather monitor installation: Difference between revisions

From Rsewiki
 
Line 174: Line 174:


  [service]
  [service]
  logpath = /home/local/svn/weather_monitor/log/log_%d/
  basepath = /home/local/svn/weather_monitor/log/
  ; the '%d' will be replaced with date and timestamp (must end with a '/'). =
logpath = log_%d/
max_logging_minutes = 60.0
  ; the '%d' will be replaced with date and timestamp (must end with a '/'). =  
  log_service = true
  log_service = true
maximized = 0
   
   
  [mqttin]
  [mqttin]
  ;broker = tcp://10.59.9.201:1883
  broker = tcp://192.168.2.179:1883
broker = tcp://10.197.217.56:1883
  context = not used
  context = ublox9/
clientid = ublox9_in
  function = nmea/
  function = nmea/
  system = ublox9/
  system = ublox9/
  log = true
  log = true
  print = false
  print = false
  use = true
  use = false
   
   
  [gnss]
  [gnss]
  ;input = ../../../log/gnss_2025_06_18.nmea
  input = /dev/ttyACM0
input = ../../../log/log_24h_asta_mqtt.txt
  input_use = false
  input_use = false
  log = false
  log = false
  interval_sec = 0
  interval_sec = 6
  logtime = false
  logtime = 5
   
   
  [ini]
  [ini]
  ; set 'saveconfig' to 'false' to avoid autosave =
  ; set 'saveconfig' to 'false' to avoid autosave =  
  saveconfig = true
  saveconfig = true
  version = 2285 2025-06-26 07:20:46
  version = 2285 2025-06-26 07:20:46
   
   
  [mqttinw]
  [weather]
  broker = tcp://192.168.2.216:1883
log = true
logload = true
logloaddir = log_20
show_temp = 0 1
show_hum = 0 1
show_sound = 0
show_ppm2_5 = 0
show_ppm_10 = 0
show_light = 0 0
show_rain = 1
show_wind = 1
[mqtt_indoor]
  broker = tcp://localhost:1883
  context = not used
  context = not used
clientid = weather_in
  function = indoor/
  function =
  system = weather/
  system = weather7/
  log = true
  log = true
  print = false
  print = false
  use = false
  use = false
   
   
  [weather]
  [mqtt_outdoor]
  input = ../log/weather-xxx.txt
  broker = tcp://192.168.2.216:1883
  input_use = false
context = not used
function = outdoor/
  system = weather/
  log = false
  log = false
  interval_sec = 60
  print = false
  logpathload = /home/local/svn/weather_monitor/log/w1
use = true
  logpathsave = /home/local/svn/weather_monitor/log/w2
  logload = false
[mqtt_df1]
  #broker = tcp://192.168.2.152:1883
broker = tcp://localhost:1883
context = not used
function = greve/#
system = weather/
log = true
print = false
use = true
[splitter]
stretch = 0 1 1
[mqtt_pv]
  broker = tcp://192.168.2.151:1883
context = not used
system = pv/
function = monitor/#
log = true
print = false
use = true
[pv]
log = true
loguse = false
use = true
  logload = true
logloaddir = log_20
voltage_scale = 1.0 1.0 1.0 1.0
voltage_scaleinfo = charger1 charger2 battery1 battery2
 




Line 227: Line 269:
* Group ''[mqttin]''. It is for use with an MQTT server that streams the NMEA messages. Change the IP in the ''[mqttin]'' group and change to ''use=true''. The NMEA messages are assumed to be in the payload of the message, and the subject as described (subscribing to 'ublox9/nmea/#').
* Group ''[mqttin]''. It is for use with an MQTT server that streams the NMEA messages. Change the IP in the ''[mqttin]'' group and change to ''use=true''. The NMEA messages are assumed to be in the payload of the message, and the subject as described (subscribing to 'ublox9/nmea/#').
* Group ''[mqttinw]'' is the input source for weather information.
* Group ''[mqttinw]'' is the input source for weather information.


== Autostart MQTT talker ==
== Autostart MQTT talker ==

Latest revision as of 09:29, 11 January 2026

Back to weather monitor

Installation issues

Required packages

Some of the packages are merely for convenience, but most are required to run the intended applications.

libreadline-dev
libopencv-dev
libgpiod-dev
gpiod
cmake
subversion
aptitude
apt-file
telnet
ntp
ntpdate
nmap
lsof
libpaho-mqtt-dev 
libpaho-mqttpp-dev (if not available, then not needed)
python3-paho-mqtt
python3-opencv
python3-setproctitle
mosquito
mosquitto-dev 
mosquitto-clients
libusb-dev
libcli11-dev    (maybe not available)
libgeographiclib-dev
libpaho-mqttpp-dev
qt6-base-dev
qt6-tools-dev
qt6-charts-dev
libxkbcommon-dev
sudo apt install libreadline-dev libopencv-dev libgpiod-dev gpiod cmake subversion aptitude apt-file telnet ntp ntpdate nmap lsof python3-paho-mqtt libpaho-mqtt-dev python3-opencv python3-setproctitle mosquitto mosquitto-dev mosquitto-clients libusb-dev libcli11-dev libgeographiclib-dev libpaho-mqttpp-dev qt6-base-dev qt6-tools-dev qt6-charts-dev libxkbcommon-dev

For Python install

pip install geographiclib

or

sudo apt install python3-geographiclib

Build

Code is found here (on SVN)

cd ~/svn
svn co svn://repos.gbar.dtu.dk/jcan/weather_monitor

The Qt C++ code is then in ~/svn/weather_monitor/qt_monitor

Build by

cd ~/svn/weather_monitor/qt_monitor
mkdir -p build
cd build
cmake ..
make -j3

Debug build by

cd ~/svn/weather_monitor/qt_monitor
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
make -j3

Run once to create a configuration file, then edit to configure.

./gnss_qt
nano gnss_qt.ini

Debug run with valgrind

valgrind ./gnss_qt

CMake problem

GeographicLibConfig.cmake

The find package

find_package(GeographicLib REQUIRED)

in cmake fails, as the file GeographicLibConfig.cmake is not found.

This can be fixed by renaming the provided file FindGeographicLib.cmake by

cd /usr/share/cmake/geographiclib
sudo ln -s FindGeographicLib.cmake GeographicLibConfig.cmake

XKB

Missing library, and CMake complains:

-- Could NOT find XKB (missing: XKB_LIBRARY XKB_INCLUDE_DIR) (Required is at least version "0.5.0")

The solution was to install

sudo apt install libxkbcommon-dev

This occurred on Raspberry Pi 4-5 using the 64-bit default OS.

XCB-plugin

When trying to start the Qt app on reboot I got:

Could not load the Qt platform plugin "xcb" in "" even though it was found.

I inserted

export QT_QPA_PLATFORM=xcb

into the 'on_reboot.bash' that is activated by crontab on reboot.

and installed

sudo apt install qt5dxcb-plugin

No, it didn't help. Use desktop-file as in next section:

Autostart QT-GUI app at boot

Make a desktop file in ~/.config/autostart/

cd 
cd .config
mkdir -p autostart
cd autostart
nano qt_monitor.desktop

Insert the following

[Desktop Entry]
Name=Gnss_qt
Exec=/home/local/on_reboot.fromDesktop
Type=Application
Terminal=true
NoDisplay=false
X-KeepTerminal=true
StartupNotify=true

The file /home/local/on_reboot.fromDesktop is an executable bash script with the following content;

#!/bin/bash
# script to start applications after a reboot
#
# Run the weather app
mkdir -p /home/local/svn/log
cd /home/local/svn/log
# save the last reboot date
echo "================ Rebooted ================" >> rebootinfo.txt
date >> rebootinfo.txt
# start weather display app
sleep 15
cd /home/local/svn/weather_monitor/qt_monitor/build
./gnss_qt -d 2>out_err.txt >out_console.txt &
echo "display app started with PID:" >> /home/local/svn/log/rebootinfo.txt
sleep 1
pgrep -l gnss_qt >> /home/local/svn/log/rebootinfo.txt
#
# starting the DF temp sensor interface
source /home/local/venv/bin/activate
cd /home/local/svn/weather_monitor/dfsensor
python3 df-mqtt-sensor.py >> /home/local/svn/log/rebootinfo.txt &
sleep 4
echo "DF sensor node, started with PID:" >> /home/local/svn/log/rebootinfo.txt
pgrep -l df-mqtt-sen >> /home/local/svn/log/rebootinfo.txt
#
exit 0


This seems to work better than crontab with an @reboot entry, as it has the XCB issue described above.

Configure

After the gnss_qt is run the first time, there should be a default configuration file, this will need to be modified. E.g. similar to this:

[service]
basepath = /home/local/svn/weather_monitor/log/
logpath = log_%d/
; the '%d' will be replaced with date and timestamp (must end with a '/'). = 
log_service = true
maximized = 0

[mqttin]
broker = tcp://192.168.2.179:1883
context = not used
function = nmea/
system = ublox9/
log = true
print = false
use = false

[gnss]
input = /dev/ttyACM0
input_use = false
log = false
interval_sec = 6
logtime = 5

[ini]
; set 'saveconfig' to 'false' to avoid autosave = 
saveconfig = true
version = 2285 2025-06-26 07:20:46

[weather]
log = true
logload = true
logloaddir = log_20
show_temp = 0 1
show_hum = 0 1
show_sound = 0
show_ppm2_5 = 0
show_ppm_10 = 0
show_light = 0 0
show_rain = 1
show_wind = 1

[mqtt_indoor]
broker = tcp://localhost:1883
context = not used
function = indoor/
system = weather/
log = true
print = false
use = false

[mqtt_outdoor]
broker = tcp://192.168.2.216:1883
context = not used
function = outdoor/
system = weather/
log = false
print = false
use = true

[mqtt_df1]
#broker = tcp://192.168.2.152:1883
broker = tcp://localhost:1883
context = not used
function = greve/#
system = weather/
log = true
print = false
use = true

[splitter]
stretch = 0 1 1

[mqtt_pv]
broker = tcp://192.168.2.151:1883
context = not used
system = pv/
function = monitor/#
log = true
print = false
use = true

[pv]
log = true
loguse = false
use = true
logload = true
logloaddir = log_20
voltage_scale = 1.0 1.0 1.0 1.0
voltage_scaleinfo = charger1 charger2 battery1 battery2


Each group corresponds to one of the modules in the app:

  • Group [gnss]. Input can be from a file, either directly from the receiver /dev/ttyACM0, or a logfile generated by the MQTT streamer for NMEA messages. Set input_use = true to use this alternative.
  • Group [mqttin]. It is for use with an MQTT server that streams the NMEA messages. Change the IP in the [mqttin] group and change to use=true. The NMEA messages are assumed to be in the payload of the message, and the subject as described (subscribing to 'ublox9/nmea/#').
  • Group [mqttinw] is the input source for weather information.

Autostart MQTT talker

Autostart the MQTT server for weather monitoring.

Create an on_reboot.bash file

cd
nano on_reboot.bash

Fill it with

#!/bin/bash
# script to start applications after a reboot
#
# Run the weather app
mkdir -p /home/local/svn/log
cd /home/local/svn/log
# save the last reboot date
echo "================ Rebooted ================" >> rebootinfo.txt
date >> rebootinfo.txt
# start camera server (allow camera to be detected)
sleep 0.2
cd /home/local/svn/weather_monitor/weather_talk/build/
./weather_talk 2>w_talk.err >w_talk.out &
echo "weather talk started with PID:" >> /home/local/svn/log/rebootinfo.txt
sleep 0.1
pgrep -l weather >> /home/local/svn/log/rebootinfo.txt
#
exit 0

Next, make an on reboot crontab job

crontab -e

Select an appropriate editor, and add this line at the end of the file:

@reboot /home/local/on_reboot.bash

Venv for python sensor

install

Create a venv structure for a separate Python environment. Make the venv structure in the home directory.

cd
python -m venv venv
source ~/venv/bin/activate

Install the needed packages after the venv is activated

pip install RPi.GPIO
pip install psutil
pip install setproctitle
pip install paho-mqtt
pip install serial
pip install smbus
pip install modbus_tk

Remember to enable the serial hardware in raspi-config.

Hardware

Cables

The RS-485 cable to the weather station is extended using network cable:

  • weather cable yellow (A) to ethernet white (twist with green)
  • weather cable blue (B) to ethernet green
  • weather cable brown (10-30V) to ethernet brown + white (pair)
  • weather cable black (GND) to ethernet blue + white
  • (ethernet pair orange - NC)