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.