Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    MQTTClient subscriptions not working

    Scheduled Pinned Locked Moved Discussion
    2 Posts 1 Posters 239 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C Offline
      cmisztur
      last edited by

      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)
      
      C 1 Reply Last reply Reply Quote 0
      • C Offline
        cmisztur @cmisztur
        last edited by

        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()```
        1 Reply Last reply Reply Quote 0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • 1 / 1
        • First post
          Last post

        Pycom on Twitter

        Pycom