MQTTClient subscriptions not working



  • Just curious what I'm doing wrong here. LoPY4 1.19.0.b4

    I'm assuming this is the client code: https://github.com/pycom/pycom-micropython-sigfox/blob/master/esp32/frozen/Common/MQTTClient.py

    I can publish but I cannot get a subscription working.
    The most I see is 'Packet sent. (Length: 4)' when publishing a message through broker when LoPY4 is subscribed.

    from MQTTClient import MQTTClient
    
    l99_serial = "abc"
    mqtt_client = MQTTClient(l99_serial, False, 4)
    mqtt_client.setLastWill('L99/{}/io/state/offline'.format(l99_serial), QoS=1)
    mqtt_client.configEndpoint('192.168.2.107', 1883)
    mqtt_client.connect(180)
    
    def mqtt_output_command_callback(ud,p=5):
        print('sub')
        print(ud)
    
    #mqtt_client.subscribe('L99/{}/io/OUTPUT/+/+'.format(l99_serial), 1, mqtt_output_command_callback)
    #mqtt_client.publish('L99/{}/io/state/online'.format(l99_serial), '', 1, False)
    
    mqtt_client.subscribe('L99/#', 1, mqtt_output_command_callback)
    


  • Well, whatever umqtt.simple works fine.

    import machine
    from umqtt.simple import MQTTClient
    
    def mqtt_output_command_callback(topic,message):
        print('sub')
        print(topic)
    
    l99_serial = "abc"
    mqtt_client = MQTTClient(l99_serial, '192.168.2.107', 1883)
    mqtt_client.set_last_will('L99/{}/io/state/offline'.format(l99_serial), '', qos=1)
    mqtt_client.connect()
    mqtt_client.set_callback(mqtt_output_command_callback)
    mqtt_client.subscribe('L99/{}/io/OUTPUT/+/+'.format(l99_serial), qos=1)
    mqtt_client.publish('L99/{}/io/state/online'.format(l99_serial), '', qos=1)
    
    while True:
        machine.idle()
        mqtt_client.check_msg()```

Log in to reply
 

Pycom on Twitter