MQTT integration with application server

Hi,

I would like to know the steps to integrate the Chirpstack application server with an external MQTT broker so that I can receive uplink data from my device on this MQTT broker and initiate downlink data from the broker to the application server.

I have installed Chirpstack version 4 using docker compose. After adding application and devices I navigated to integration tab to add MQTT integration. But the MQTT panel there displays “Get certificate”. If I click on it it displays “Generate MQTT certificate”. Then if I click on “Generate certificate” I get an error on the page " Error: Read mqtt ca_cert".

How do I integrate an external broker to talk to the application and devices I have added.

Thanks

Regards,
Harsha

MQTT integration:

https://www.chirpstack.io/docs/chirpstack/integrations/mqtt.html

Note that you will need to enable it (see [integration]):

https://www.chirpstack.io/docs/chirpstack/configuration.html

1 Like

Did you ever resolve this issue? If so, what was the solution?

All the “MQTT integration” button does is sign a certificate you can use to subscribe to the MQTT broker’s topics if you have already set up MQTT TLS by following these steps.

If you haven’t set up Mosquitto TLS, you can simply subscribe to your MQTT broker using mosquitto_sub -v -h broker_ip -p 1883 -t '#'.

If you wanted to pipe the MQTT topics to another MQTT broker you should look into MQTT-Mirror or MQTT-Bridge. Although this is really only necessary for some niche use-cases as most applications can simply subscribe to the MQTT-broker Chirpstack uses to view the events.

1 Like

Hello sir,

I have the same issue as Harsha, I struggle to “push” the data I receive on ChirpStack towards my MQTT broker. Since I’m completely new to the use of ChirpStack and almost every step related to data processing chains, I must say that I find the documentation about MQTT integration not very clear…
In practice, what must be done to actually integrate my MQTT broker with application server ?

Thanks
Regards

Your question isn’t exactly clear. When you say you are trying to “integrate your MQTT broker with application server” what do you mean by that?

Are you running Chirpstack V3 or V4? Chirpstack V3 is separated between an application server and a network server, and if this is what you mean by application server you should really just use Chirpstack V4, especially if you are new.

Is your goal to have an external application listen to the events on the Chirpstack MQTT Broker? or do you wish to send events to an external MQTT broker you have setup?

As you’re new I’m going to assume you are using V4, and are trying to add the integration events to Chirpstacks MQTT Broker, then have an external application subscribe to the Broker and see these events:

A bit of information first:

In the MQTT Event Types outlined in the documentation, the first four events: up/status/join/ack, should all already be being sent in your MQTT Broker, they are the four messages Chirpstack uses internally and requires to run, if you view your Chirpstack logs or subscribe to the MQTT Broker you should already see them. The rest of the events: txack, log, location, integration, are optional events that you can enable through the integrations section of your Chirpstack.toml. Note that the “integration event” is actually several events with the same topic format: application/<application_id>/device/<devEUI>/event/<event>.

To enable these optional events, all that is necessary is to fill in the following configuration section in your chirpstack.toml, if you do not have an integration section you can add it:

[integration]
  enabled=["mqtt"]
  [integration.mqtt]
    server="tcp://$MQTT_BROKER_HOST:1883/"
    json=true

If you wish to instead send the optional events to an external MQTT Broker you could change the location in the server= line.

Then to view these events your application must subscribe to one of the brokers topics, either a specific topic or all of them using the “#” wildcard topic, you must figure out how to do this yourself for the purposes of your application. For debugging, you can subscribe to the MQTT broker yourself using:

mosquitto_sub -v -h broker_ip -p 1883 -t '#'

If you have done the steps bconway outlined here to enable TLS for your MQTT Broker using self-signed certificates, then you must use the mosquitto_sub command with the “MQTT Integration” certificates given through the web UI.

I hope this wasn’t too much of an information dump but it really is necessary to understand how Chirpstack works before trying to build anything on top of it. Good luck!

1 Like

First of all thank you very much for your answer, now things make more sense.

I’m running ChirpStack V4 and I’d like to send events to an external MQTT broker that I have setup localy for instance.
There is one thing I still haven’t figured out : where should I write the command lines (for example about the configuration section in chirpstack.toml) ? Until now, my access to Chirpstack was limited to my web browser since I’m working on a pre-existing LoRa network (my school network), and I don’t see where I could write anything. I guess it’s a foolish question, so sorry to bother you !

thanks a lot
Sincerely,

No worries man, I’m happy to help.

Unfortunately if you only have access to the web-interface you won’t be able to set up the MQTT Broker Integration.

If you do have access to ssh into the server running Chirpstack there is a main configuration called chirpstack.toml, the location of this file depends on your system and how it was setup (I.E what machine is it running on? Ubuntu, Raspberry Pi? Is it setup in Docker?).

Regardless of what the setup is though it shouldn’t be too hard to poke around and find the chirpstack.toml file. In there you need to enable the mqtt integration and configure it as I showed in the previous message, then restart Chirpstack (again doing this depends on the system).

For reference my setup is on a Ubuntu VM, and I set it up using docker following these instructions, and the path to my chirpstack.toml file is:

/home/local/chirpstack-docker/configuration/chirpstack

I believe in non-docker Ubuntu setups the path is:

/home/(your-user)/etc/chirpstack/chirpstack.toml

Well, I work on macOS and also use Docker to run ChirpStack (I followed the steps depicted in the documentation). By doing so I was able to access the files (chirpstack.toml file particularly), and I also specified the region (EU868 for me). But then, how can connect to the Chirpstack server of my school using my old ID and password via Docker ?

