MQTT - Timer Hogging
Posted: Tue Jun 21, 2022 12:26 pm
Playing with the mqtt-paho example, I found that it uses up 3 of the 4 HiResTimers. It acquires three timers and keeps two active, using them occasionally. The third one is released and re-acquired throughout the publish-subscribe cycle.
The app I want to add mqtt to already uses two timers, so it crashes if I try to integrate this.
I tried hard-coding the init() function in class NBMQTTCountdown to use one specific timer (i.e. timer = HiResTimer::getHiResTimer(3);) and it seems to run on that one timer exactly as it did on three. I have had it running for a couple of days with the hard-coded timer number and it seems fine.
Is this going to blow up on me, or can it survive on one timer? I would also like to know how to restrict it to one timer without using a magic number.
I have listed the output before and after hard-coding the timer number at the end of this entry. Sorry they are so long - they are the connect-to-server, connect to broker, and two publish - subscribe cycles. The calling method is shown for each line
Ed
timer = HiResTimer::getHiResTimer();
[
Waiting 2sec to start 'A' to abort
Configured IP = 192.168.50.239
Configured Mask = 255.255.255.0
MAC Address= 00:03:f4:04:5c:fa
Application started
timer 0x20008e54 acquired
timer 0x20008e82 acquired
timer 0x20008eb0 acquired
timer 0x20008eb0 accessed-countdown_ms
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008e54 accessed-countdown_ms
timer 0x20008e54 accessed-countdown
timer 0x20008e82 accessed-countdown_ms
timer 0x20008e82 accessed-countdown
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008e82 accessed-countdown_ms
timer 0x20008e82 accessed-countdown
timer 0x20008e54 accessed-expired
timer 0x20008e54 accessed-left_ms
timer 0x20008e82 accessed-expired
timer 0x20008e82 accessed-left_ms
timer 0x20008eb0 released
timer 0x20008eb0 acquired
timer 0x20008eb0 accessed-countdown_ms
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008e54 accessed-countdown_ms
timer 0x20008e54 accessed-countdown
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008e82 accessed-countdown_ms
timer 0x20008e82 accessed-countdown
timer 0x20008e54 accessed-expired
timer 0x20008e54 accessed-left_ms
timer 0x20008e82 accessed-expired
timer 0x20008e82 accessed-left_ms
timer 0x20008eb0 released
timer 0x20008eb0 acquired
timer 0x20008eb0 accessed-countdown_ms
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008e54 accessed-countdown_ms
timer 0x20008e54 accessed-countdown
timer 0x20008eb0 released
timer 0x20008eb0 acquired
timer 0x20008eb0 accessed-countdown_ms
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008e82 accessed-countdown_ms
timer 0x20008e82 accessed-countdown
Message 1 arrived: qos 0, retained 0, dup 0, packetid 10618
Payload: nb-5CFA -> Uptime: 35
timer 0x20008e54 accessed-expired
timer 0x20008e54 accessed-left_ms
timer 0x20008e82 accessed-expired
timer 0x20008e82 accessed-left_ms
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008e54 accessed-expired
timer 0x20008e54 accessed-left_ms
timer 0x20008e82 accessed-expired
timer 0x20008e82 accessed-left_ms
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 released
timer 0x20008eb0 acquired
timer 0x20008eb0 accessed-countdown_ms
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008e54 accessed-countdown_ms
timer 0x20008e54 accessed-countdown
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008e82 accessed-countdown_ms
timer 0x20008e82 accessed-countdown
timer 0x20008e54 accessed-expired
timer 0x20008e54 accessed-left_ms
timer 0x20008e82 accessed-expired
timer 0x20008e82 accessed-left_ms
timer 0x20008eb0 released
timer 0x20008eb0 acquired
timer 0x20008eb0 accessed-countdown_ms
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008e54 accessed-countdown_ms
timer 0x20008e54 accessed-countdown
timer 0x20008eb0 released
timer 0x20008eb0 acquired
timer 0x20008eb0 accessed-countdown_ms
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008e82 accessed-countdown_ms
timer 0x20008e82 accessed-countdown
Message 2 arrived: qos 0, retained 0, dup 0, packetid 10618
Payload: nb-5CFA -> Uptime: 70
timer 0x20008e54 accessed-expired
timer 0x20008e54 accessed-left_ms
timer 0x20008e82 accessed-expired
timer 0x20008e82 accessed-left_ms
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008e54 accessed-expired
timer 0x20008e54 accessed-left_ms
timer 0x20008e82 accessed-expired
timer 0x20008e82 accessed-left_ms
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 released]
timer = HiResTimer::getHiResTimer(3);
[
Waiting 2sec to start 'A' to abort
Configured IP = 192.168.50.239
Configured Mask = 255.255.255.0
MAC Address= 00:03:f4:04:5c:fa
Application started
timer 0x20008ede acquired
timer 0x20008ede acquired
timer 0x20008ede acquired
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-countdown
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-countdown
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-countdown
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede released
timer 0x20008ede acquired
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-countdown
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-countdown
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede released
timer 0x20008ede acquired
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-countdown
timer 0x20008ede released
timer 0x20008ede acquired
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-countdown
Message 1 arrived: qos 0, retained 0, dup 0, packetid 10618
Payload: nb-5CFA -> Uptime: 35
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede released
timer 0x20008ede acquired
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-countdown
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-countdown
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede released
timer 0x20008ede acquired
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-countdown
timer 0x20008ede released
timer 0x20008ede acquired
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-countdown
Message 2 arrived: qos 0, retained 0, dup 0, packetid 10618
Payload: nb-5CFA -> Uptime: 70
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede released
]
The app I want to add mqtt to already uses two timers, so it crashes if I try to integrate this.
I tried hard-coding the init() function in class NBMQTTCountdown to use one specific timer (i.e. timer = HiResTimer::getHiResTimer(3);) and it seems to run on that one timer exactly as it did on three. I have had it running for a couple of days with the hard-coded timer number and it seems fine.
Is this going to blow up on me, or can it survive on one timer? I would also like to know how to restrict it to one timer without using a magic number.
I have listed the output before and after hard-coding the timer number at the end of this entry. Sorry they are so long - they are the connect-to-server, connect to broker, and two publish - subscribe cycles. The calling method is shown for each line
Ed
timer = HiResTimer::getHiResTimer();
[
Waiting 2sec to start 'A' to abort
Configured IP = 192.168.50.239
Configured Mask = 255.255.255.0
MAC Address= 00:03:f4:04:5c:fa
Application started
timer 0x20008e54 acquired
timer 0x20008e82 acquired
timer 0x20008eb0 acquired
timer 0x20008eb0 accessed-countdown_ms
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008e54 accessed-countdown_ms
timer 0x20008e54 accessed-countdown
timer 0x20008e82 accessed-countdown_ms
timer 0x20008e82 accessed-countdown
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008e82 accessed-countdown_ms
timer 0x20008e82 accessed-countdown
timer 0x20008e54 accessed-expired
timer 0x20008e54 accessed-left_ms
timer 0x20008e82 accessed-expired
timer 0x20008e82 accessed-left_ms
timer 0x20008eb0 released
timer 0x20008eb0 acquired
timer 0x20008eb0 accessed-countdown_ms
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008e54 accessed-countdown_ms
timer 0x20008e54 accessed-countdown
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008e82 accessed-countdown_ms
timer 0x20008e82 accessed-countdown
timer 0x20008e54 accessed-expired
timer 0x20008e54 accessed-left_ms
timer 0x20008e82 accessed-expired
timer 0x20008e82 accessed-left_ms
timer 0x20008eb0 released
timer 0x20008eb0 acquired
timer 0x20008eb0 accessed-countdown_ms
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008e54 accessed-countdown_ms
timer 0x20008e54 accessed-countdown
timer 0x20008eb0 released
timer 0x20008eb0 acquired
timer 0x20008eb0 accessed-countdown_ms
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008e82 accessed-countdown_ms
timer 0x20008e82 accessed-countdown
Message 1 arrived: qos 0, retained 0, dup 0, packetid 10618
Payload: nb-5CFA -> Uptime: 35
timer 0x20008e54 accessed-expired
timer 0x20008e54 accessed-left_ms
timer 0x20008e82 accessed-expired
timer 0x20008e82 accessed-left_ms
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008e54 accessed-expired
timer 0x20008e54 accessed-left_ms
timer 0x20008e82 accessed-expired
timer 0x20008e82 accessed-left_ms
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 released
timer 0x20008eb0 acquired
timer 0x20008eb0 accessed-countdown_ms
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008e54 accessed-countdown_ms
timer 0x20008e54 accessed-countdown
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008e82 accessed-countdown_ms
timer 0x20008e82 accessed-countdown
timer 0x20008e54 accessed-expired
timer 0x20008e54 accessed-left_ms
timer 0x20008e82 accessed-expired
timer 0x20008e82 accessed-left_ms
timer 0x20008eb0 released
timer 0x20008eb0 acquired
timer 0x20008eb0 accessed-countdown_ms
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008e54 accessed-countdown_ms
timer 0x20008e54 accessed-countdown
timer 0x20008eb0 released
timer 0x20008eb0 acquired
timer 0x20008eb0 accessed-countdown_ms
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008e82 accessed-countdown_ms
timer 0x20008e82 accessed-countdown
Message 2 arrived: qos 0, retained 0, dup 0, packetid 10618
Payload: nb-5CFA -> Uptime: 70
timer 0x20008e54 accessed-expired
timer 0x20008e54 accessed-left_ms
timer 0x20008e82 accessed-expired
timer 0x20008e82 accessed-left_ms
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 accessed-left_ms
timer 0x20008e54 accessed-expired
timer 0x20008e54 accessed-left_ms
timer 0x20008e82 accessed-expired
timer 0x20008e82 accessed-left_ms
timer 0x20008eb0 accessed-expired
timer 0x20008eb0 accessed-left_ms
timer 0x20008eb0 released]
timer = HiResTimer::getHiResTimer(3);
[
Waiting 2sec to start 'A' to abort
Configured IP = 192.168.50.239
Configured Mask = 255.255.255.0
MAC Address= 00:03:f4:04:5c:fa
Application started
timer 0x20008ede acquired
timer 0x20008ede acquired
timer 0x20008ede acquired
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-countdown
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-countdown
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-countdown
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede released
timer 0x20008ede acquired
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-countdown
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-countdown
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede released
timer 0x20008ede acquired
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-countdown
timer 0x20008ede released
timer 0x20008ede acquired
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-countdown
Message 1 arrived: qos 0, retained 0, dup 0, packetid 10618
Payload: nb-5CFA -> Uptime: 35
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede released
timer 0x20008ede acquired
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-countdown
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-countdown
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede released
timer 0x20008ede acquired
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-countdown
timer 0x20008ede released
timer 0x20008ede acquired
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-countdown_ms
timer 0x20008ede accessed-countdown
Message 2 arrived: qos 0, retained 0, dup 0, packetid 10618
Payload: nb-5CFA -> Uptime: 70
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede accessed-expired
timer 0x20008ede accessed-left_ms
timer 0x20008ede released
]