Gateway Status On Postgres DB

Hi there,

I’m trying to get the state of my gateways on my Postgres database that I have intergrated but can’t seem to get it going. I have all the Event tables that have been populated but nothing to do with the gateways status.

image

I also noticed that the Mosquitto is not bound and cannot access it via port 1883, I was trying to connect to the MQTT broker with NodeRed but have been unsuccessful connecting a subscriber.

I have the following when containers and ports running:

  IMAGE                                    COMMAND                  CREATED          STATUS          PORTS                                       NAMES
   chirpstack/chirpstack-rest-api:4         "/usr/bin/chirpstack…"   25 minutes ago   Up 25 minutes   0.0.0.0:8090->8090/tcp, :::8090->8090/tcp   chirpstack-rest-api
   chirpstack/chirpstack-gateway-bridge:4   "/usr/bin/chirpstack…"   25 minutes ago   Up 25 minutes   0.0.0.0:1701->1700/udp, :::1701->1700/udp   chirpstack-gateway-bridge-as923
   chirpstack/chirpstack-gateway-bridge:4   "/usr/bin/chirpstack…"   25 minutes ago   Up 25 minutes   0.0.0.0:1700->1700/udp, :::1700->1700/udp   chirpstack-gateway-bridge-eu868
   chirpstack/chirpstack-gateway-bridge:4   "/usr/bin/chirpstack…"   25 minutes ago   Up 25 minutes   0.0.0.0:3001->3001/tcp, :::3001->3001/tcp   chirpstack-docker-chirpstack-gateway-bridge-basicstation-1
   chirpstack/chirpstack:4                  "/usr/bin/chirpstack…"   25 minutes ago   Up 25 minutes   0.0.0.0:8080->8080/tcp, :::8080->8080/tcp   chirpstack-docker-chirpstack-1
   eclipse-mosquitto:2                      "/docker-entrypoint.…"   25 minutes ago   Up 25 minutes   1883/tcp                                    chirpstack-docker-mosquitto-1
   postgres:14-alpine                       "docker-entrypoint.s…"   13 hours ago     Up 52 minutes   5432/tcp                                    chirpstack-postgres
   redis:7-alpine                           "docker-entrypoint.s…"   13 hours ago     Up 52 minutes   6379/tcp                                    chirpstack-redis

and I have the following config in my chirpstack-gateway-bridge.toml

[general]
# debug=5, info=4, warning=3, error=2, fatal=1, panic=0
log_level=4

# Log in JSON format.
log_json=false

# Log to syslog.
#
# When set to true, log messages are being written to syslog.
log_to_syslog=false


# Filters.
#
# These can be used to filter LoRaWAN frames to reduce bandwith usage between
# the gateway and ChirpStack Gateway Bridge. Depending the used backend, filtering
# will be performed by the Packet Forwarder or ChirpStack Gateway Bridge.
[filters]

# NetIDs filters.
#
# The configured NetIDs will be used to filter uplink data frames.
# When left blank, no filtering will be performed on NetIDs.
#
# Example:
# net_ids=[
#   "000000",
#   "000001",
# ]
net_ids=[
]

# JoinEUI filters.
#
# The configured JoinEUI ranges will be used to filter join-requests.
# When left blank, no filtering will be performed on JoinEUIs.
#
# Example:
# join_euis=[
#   ["0000000000000000", "00000000000000ff"],
#   ["000000000000ff00", "000000000000ffff"],
# ]
join_euis=[
]


# Gateway backend configuration.
[backend]

