@@ -1746,16 +1746,18 @@ void cbThrottleTopic(char *throttleData, uint16_t len) {
17461746 WS_DEBUG_PRINTVAR (throttleDuration);
17471747 WS_DEBUG_PRINTLN (" ms and blocking command execution." );
17481748
1749+ const uint32_t pingDelayMs = WS_DEVICE_PING_MS;
1750+
17491751 // If throttle duration is less than the keepalive interval, delay for the
17501752 // full keepalive interval
1751- if (throttleDuration < WS_DEVICE_PING_MS ) {
1752- delay (WS_DEVICE_PING_MS );
1753+ if (throttleDuration < pingDelayMs ) {
1754+ delay (pingDelayMs );
17531755 } else {
1754- // round to nearest millis to prevent delaying for less time than req'd .
1755- float throttleLoops = ceil (throttleDuration / WS_DEVICE_PING_MS) ;
1756+ // Round up so throttling never ends earlier than requested .
1757+ uint32_t throttleLoops = (throttleDuration + pingDelayMs - 1 ) / pingDelayMs ;
17561758 // block the run() loop
17571759 while (throttleLoops > 0 ) {
1758- delay (WS_DEVICE_PING_MS );
1760+ delay (pingDelayMs );
17591761 WS.feedWDT ();
17601762 WS._mqtt ->ping ();
17611763 throttleLoops--;
@@ -2474,7 +2476,7 @@ void Wippersnapper::runNetFSM() {
24742476 fsmNetwork = FSM_NET_CHECK_NETWORK;
24752477 break ;
24762478 case FSM_NET_ESTABLISH_MQTT:
2477- WS._mqtt ->setKeepAliveInterval (WS_BROKER_KEEPALIVE_MS / 1000 );
2479+ WS._mqtt ->setKeepAliveInterval (_brokerKeepAliveIntervalSeconds );
24782480 // Attempt to connect
24792481 maxAttempts = 5 ;
24802482 while (maxAttempts > 0 ) {
@@ -2794,6 +2796,8 @@ void Wippersnapper::connect() {
27942796 // Dump device info to the serial monitor
27952797 printDeviceInfo ();
27962798
2799+ _brokerKeepAliveIntervalSeconds = WS_BROKER_KEEPALIVE_MS / 1000 ;
2800+
27972801 // Generate device identifier
27982802 if (!generateDeviceUID ()) {
27992803 haltError (" Unable to generate Device UID" );
0 commit comments