I am working on a project with a nucleoF767ZI nucleo board. In this project I want to send MQTT messages every 100 milliseconds. However, when I use any kind of timer, it queues the messages and they get send every 500 milliseconds.
I use the umqtt library from https://github.com/micropython/micropyt ... qtt.simple, but have tried the one from https://github.com/fizista/micropython- ... ple_sub.py as well.
When I use
Code: Select all
while True:
client.publish("foo_topic", "hello")
When I tried either of the three following, they get queued, and sent around every 500ms, resulting in 10 messages coming in at once:
Code: Select all
lastTime = 0
while True:
if(ticks_ms() > lastTime + 100):
client.publish("foo_topic", "hello")
lastTime = ticks_ms()
Code: Select all
def sendMessage():
global client
client.publish(b"foo_topic", b"hello")
def tick(timer): # we will receive the timer object when being called
print(timer.counter()) # show current timer's counter value
micropython.schedule(sendMessage, "timer")
# create a timer object using timer 4 - trigger at 10Hz
tim = Timer(4, freq=10, callback=tick)
Code: Select all
lastTime = 0
while True:
client.publish("foo_topic", "hello")
utime.sleep_ms(100)