# Backend type.
#
# Valid options are:
#   * semtech_udp
#   * concentratord
#   * basic_station
type="semtech_udp"


  # Semtech UDP packet-forwarder backend.
  [backend.semtech_udp]

  # ip:port to bind the UDP listener to
  #
  # Example: 0.0.0.0:1700 to listen on port 1700 for all network interfaces.
  # This is the listener to which the packet-forwarder forwards its data
  # so make sure the 'serv_port_up' and 'serv_port_down' from your
  # packet-forwarder matches this port.
  udp_bind = "0.0.0.0:1700"

  # Fake RX timestamp.
  #
  # Fake the RX time when the gateway does not have GPS, in which case
  # the time would otherwise be unset.
  fake_rx_time=false


  # ChirpStack Concentratord backend.
  #[backend.concentratord]

  # Event API URL.
  #event_url="ipc:///tmp/concentratord_event"

  # Command API URL.
  #command_url="ipc:///tmp/concentratord_command"


  # Basic Station backend.
  [backend.basic_station]

  # ip:port to bind the Websocket listener to.
  bind=":3001"

  # TLS certificate and key files.
  #
  # When set, the websocket listener will use TLS to secure the connections
  # between the gateways and ChirpStack Gateway Bridge (optional).
  tls_cert=""
  tls_key=""

  # TLS CA certificate.
  #
  # When configured, ChirpStack Gateway Bridge will validate that the client
  # certificate of the gateway has been signed by this CA certificate.
  ca_cert=""

  # Stats interval.
  #
  # This defines the interval in which the ChirpStack Gateway Bridge forwards
  # the uplink / downlink statistics.
  stats_interval="30s"

  # Ping interval.
  ping_interval="1m0s"

  # Timesync interval.
  #
  # This defines the interval in which the ChirpStack Gateway Bridge sends
  # a timesync request to the gateway. Setting this to 0 disables sending
  # timesync requests.
  timesync_interval="0s"

  # Read timeout.
  #
  # This interval must be greater than the configured ping interval.
  read_timeout="1m5s"

  # Write timeout.
  write_timeout="1s"

  # Region.
  #
  # Please refer to the LoRaWAN Regional Parameters specification
  # for the complete list of common region names.
  region="EU868"

  # Minimal frequency (Hz).
  frequency_min=863000000

  # Maximum frequency (Hz).
  frequency_max=870000000

  # Concentrator configuration.
  #
  # This section contains the configuration for the SX1301 concentrator chips.
  # Example:
  # [[backend.basic_station.concentrators]]
  #
  #   # Multi-SF channel configuration.
  #   [backend.basic_station.concentrators.multi_sf]
  #
  #   # Frequencies (Hz).
  #   frequencies=[
  #     868100000,
  #     868300000,
  #     868500000,
  #     867100000,
  #     867300000,
  #     867500000,
  #     867700000,
  #     867900000,
  #   ]
  #
  #   # LoRa STD channel.
  #   [backend.basic_station.concentrators.lora_std]
  #
  #   # Frequency (Hz).
  #   frequency=868300000
  #
  #   # Bandwidth (Hz).
  #   bandwidth=250000
  #
  #   # Spreading factor.
  #   spreading_factor=7
  #
  #   # FSK channel.
  #   [backend.basic_station.concentrators.fsk]
  #
  #   # Frequency (Hz).
  #   frequency=868800000


