LoPy4 publishing to TTN v3 via MQTT



  • Has anybody managed to get functioning sample code? Studied tutorial on TTN website, used their CLI tools mosquitto_sub and mosquitt_pub: got data with mosquitto_sub, but cannot publish with mosquitto_pub. Neither can I get my LoPy to submit any data. LoPy is connected via wlan to the internet.

    from mqtt import MQTTClient
    import time
    
    def sub_cb(topic, msg):
       print(msg)
    
    client = MQTTClient(
        'dev7',
        'nam1.cloud.thethings.network',
        user='app7@ttn',
        password='NNSXS.GC.....',
        port=1883)
    
    client.set_callback(sub_cb)
    client.connect()
    time.sleep(3)
    
    client.publish(topic='v3/app7@ttn/devices/dev7/up', msg='vu8=')
    

    After client.connect() I get the following response.

    0xc b'10:7e:00:04:4d:51:54:54:04:c2:00:00'
    b' \x02\x00\x00'
    

    But no reaction to the client.publish(...) part. Got any ideas?



  • Meanwhile I am able to subscribe and publish from a Unix console with

    mosquitto_sub -h "nam1.cloud.thethings.network" -p "8883" -u "app7@ttn" -P "NNSXS.GCNX64NFC6OYQRVYMZZBQ2UT7DUYZ4AQW22QTOA.WVSKGGBTNDGA52OH4BERZPBPUSBS6TKSXLVTUNSCIFVJBOVG4KAA" -t "#" -d
    

    and

    mosquitto_pub -h "nam1.cloud.thethings.network" -p "8883" -u "app7" -P "NNSXS.GCNX64NFC6OYQRVYMZZBQ2UT7DUYZ4AQW22QTOA.WVSKGGBTNDGA52OH4BERZPBPUSBS6TKSXLVTUNSCIFVJBOVG4KAA" -t "v3/app7@ttn/devices/dev7/down/push" -m '{"downlinks":[{"f_port": 2, "frm_payload": "vu8=", "priority": "NORMAL"}]}' -d
    

    The problem was the payload as it needs to be encoded Base64 or it gets dismissed to Nirvana without feedback.

    So I know I can communicate to TTN v3. But I cannot replicate the same functionality from a LoPy4 module using its WiFi connection. It seems to make a valid connect(), but then there is no reaction on the callback function!? Is there any additional setup required to bring that to life?



  • For easier testing here's the complete config.

    client = MQTTClient(
        'dev7',
        'nam1.cloud.thethings.network',
        user='app7@ttn',
        password='NNSXS.GCNX64NFC6OYQRVYMZZBQ2UT7DUYZ4AQW22QTOA.WVSKGGBTNDGA52OH4BERZPBPUSBS6TKSXLVTUNSCIFVJBOVG4KAA',
        port=1883)
    

Log in to reply
 

Pycom on Twitter