🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Can't instantiate MQTT class (M5 Stick C Plus with Micropython)

    Scheduled Pinned Locked Moved Micropython
    3 Posts 2 Posters 6.1k Views
    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.
    • R Offline
      rousveiga
      last edited by

      Hello! I have a small MicroPython program running on my M5 Stick C Plus (with UI Flow firmware version 1.6.5.1-plus, as I get screen errors with 1.6.6-plus) and I wanted to add MQTT communication. I was following loboris' documentation and examples. However, I get the following error:

        File "main.py", line 289, in <module>
      AttributeError: 'module' object has no attribute 'mqtt'
      MicroPython 7021d9419-dirty on 2020-10-30; M5StickC-Plus with ESP32
      

      Line 289 looks as follows (I imported network earlier in the code):

      client = network.mqtt(NAME, SERVER, user="mosquitto", password="mosquitto", cleansession=True, connected_cb=conncb, disconnected_cb=disconncb, subscribed_cb=subscb, published_cb=pubcb, data_cb=datacb)
      

      I'm completely dumbfounded, as the same method call appears in the M5 Cloud MQTT example. Does anybody know what could be causing this behavior?

      Thanks in advance,

      Rosa

      1 Reply Last reply Reply Quote 0
      • sodokuS Offline
        sodoku
        last edited by

        If I use the mqtt blocks in UIFlow.1.6.6 it generates the following python code:

        from m5mqtt import M5mqtt
        
        m5mqtt = M5mqtt('NAME', 'SERVER', 1883, 'mosquitto', 'mosquitto', 300)
        
        m5mqtt.publish(str('topic'),str('message'))
        
        R 1 Reply Last reply Reply Quote 0
        • R Offline
          rousveiga @sodoku
          last edited by

          @sodoku I see! I'll try that code. Thank you!

          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
          • First post
            Last post