Combining Multiple MQTT Topics

I am using lilygo-rtl_433 on a lilygo lora32 board to receive data from an outside weather station as well as from an indoor BME280. Data from these 2 sources is published in 2 different topics. Are there options out there to combine those 2 different topics into one for the ease of feeding the combined sensor readings into Weewx? I am currently running WeeWX-MQTTSubscribe as my weewx driver.

Hello,

Yes, you can do it by building your binary

You have to comment -DvalueAsATopic=true' ;

And build/upload from platformio.

[env:lilygo-rtl_433]
platform = ${com.esp32_platform}
board = ttgo-lora32-v21
; ~/.platformio/packages/framework-arduinoespressif32/variants/.../pins_arduino.h
board_build.partitions = min_spiffs.csv
lib_deps =
  ${com-esp32.lib_deps}
  ${libraries.ssd1306}
  ${libraries.rtl_433_ESP}
build_flags =
  ${com-esp32.build_flags}
; *** OpenMQTTGateway Config ***
  ;'-UZmqttDiscovery'          ; disables MQTT Discovery
  ;'-DvalueAsATopic=true'    ; MQTT topic includes model and device
  '-DGateway_Name="OMG_lilygo_rtl_433_ESP"'
; *** OpenMQTTGateway Modules ***
  '-DZgatewayRTL_433="rtl_433"'
  '-DZradioSX127x="SX127x"'
; *** ssd1306 Display Options ***
  '-DZdisplaySSD1306="LilyGo_SSD1306"'

Thank you so much Sir, I will give this a try and let you know how it comes out!

I may have read too fast; the BME280 is connected to the Lilygo, I suppose?

Correct… here is what I am seeing in the monitor:

E: [ WebUI ] rtl_433 not displaying RTL_433toMQTT
N: Send on /RTL_433toMQTT msg {"model":"Bresser-7in1","id":43980,"temperature_C":4.1,"humidity":99,"wind_max_m_s":0,"wind_avg_m_s":0,"wind_dir_deg":312,"rain_mm":670.7999,"light_klx":0.577,"light_lux":577,"uv":0,"battery_ok":0,"mic":"CRC","protocol":"Bresser Weather Center 7-in-1","rssi":-68,"duration":41000}

Checking to see if this is easer to read,

N: Send on /RTL_433toMQTT msg {“tempc”:27.29,“tempf”:81.122,“hum”:33.25879,“pa”:99670.33,“altim”:138.6583,“altift”:454.9156}
E: [ WebUI ] rtl_433 not displaying RTL_433toMQTT
N: Send on /RTL_433toMQTT msg {“model”:“Bresser-7in1”,“id”:43980,“temperature_C”:4.1,“humidity”:99,“wind_max_m_s”:0,“wind_avg_m_s”:0,“wind_dir_deg”:312,“rain_mm”:670.7999,“light_klx”:0.593,“light_lux”:593,“uv”:0,“battery_ok”:0,“mic”:“CRC”,“protocol”:“Bresser Weather Center 7-in-1”,“rssi”:-68,“duration”:41000}

This line was not there prior to making the change originally suggested

E: [ WebUI ] rtl_433 not displaying RTL_433toMQTT

if the BME280 is connected to the Lilygo you may have to combine 2 custom flags for the build:
BMETOPIC that you have to set to your target merged topic, like
and
comment '-DvalueAsATopic=true'

You could have the following build flags:
;'-DvalueAsATopic=true'
BMETOPIC=subjectRTL_433toMQTT

Yes not using valueAsATopic is not supported by the WebUI.

Still seems to be post both sensors separately.

Edit: i fixed the missing “/” in the BME topic name

I updated the BME topic in BME280.h I don’t think should matter?

#ifndef BMETOPIC

define BMETOPIC “RTL_433toMQTT”

#endif

Here is the rest of my portable config…

[env:lilygo-rtl_433-fsk-fg]
platform = ${com.esp32_platform}
board = ttgo-lora32-v21
; ~/.platformio/packages/framework-arduinoespressif32/variants/.../pins_arduino.h
board_build.partitions = min_spiffs.csv
lib_deps =
  ${com-esp32.lib_deps}
  ${libraries.ssd1306}
  ${libraries.rtl_433_ESP}
build_flags =
  ${com-esp32.build_flags}
; *** OpenMQTTGateway Config ***
  ;'-UZmqttDiscovery'          ; disables MQTT Discovery
  ;'-DvalueAsATopic=false'    ; MQTT topic includes model and device
  '-DOOK_MODULATION=false' ; FSK modulation activated
  '-DGateway_Name="Bresser Weather"'
  '-DZsensorBME280="BME280"'
  '-DMQTT_SERVER="10.0.0.5"'
  '-DRF_FREQUENCY=915'
  ;-DRF_FREQUENCY=868.300'
  ;-DRF_FREQUENCY=433.9'
