Chipstack Newb and MQTT

I hope somebody can help me here. I am new to chirpstack, but I am having some success.
Everything is up and running and I have several devices from decentlabs, strega, tektellic etc that are communicating. From the chirpstack application server I can uplink and downlink etc. SO that is all good. Codecs are installed and devices are operational as far as the chripstack application server is considered. (yay me!)

I have an inductive automation (ignition) server that has an MQTT broker (Cirrus) and using that I can read all transmitter values (strega, decentlabs etc.) from chirpstack using the cirrus MQTT client. Data is appearing as it should (Json tags in ignition). This is our SCADA server and handles the GUI and a good portion of my historical data and reporting and this is a really good start.

However, I cannot seem to figure out a way to initiate a downlink from ignition to the some of my devices. I suspect it’s a compatibility issues between the sparklug b payload of Cirrus/ignition and the payload that the mosquito broker is expecting. No biggie - lets try some thing else.

I figured I could accomplish this using a little scripting in ignition which is jython. I figured I would start with the subscribe portion before attempting to publish data.

Using paho MQTT I am able to connect to the mosquitto broker and subscribe to a topic. But something is wrong (or more likely I am missing a step)

No matter what topic I connect to I always get the same return value, I get the same return value even if I change manually change the state of the of a device

For example:

Topic: application/1/device/0004a30b00f8d719/event/up

Returns: b’1628553637309’

Topic: ‘application/1/device/#’

Also returns: b’1628553637309

So the million dollar question is does that byte array represent?

Here is what I did in python (passwords, IP’s etc x’d out):

import time
import paho.mqtt.client as mqtt
import paho.mqtt.publish as publish
import json as json
import logging

define our variables to be used for Paho

user = ‘xxxx’
password = ‘xxxxx’
broker = ‘192.168.xx.xxx’ # mosquitto server IP
payload = ‘somestring’
topic = ‘application/1/device/#’ # strega emitter D719

values for ignition

tagpath = ‘[default]Memory Tags/Strega_Test’
values = [’’]

callback function

def on_connect(client, userdata, flags, rc):
print(‘Connected to {} with result code {}’.format(broker, rc))
print(‘Subscribing to Topic: {}’.format(topic))
client.subscribe(topic)

def on_disconnect(client, userdata, rc):
print(‘Disconnected from {} with result code {}’.format(broker, rc))

def on_message(client, userdata, message):
value = message.payload
#msg = json.loads(message.payload)
values[0] = value
#quality = system.tag.writeBlocking(tagpath, values)
print("{} value: {}".format(topic, value))
#print(’{} write quality: {}’).format(tagpath, quality)
int_value = int(message.payload)
hex_value = hex(int_value)
print (hex_value)
byte_array = bytearray(value)
#print (msg)
print(byte_array)

create a client and set the user name and password

client = mqtt.Client(client_id="", clean_session=True)
client.username_pw_set(user, password=password)

call callback functions

client.connect(broker)
client.loop_start()
client.on_connect = on_connect
client.on_disconnect = on_disconnect
client.on_message = on_message
time.sleep(10)
client.disconnect()
client.loop_stop()

The other thing that is frustrating is that the client will not subscribe to topics like:

application/1/device/0004a30b00f8d719/event/ack
application/1/device/0004a30b00f8d719/event/error

I have also tried subscribing to the broker using Node Red (MQTT_In) with the exact same results.

My Ignition client can see this data – so the million dollar question is what is wrong in Paho?

When I subscribe to a topic I would expect to see a json object as the payload would I not? Is that not the function of the codec in the chirpstack application server? (to decode the binary data received from the device)

Or when I am subscribing to the mosquito broker am I reading a binary representation of the json payload? Either way – why would that be the same regardless of the topic that I am trying to read or the state of the transmitter?

Any ideas on what is going wrong here for me?
The log files have been little to no help as I am connecting and subscribing with success.
I understand if you cant help – but I am curious if anyone could offer some insight…

Thanks so much in advance.

Topic: application/1/device/0004a30b00f8d719/event/up
Returns: b’1628553637309’