# Integration configuration.
[integration]
# Payload marshaler.
#
# This defines how the MQTT payloads are encoded. Valid options are:
# * protobuf:  Protobuf encoding
# * json:      JSON encoding (for debugging)
marshaler="json"

  # MQTT integration configuration.
  [integration.mqtt]
  # Event topic template.
  event_topic_template="gateway/{{ .GatewayID }}/event/{{ .EventType }}"

  # State topic template.
  #
  # States are sent by the gateway as retained MQTT messages (by default)
  # so that the last message will be stored by the MQTT broker. When set to
  # a blank string, this feature will be disabled. This feature is only
  # supported when using the generic authentication type.
  state_topic_template="gateway/{{ .GatewayID }}/state/{{ .StateType }}"

  # Command topic template.
  command_topic_template="gateway/{{ .GatewayID }}/command/#"

  # State retained.
  #
  # By default this value is set to true and states are published as retained
  # MQTT messages. Setting this to false means that states will not be retained
  # by the MQTT broker.
  state_retained=true

  # Keep alive will set the amount of time (in seconds) that the client should
  # wait before sending a PING request to the broker. This will allow the client
  # to know that a connection has not been lost with the server.
  # Valid units are 'ms', 's', 'm', 'h'. Note that these values can be combined, e.g. '24h30m15s'.
  keep_alive="30s"

  # Maximum interval that will be waited between reconnection attempts when connection is lost.
  # Valid units are 'ms', 's', 'm', 'h'. Note that these values can be combined, e.g. '24h30m15s'.
  max_reconnect_interval="1m0s"

  # Terminate on connect error.
  #
  # When set to true, instead of re-trying to connect, the ChirpStack Gateway Bridge
  # process will be terminated on a connection error.
  terminate_on_connect_error=false

  # MQTT authentication.
  [integration.mqtt.auth]
  # Type defines the MQTT authentication type to use.
  #
  # Set this to the name of one of the sections below.
  type="generic"

    # 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://mosquitto:1883",
    ]

    # Connect with the given username (optional)
    username=""

    # Connect with the given password (optional)
    password=""

    # Quality of service level
    #
    # 0: at most once
    # 1: at least once
    # 2: exactly once
    #
    # Note: an increase of this value will decrease the performance.
    # For more information: https://www.hivemq.com/blog/mqtt-essentials-part-6-mqtt-quality-of-service-levels
    qos=0

    # Clean session
    #
    # Set the "clean session" flag in the connect message when this client
    # connects to an MQTT broker. By setting this flag you are indicating
    # that no messages saved by the broker for this client should be delivered.
    clean_session=true

    # Client ID
    #
    # Set the client id to be used by this client when connecting to the MQTT
    # broker. A client id must be no longer than 23 characters. When left blank,
    # a random id will be generated. This requires clean_session=true.
    client_id=""

    # CA certificate file (optional)
    #
    # Use this when setting up a secure connection (when server uses ssl://...)
    # but the certificate used by the server is not trusted by any CA certificate
    # on the server (e.g. when self generated).
    ca_cert=""

    # mqtt TLS certificate file (optional)
    tls_cert=""

    # mqtt TLS key file (optional)
    tls_key=""

Thanks

Try

sugo systemctl status mosquitto

What do you see?

hmmm… I get? @marekpow

chirpstack-docker]# sudo systemctl status mosquitto
Unit mosquitto.service could not be found.

So, probably, it isn’t installed.

How to Install The Mosquitto MQTT Broker on Linux (steves-internet-guide.com)

Are you sure that you installed all the components needed by CS?

Thanks @marekpow, you got me thinking and I went into the docker-compose.yml and saw there was no Ports assigned to my mosquitto. :slightly_smiling_face: (I must have deleted by accident.)

It was:

mosquitto:
    image: eclipse-mosquitto:2
    restart: unless-stopped
    volumes:
      - ./configuration/mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf

and it should be:

mosquitto:
    image: eclipse-mosquitto:2
    restart: unless-stopped
    ports:
      - 1883:1883
    volumes:
      - ./configuration/mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf

So I can connect to my mosquitto broker now in Node-Red and I can see messages coming in, just need to find a way to publish to my Postgres DB.

Why do you do this way? Why don’t you use the standard way described in the CS documentation? Do you want to have software that will manage up and downlinks?

Hi @marekpow,

Thanks, Are you referring to this documentation here?

I have this integration and can see the following tables here as listed, but I cannot see the Gateway Status (State) in any of these tables.

So I’d like to know if there’s a way to add the Gateway State to my Postgres Table, natively without using Node-Red???

state_topic_template="gateway/{{ .GatewayID }}/state/{{ .StateType }}"

I can get the Gateway ‘State’ using Node-red, I was just wondering if CS could generate this natively through the Integration.

Screenshot 2024-01-29 at 11.12.38 PM

Question one, my answer: yes.
To be honest, I rarely often look into the Postgres tables being in the basement for CS.
I use CS=> Application=>Events & LoraWAN frames.
I see the status of the gateway on the CS web interface http://< IP address of the gateway >:8080.

1 Like