; *** OpenMQTTGateway Modules ***
  '-DZgatewayRTL_433="rtl_433"'
  '-DZradioSX127x="SX127x"'
; *** ssd1306 Display Options ***
  '-DZdisplaySSD1306="LilyGo_SSD1306"'
;  '-DLOG_TO_OLED=true'         ; Enable log to OLED
;  '-DJSON_TO_OLED=true'
;  '-DLOG_LEVEL_OLED=LOG_LEVEL_NOTICE'
;  '-DDISPLAY_IDLE_LOGO=false'
;  '-DDISPLAY_BRIGHTNESS=80'
;  '-DDISPLAY_METRIC=false'
custom_description = For ESP32, Gateway using RTL_433_ESP and RadioLib with FSK modulation (beta)
custom_hardware = ESP32 LILYGO LoRa32 V2.1

Could you check MQTT explorer, it will be easier for you to compare and update the configuration instead of the logs.

Try this:

[env:lilygo-rtl_433-fsk-fg]
platform = ${com.esp32_platform}
board = ttgo-lora32-v21
; ~/.platformio/packages/framework-arduinoespressif32/variants/.../pins_arduino.h
board_build.partitions = min_spiffs.csv
lib_deps =
  ${com-esp32.lib_deps}
  ${libraries.ssd1306}
  ${libraries.rtl_433_ESP}
build_flags =
  ${com-esp32.build_flags}
; *** OpenMQTTGateway Config ***
  ;'-DvalueAsATopic=false'    ; MQTT topic includes model and device
  '-DOOK_MODULATION=false' ; FSK modulation activated
  '-DGateway_Name="Bresser Weather"'
  '-DZsensorBME280="BME280"'
  '-DBMETOPIC=subjectRTL_433toMQTT'
  '-DMQTT_SERVER="10.0.0.5"'
  '-DRF_FREQUENCY=915'
; *** OpenMQTTGateway Modules ***
  '-DZgatewayRTL_433="rtl_433"'
  '-DZradioSX127x="SX127x"'
; *** ssd1306 Display Options ***
  '-DZdisplaySSD1306="LilyGo_SSD1306"'

Watching MQTT Explorer, the data in the topic “home/Bresser Weather/RTL_433toMQTT” is alternating back and forth between the weather station data and the attached BME280 sensor data at each update. This is causing confusion thus locking up the WeeWx software application. I was hoping to have both sensors combined into a single json string.

Weather Sation data:

{
  "model": "Bresser-7in1",
  "id": 43980,
  "temperature_C": 3.5,
  "humidity": 87,
  "wind_max_m_s": 1.2,
  "wind_avg_m_s": 1.2,
  "wind_dir_deg": 312,
  "rain_mm": 677.6,
  "light_klx": 3.097,
  "light_lux": 3097,
  "uv": 0,
  "battery_ok": 0,
  "mic": "CRC",
  "protocol": "Bresser Weather Center 7-in-1",
  "rssi": -64,
  "duration": 41000
}

BME280 data"

{
  "tempc": 20.67,
  "tempf": 69.206,
  "hum": 39.45605,
  "pa": 98921.16,
  "altim": 202.0503,
  "altift": 662.8948
}

The result would be something like this:

{
  "model": "Bresser-7in1",
  "id": 43980,
  "temperature_C": 3.5,
  "humidity": 87,
  "wind_max_m_s": 1.2,
  "wind_avg_m_s": 1.2,
  "wind_dir_deg": 312,
  "rain_mm": 677.6,
  "light_klx": 3.097,
  "light_lux": 3097,
  "uv": 0,
  "battery_ok": 0,
  "mic": "CRC",
  "protocol": "Bresser Weather Center 7-in-1",
  "rssi": -64,
  "duration": 41000
  "tempc": 20.67,
  "tempf": 69.206,
  "hum": 39.45605,
  "pa": 98921.16,
  "altim": 202.0503,
  "altift": 662.8948
}

Thinking this may require additional python code to parse out the 2 strings then rebuild into a single,
A project for another long winter at my skill level!

Yes it is 2 different json, we don’t merge json as this could cause confusion also.

I think that the best way should be for your software to handle different topics, this is more adapted to MQTT philosophy.

I agree and thank you for all the support. I learned a lot about programming the ESP32 and Platformio and you really helped move my project along!! Cheers until next time I get stuck!

1 Like