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

    M5 Stack unable to subscribe and recieve new messages

    M5 Stick/StickC
    3
    3
    2.6k
    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.
    • S
      sleepyfatcat
      last edited by

      Hello everyone, I am trying to print new messages on my m5 stick c plus, through hive mq. I am able to publish, but not able to subscribe. Not sure what is the issue here, please advise! Thank you in advance!

      Here is my code:

      from m5stack import *
      from m5ui import *
      from uiflow import *
      import time
      
      setScreenColor(0x111111)
      
      
      PASSW = None
      CLIENTID = None
      USER = None
      HOST = None
      
      
      
      label0 = M5TextBox(47, 49, "label0", lcd.FONT_Default, 0xFFFFFF, rotate=0)
      label1 = M5TextBox(47, 176, "label0", lcd.FONT_Default, 0xFFFFFF, rotate=0)
      
      
      PASSW = 'password'
      CLIENTID = 'm5stack'
      USER = 'user'
      HOST = '07ecd30c.s1.eu.hivemq.cloud'
      from m5mqtt import M5mqtt
      
      m5mqtt = M5mqtt(CLIENTID,HOST,8883,USER,PASSW,300,ssl=True,ssl_params={'server_hostname':HOST})
      m5mqtt.start()
      label0.setText('Hello M5')
      
      a = None
      
      def callback(topic_data):
        a = topic_data
        label0.setText(str(a))
        pass
      
      while True:
        m5mqtt.subscribe(str('topic/1'), callback)
      

      My StickCPlus is currently v1.9.8-plus

      1 Reply Last reply Reply Quote 0
      • felmueF
        felmue
        last edited by

        Hello @sleepyfatcat

        any particular reason you subscribe in an infinite while loop? Last time I tried mqtt I called m5mqtt.subscribe() only once and just before calling m5mqtt.start().

        Thanks
        Felix

        GPIO translation table M5Stack / M5Core2
        Information about various M5Stack products.
        Code examples

        1 Reply Last reply Reply Quote 0
        • ajb2k3A
          ajb2k3
          last edited by ajb2k3

          what do you mean by "Not able to subscribe" ?
          Does it not connect or does it not return data?
          Does the data turn up in HiveMQ?

          This looks like Micropython but the functions look strange, you have SSL set to true but no keys and certificates set.

          UIFlow, so easy an adult can learn it!
          If I don't know it, be patient!
          I've ether not learned it or am too drunk to remember it!
          Author of the WIP UIFlow Handbook!
          M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post