Is it possible to use two generic MQTT server addresses in bridge configuration?

The bridge is installed on GW and the network and application on another machine. I would like to save the data in the json formed bridge locally in my gateway. I would like to know if it is possible to use two generic MQTT server addresses in bridge configuration? one address would be for an external mqtt broker and another address for local mqtt broker (GW).

I don’t see why this should not work, see:

    # Generic MQTT authentication.
    [integration.mqtt.auth.generic]
    # MQTT servers.
    #
    # Configure one or multiple MQTT server to connect to. Each item must be in
    # the following format: scheme://host:port where scheme is tcp, ssl or ws.
    servers=[
      "tcp://127.0.0.1:1883",
    ]

https://www.chirpstack.io/gateway-bridge/install/config/

3 Likes

Another option could be to use the bridge option of MQTT server itself. I’m doing that very often and it works fine
Check this out
http://www.steves-internet-guide.com/mosquitto-bridge-configuration/

1 Like

I am not able to get this to work. I’m also trying to use two generic MQTT server addresses on the gateway-bridge but haven’t gotten it to work. This is what I tried under [integration.mqtt.auth.generic] in chirpstack-gateway-bridge.toml:

This works as expected
server=“tcp://127.0.0.1:1883”

This works as expected
server=“tcp://206.117.190.51:1883”

This publishes a message only to the first address but not the second
servers=[“tcp://127.0.0.1:1883”,“tcp://206.117.190.51:1883”,]

This (without the trailing comma like in the example) also publishes a message only to the first address
servers=[“tcp://127.0.0.1:1883”,“tcp://206.117.190.51:1883”]

Any thoughts on what I’m doing wrong?

Ned

Not sure, but my guess is to have multiple integration something like that

  [integration.mqtt]

  [integration.mqtt.auth]
  type="generic"

    [integration.mqtt.auth.generic]
    server="tcp://127.0.0.1:1883"

    [integration.mqtt.auth.generic]
    server="tcp://206.117.190.51:1883"

or

  [integration.mqtt]

  [integration.mqtt.auth]
  type="generic"

    [integration.mqtt.auth.generic]
    server="tcp://127.0.0.11:1883"

  [integration.mqtt.auth]
  type="generic"

    [integration.mqtt.auth.generic]
    server="tcp://206.117.190.51:1883"

Thanks for the suggestion. When I tried those two options they both had the same result of not sending data to either device.

ok, but may be I’m wrong, just need to be tried

servers=[
      "tcp://firstmqtt.com:1883",
      "tcp://10.20.30.40:1883"
    ]

I’m having the same issue, if more then one mqtt server is declared the gateway-bridge only connects to the first one.

Even if the first server is shut down after it connected, the gateway-bridge doesn’t connect to the other.
However: if i start the gateway bridge while the first server is unavailable, it will actually connect to the second one.

you put comma to wrong place.
the listing is comma-separated
and you have the contrary

Yep, you’re right, :sweat_smile:
however i only made this error in the above example.

The config i actually use is valid. (as far as i know)
(edited my reply to match that)

Hi everybody,

Did anybody go ahead with this topic?
I made some tests, we have two instances of mosquitto running in our server with ports 1883 and 1884.

I got these conclusions:

  1. The right setup for starting gateway-bridge without failing is the following one, with commans after each line:
servers=[
  "tcp://127.0.0.1:1883",
  "tcp://127.0.0.1:1884",
]

But it connects only to the first server in the array, whatever it is the order. I show the log

Nov 08 18:19:45  systemd[1]: Stopped ChirpStack Gateway Bridge.
Nov 08 18:19:45  systemd[1]: Started ChirpStack Gateway Bridge.
Nov 08 18:19:45  chirpstack-gateway-bridge[22848]: time="2020-11-08T18:19:45+01:00" level=info msg="starting ChirpStack Gateway Bridge" docs="https://www.chirpstack.io/gateway-bridge/" version=3.9.2
Nov 08 18:19:45  chirpstack-gateway-bridge[22848]: time="2020-11-08T18:19:45+01:00" level=info msg="backend/semtechudp: starting gateway udp listener" addr="0.0.0.0:1702"
Nov 08 18:19:45  mosquitto[20091]: 1604855985: New connection from 127.0.0.1 on port 1883.
Nov 08 18:19:45  chirpstack-gateway-bridge[22848]: time="2020-11-08T18:19:45+01:00" level=info msg="integration/mqtt: connected to mqtt broker"
Nov 08 18:19:45  mosquitto[20091]: 1604855985: New client connected from 127.0.0.1 as auto-CC80F143-87A2-936C-3234-EAF064DFBDDB (p2, c1, k30, u'chirpstack_gw').
  1. I had a look at the source code and I could guess it is considering an array as servers.
// Init applies the initial configuration.
func (a *GenericAuthentication) Init(opts *mqtt.ClientOptions) error {
	for _, server := range a.servers {
		opts.AddBroker(server)
	}
	opts.SetUsername(a.username)
	opts.SetPassword(a.password)
	opts.SetCleanSession(a.cleanSession)
	opts.SetClientID(a.clientID)

	if a.tlsConfig != nil {
		opts.SetTLSConfig(a.tlsConfig)
	}

	return nil
}

Any idea if it is really possible to connect more than one server?
I couldn’t make it work.

Regards

I was testing this as well, the underlying paho.mqtt.golang library attempts to connect to the brokers one at a time, but only connects to one. https://github.com/eclipse/paho.mqtt.golang/blob/v1.2.0/client.go#L232-L278

As of now, you cannot connect the generic backend to multiple brokers.

2 Likes

@ndrs @John_Roesler any updates on that?
Still trying to connect to two MQTT Servers the bridge only connect to the first.

No updates to my knowledge. It would require changing how the gateway bridge connects to servers. Right now, it’s passing that list of servers to the mqtt driver, which in turn connects only to the first. The gateway bridge would need to be refactored to connect to multiple mqtt drivers instead.

Any updates on this ?
As you see, we put multiple mqtt instance addresses to the “servers” section and Chirpstack Gateway Bridge can not get it right.

There is no update on this, as this is how the underlying MQTT client works. It connects to one of the configured MQTT brokers at a time.

So last update on this topic was from April 2022, but I need to connect a Gateway Bridge to two MQTT-brokers. Is that still not a possibility?

Edit: If one single broker is the limitation, could I just have something like a python-script act as a go-between between the one primary MQTT-broker and the second one that I also want to apply?