State of connection mqtt packet forwarder in the gateway

Hello,

There is fonction to know if the chirpstack-mqtt-forwarder is correctly connected to mqtt broker, without checking log ?

A command like the gateway-id binary from chirpstack-os which returns the gateway-id from chirpstack-concentratord, like states in uci config or tmp fs ?

I believe it’s the connection status of the gateway inside the server, but I want to know the connection status inside the gateway.

I have a LED, I use to display many states, internet connection, if lora is active and now I want to check if the mqtt connection is correct from gateway to the broker.

For now I’m using this

netstat -etp | grep $(ps ww | grep chirpstack-mqtt-forwarder | grep -v grep | awk '{print $1}')

netstat grep on the pid of chirpstack-mqtt-forwarder, that not realy good

But the tcp connection can be established without connection on broker mqtt is complete

I see, that is definitely not as straightforward.

There’s likely better ways but IMO the simplest way to do this would be log monitoring. Either watch the MQTT forwarders logs for errors (which should only happen when the forwarder has connection issues) or monitor it for successful stats messages being sent to the broker (likely the better of the two), Chirpstack displays the gateway status depending on whether it is receiving stats messages from the gateway so if it’s good enough for the server I reckon it’s the best you can do gateway side as well.

Listen log continuous to detect specific event seems to me
very complex,

But one of this log event could work

# one event at start
Starting MQTT event loop
Subscribing to command topic, topic: eu868/gateway/ac1f09fffe0caacd/command/+
Sending conn state, topic: eu868/gateway/00aa00aa00aa00aa/state/conn

# freqency event but contienu when the internet conexion is disable
Received gateway stats
Sending gateway stats event, topic: eu868/gateway/00aa00aa00aa00aa/event/stats

# this event displayed when conexion not work well
MQTT error, error: Mqtt state: Last pingreq isn't acked
MQTT error, error: Timeout

## No error when the certificat are unvalide

An evolution could be considered, in particular to display this stratus on the Luci interface and inform the user that the broker communicates well.

Several solutions could be considered,

  • A simple state in a file /tmp/state or other.
  • An entry into the UCI.
  • Setting up a zmq only for the forwarder in Pub-sub
1 Like

Following SC2009

pgrep chirpstack-mqtt-forwarder

is clearer than

ps ww | grep chirpstack-mqtt-forwarder | grep -v grep | awk '{print $1}'

This call is better and works fine but does not resolve le false positif successful TCP with bad MQTT conexion

netstat -tep | grep "ESTABLISHED $(pgrep chirpstack-mqtt-forwarder || echo 0)/" | grep 8883