Calling functions in uMQTT
-
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) -
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 -
@paul-thornton Thanks very much! So obvious, I dont know how I missed that, haha.
-
@dezert754 We've all had those moments :P glad its all sorted.
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