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

    simple mqtt client not working

    Scheduled Pinned Locked Moved LoPy
    mqttlopy
    6 Posts 3 Posters 2.0k Views 3 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.
    • M Offline
      misterlisty
      last edited by

      Trying to run simple mqtt example but always get error at 140 of mqtt.py

      ♦Traceback (most recent call last):
      File "<stdin>", line 14, in <module>
      File "/flash/lib/mqtt.py", line 140, in subscribe
      TypeError: function missing 1 required positional arguments

          struct.pack_into("!BH", pkt, 1, 2 + 2 + len(topic) + 1, self.pid)
          #print(hex(len(pkt)), hexlify(pkt, ":"))
          self.sock.write(pkt)
          self._send_str(topic)
          self.sock.write(qos.to_bytes(1))  # LINE 140
          while 1:
              op = self.wait_msg()
              if op == 0x90:
                  resp = self.sock.read(4)
      
      1 Reply Last reply Reply Quote 0
      • St3veVS Offline
        St3veV
        last edited by

        Hey... I had a same issue and it was fairly simple to fix it.
        I've created a pull request to the GitHub repo (https://github.com/pycom/pycom-libraries/pull/36) so you can check what is changed.
        I'll struggle with the CLA agreement tomorrow to make the PR mergeable.

        1 Reply Last reply Reply Quote 0
        • M Offline
          misterlisty
          last edited by

          This is my mqtt main.py which sends msg ok but the subscribe is not returning anything? ANyone see anything wrong?

          from network import WLAN
          from mqtt import MQTTClient
          import machine
          import time

          print("Setup::event")
          def sub_cb(topic, msg):
          print("mqtt::",topic,"msg[",msg,"]")

          print("Connected to Wifi\n")
          client = MQTTClient("demo", "test.smallbiz.com.au", port=1883)
          client.settimeout = 10000
          client.set_callback(sub_cb)
          client.connect()
          client.subscribe(topic="lopy01/inbox")

          while True:
          print("Sending ON")
          client.publish("lopy01/outbox/", "ON")
          time.sleep(1)
          print("Sending OFF")
          client.publish("lopy01/outbox/", "OFF")
          time.sleep(1)

          St3veVS 1 Reply Last reply Reply Quote 0
          • St3veVS Offline
            St3veV @misterlisty
            last edited by

            @misterlisty The tutorial is broken. You have to manually check for new messages. I created another PR for the tutorial: https://github.com/pycom/pycom-documentation/pull/15

            H 1 Reply Last reply Reply Quote 0
            • M Offline
              misterlisty
              last edited by

              thanks its working now

              1 Reply Last reply Reply Quote 0
              • H Offline
                hansamann @St3veV
                last edited by

                @st3vev thx so much. This should really be mentioned in the tutorial. I also think that this polling needs to be activated automatically once a subscribe happens.

                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