I don’t understand, did you set up the schools Chirpstack server and no longer have access? Or are you saying you have a second (irrelevant) server running on your mac?

If you have never accessed the computer the schools server is running on (either through ssh or physically using the computer) then you would need to request access from whoever runs it in your school.

Regardless there’s nothing I can do to help you access the schools Chirpstack server if you don’t know how to.

Yes, I have a second server running on my mac but it is obviously irrelevant. Okay, I see. I’m not familiar with ssh, could you explain briefly the way it works ?

Thank you very much for sharing your knowledge man.

Most computers allow you to SSH (standing for secure shell) into them, although if your school’s IT department is any good it will probably be blocked by a firewall.

All that SSH’ing does is allow you to have remote access to the computer through it’s command line (meaning no user interface, like using your Mac through the terminal app). To do this open terminal and use the command:
ssh user@ip-or-dns-of-server

user needs to be replaced with a username of an account on the computer and the ip-or-dns-of-server needs to be replaced with either the IP or the DNS of the server (DNS stands for domain name server, some examples are: google.com or forum.chirpstack.io, note that the DNS does not include HTTP://). It will then prompt you for your accounts password and if correct you will be allowed access into the computers command line.

I am assuming you do not know the IP/DNS of your Chirpstack server (although it should be the same as the DNS you use to access the web interface so you could try that) and secondly I assume the server will be blocked from external traffic (this means you might be able to SSH to the machine if you are on the school wifi, but probably won’t be able to from any other wifi).

If these are true then again I cannot help you access the server. Although feel free to ask more questions.

Happy Hacking, :wink:

1 Like

Thank you for your explanations. Indeed, it’s hard to understand that part of the integration can be “optional” and only configurable in SSH when there is a MQTT_Forwarder function in the console that does half the work. if I understood correctly if I want to send only the sensor data (application.…)I configure the file in SSH (optional integration) and I don’t need to activate the MQTT_Forwarder?

Yes, to forward your decrypted sensor packets to an MQTT broker you will want to configure the [integration] section of your chirpstack.toml via SSH.

If you are talking about the Chirpstack MQTT_Forwarder, it is not actually for integrations at all. It is to translate a gateways packets (typically UDP) to MQTT for the gateway ↔ chirpstack backend, not for the chirpstack ↔ application integration.

Thank you for your feedback

Hello Liam
Could tell me if the following changes (BOLD) the chirpstack.toml are OK for you.
You remember, i wouls like to send a door status (for example) from a dragino device connected to my PI3+PG1302+Chirpstack to another brocker running on another PI+Raspian+Mosquito+Jeedom(like home assistant). At that time it works well with an integration with Helium (my Helium miner with MQTT integration) but i want now use a Chirpstack Gateway (for my second house, less expansive than a Helium miner gateway)

Thanks a lots
Arnaud from France (Paris)

#Global integration related configuration.
[integration]

#Enabled integrations (global).
enabled=[“mqtt”]

#MQTT integration configuration.
[integration.mqtt]

# Event topic template.
event_topic="application/{{application_id}}/device/{{dev_eui}}/event/{{event}}"

# Command topic.
# This is the topic on which the MQTT subscribes for receiving (enqueue) commands.
command_topic="application/{{application_id}}/device/{{dev_eui}}/command/{{command}}"

# Use JSON encoding instead of Protobuf (binary).
json=true

# MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws)

#MY mosquito MQTT BROCKER IS CONNECTED TO MY BOX PUBLIC IP XYZ.XYZ.XYZ.XYZ(port 1883)
# i remove server=“tcp://127.0.0.1:1883/”
server=“mqtt://XYZ.XYZ.XYZ.XYZ:1883”

#Connect with the given username (optional)
#Username of MY mosquito local BROCKER IS “mybrocker”(@BOX PUBLIC IP XYZ.XYZ.XYZ.XYZ(port 1883)
username=“mybrocker”

# Connect with the given password (optional)

#The password given by my local Brocker is
password=« abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqr»

Yes, those changes all seem okay, assuming you have all the config on your external MQTT broker to match this.

Although are you using the Full Chirpstack Gateway OS installation? Or do you have an external Chirpstack server? If it’s the full GW OS install you should realize that these changes will not persist through a reboot.

Yes i use the Full Chirpstack on my PI3+PG1302

Do you mean that that il will be better to load the “base” version to make the configuration persistent ?.. and then do all the configuration manually :frowning:

Data are sent to another PI4B with mosquito (the Broker) that Consume the data (the door status in differerente scenarios)

No, what I mean is that the Chirpstack gateway OS itself is flawed for integrations. The configuration files are created on boot, and the only way (to my knowledge) to create persistent changes to these files is using UCI commands
or directly changing the bootup script. Since the integration section of the chirpstack.toml does not have any UCI commands set up, there is no native support for changing those.

The ideal solution is to use your RPI as just a gateway, then have your chirpstack server located somewhere else using the docker or ubuntu install. If you cannot do that, then your only options are edit the chirpstack.toml on each reboot, or find the boot file and edit the script that holds the initial chirpstack.toml configuration. I did the latter once, the only issue is that it won’t persist through updates.

What a shame such a fundamental element that works very well in Helium console doesn’t work with Chirpstack web interface. A little disappointed! I’m giving up chirpstarck for the moment and see if I don’t find a Helium miner not too expensive.
Thank you for your very clear information.
Arnaud de France