Hi,
I’m trying to get the MQTT integration working on the “au1” region.
I was initially attempting to subscribe with paho-mqtt in Python, but have moved on to just trying mosquitto_sub for troubleshooting.
If I run the following:
mosquitto_sub -d -h au1.cloud.thethings.network -p 8883 -u 'gps-tracker@ttn' -P 'secret-key' -t 'v3/gps-tracker/devices/mygps/up' -v
It sits there with the output:
Client mosq-AK5uKe2jbJLKst57e9 sending CONNECT
Client mosq-AK5uKe2jbJLKst57e9 sending CONNECT
Client mosq-AK5uKe2jbJLKst57e9 sending CONNECT
Client mosq-AK5uKe2jbJLKst57e9 sending CONNECT
No messages are received and I am yet to receive any other responses.
I’ve tried a new API key and tried wildcards in the subscription path like ’ v3/gps
-tracker/devices/+/up’.
Paho MQTT seemed to actually subscribe, giving me:
log: Received SUBACK
log: Sending PINGREQ
log: Received PINGRESP
log: Sending PINGREQ
log: Received PINGRESP
But I could never received any messages.
Here’s the relevant section of my Python script:
def on_connect(client, userdata, flags, rc):
print(f'Connected with result code {rc}')
client.subscribe(f'v3/{app_id}/devices/{dev}/up')
def on_subscribed(client, userdata, mid, granted_qos):
print("Subscribed mid: " + str(mid) + ", qos: " + str(granted_qos))
def on_message(client, userdata, msg):
#message = json.loads(msg.payload.decode("utf-8"))
#values = message['payload_fields']
print("TEST")
def on_log(client, userdata, level, buf):
print("log: ",buf)
def client_init():
client = mqtt.Client()
client.on_connect = on_connect
client.on_subscribed = on_subscribed
client.on_message = on_message
client.on_log = on_log
client.tls_set()
client.username_pw_set(f'{app_id}@ttn', password=ttn["password"])
client.connect(ttn["server"], ttn["port"], 60)
client.loop_forever()
if __name__ == "__main__":
# Connect to TTN
client_init()
# Loop over everything
print("Starting main loop..")
#client.loop_forever()