What do you mean “Returns”? Is that the return code of your scripts subscribe function call? Is that the data that is sent in the payload of a published message? Looks like a pointer value or something - maybe to the data structure that contains the message? I don’t know.

Can you try mosquitto_pub and moquito_sub to verify publishing test messages and subscribing to them? mosquitto_sub -h brokerip -t "application/1/device/0004a30b00f8d719/event/up" is the easiest way to test things are ok, and post that data?

This kinda looks like a paho script issue, perhaps better answered on their or stackoverflow

With that said, the payload marshaler (app server config) can be set to protobuf, not json_v3 (default) - I assume you did not change this setting from the default json_v3 - if its set to protobuf, then yes your payload data would be binary I think.

I am also under IA’s ignition, but subscribe to everything and deal with incoming data in a tag-change script that monitors these paths. Script effectively acts as a “bridge” between physical sensors and some pre-defined variables that get logged to data historian and have alarms configured.

I chose this path because many of my sensors have timed/supervisor message programmed (every 24hrs) and this way, the bridge hides this traffic from user/historian but still allows for proactive monitoring of sensor health (battery voltage, not-dead-yet, etc).

P.S. A killer feature for chirpstack would be some sort of framework for plugins. All my sensors are on intranet (not exposed to internet) which pretty much dooms me to having to encode configurations for sensors MANUALLY. That is, almost all vendors only support a website/console interface and from there one can perform configuration of sensors. I’ve seen very few exceptions - see https://neon-configurator.twtg.io. I salivate imagining something similar for ALL my sensors, even if I have to code it the first time :slight_smile:

BTW, some sensors (e.g., Laird) allow configuration of their sensors also using bluetooth - this has it’s place, but requires physical access to device (to press a button). They also allow same via downlinks, but encoding, again, is left as exercise to user.

Everything you just said is some weird esoteric stuff (no offense, sorry) of your project. We? don’t know about “IA’s algorithm”, or “tag change”, or “pre-defined variables that get logged to data historian and have alarms configured”. I don’t want to sound like a pooper on this, but none of that stuff matters to Chirpstack. Chirpstack is kinda like the TCP/IP layer of your app, and in this analogy it sounds like your cookie data in your http reply headers are not what you want (absolutely nothing to do with TCP/IP) (analogy, sorry again!)

Can you rephrase question to talk about issues with the comm stack, not your data?

Curt, you make a good, valid point. On the surface, this forum should be for ChirpStack issues and workarounds, etc. However, it should also be for broadcasting how ChirpStack may be made to work with other real-world applications, such as Ignition.

Specifically on this specific SCADA platform, there is a “preferred vendor” that users are insinuated to work with: Cirrus MQTT server. We are not to go and setup a ChirpStack server. On IA forums, implication is that they support Cirrus and give a cold shoulder to other competing solutions.

So, what are users to do? It’s a fine pickle. I vote that as long as we’re promoting use a ChirpStack, it’s beneficial for you to put up with us - we feel orphaned on “our” forums.

I purchased the MQTT Engine module ($1900) because that was absolutely the bare minimum to natively subscribe to sensor data (even then, decoders are left as exercise to implement in Jython, Java VM Python). The MQTT server pricing is rather steep at >$2,300. I get same functionality from ChirpStack. I don’t want to say “for free” because that’s not true - my time is not free. But, I can make my colleagues lives easier by pointing out ways to make data access easier.

Thank you.

Rob, did you obtain the decoders vendor offers in their FAQ (near bottom)? If you get same result for different requests, it points to transport/authentication problem. Are you seeing data frames from device being decoded in ChirpStack?

“Q: Does STREGA provide the DECODERS and ENCODERS for all these LNS platform?
A: Yes, the CODECS (Encoder and Decoder), written in JSCRIPT, are provided free of charge by STREGA, making the life of the Application Developers way easier to provision our payloads on their platform.”

NO, these are obsolete: THIS GitHub are from someone else, as source code lacks any copyright/author info.
CORRECT ones are HERE.