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

    Calling functions in uMQTT

    Scheduled Pinned Locked Moved Discussion
    umgttmqttmicropythonadafruit iowipy mqtt
    4 Posts 2 Posters 503 Views 2 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.
    • D Offline
      Dezert754
      last edited by Dezert754

      So I tried sending some data to Adafruit IO. I followed the guide created by Chris from core electronics located here. All his code works perfect, I can turn on and off my LED and the random data is sent fine. However I tried to add some of my own functions and it seems that they are not called.

      I am used to the python way of creating and calling a function:

      def some_random_function
          print("Apples!")
      
      some_random_function()
      

      However the umqtt doesn't feature anything like that so it looks like chris' functions get called automatically.

      So I attempted to create my function following what he did, however my function doesn't even get called as I dont get my first print statement.

      def send_bme():
          print("Wipy trying to send: ", bme280.values)
          try:
              client.publish(topic=AIO_BME_FEED, msg=str(bme280.values))
              print("Success!")
              time.sleep(5)
          except Exception as e:
              print("Failed!")
              time.sleep(5)
      
      1 Reply Last reply Reply Quote 0
      • P Offline
        Paul Thornton
        last edited by Paul Thornton

        I took a quick glance at the code you linked.

        Looks like he calls his send_random function from the main loop each time.

        You'll need to do the same to have yours called

        while 1:              # Repeat this loop forever
                client.check_msg()# Action a message if one is received. Non-blocking.
                send_random() #here. 
                some_random_function() #add a call to your function here
                
        
        D 1 Reply Last reply Reply Quote 0
        • D Offline
          Dezert754 @Paul Thornton
          last edited by

          @paul-thornton Thanks very much! So obvious, I dont know how I missed that, haha.

          P 1 Reply Last reply Reply Quote 0
          • P Offline
            Paul Thornton @Dezert754
            last edited by

            @dezert754 We've all had those moments :P glad its all sorted.

            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