@@ -1735,29 +1735,34 @@ void cbThrottleTopic(char *throttleData, uint16_t len) {
17351735 (void )len; // marking unused parameter to avoid compiler warning
17361736 WS_DEBUG_PRINT (" IO Throttle Error: " );
17371737 WS_DEBUG_PRINTLNVAR (throttleData);
1738- char *throttleMessage;
1739- // Parse out # of seconds from message buffer
1740- throttleMessage = strtok (throttleData, " ," );
1741- throttleMessage = strtok (NULL , " " );
1742- // Convert from seconds to to millis
1743- int throttleDuration = atoi (throttleMessage) * 1000 ;
1744-
1738+ uint32_t throttleDuration = 60000UL ; // duration of throttle in ms
1739+ if (throttleData != NULL ) {
1740+ char *throttleMessage;
1741+ // Parse out # of seconds from message buffer
1742+ throttleMessage = strtok (throttleData, " ," );
1743+ if (throttleMessage != NULL ) {
1744+ throttleMessage = strtok (NULL , " " );
1745+ if (throttleMessage != NULL ) {
1746+ // Convert from seconds to to millis
1747+ throttleDuration = (uint32_t )atoi (throttleMessage) * 1000UL ;
1748+ }
1749+ }
1750+ }
17451751 WS_DEBUG_PRINT (" Device is throttled for " );
17461752 WS_DEBUG_PRINTVAR (throttleDuration);
17471753 WS_DEBUG_PRINTLN (" ms and blocking command execution." );
17481754
1749- const uint32_t pingDelayMs = WS_DEVICE_PING_MS;
1750-
17511755 // If throttle duration is less than the keepalive interval, delay for the
17521756 // full keepalive interval
1753- if (throttleDuration < pingDelayMs ) {
1754- delay (pingDelayMs );
1757+ if (throttleDuration < WS_DEVICE_PING_MS ) {
1758+ delay (WS_DEVICE_PING_MS );
17551759 } else {
17561760 // Round up so throttling never ends earlier than requested.
1757- uint32_t throttleLoops = (throttleDuration + pingDelayMs - 1 ) / pingDelayMs;
1761+ uint32_t throttleLoops =
1762+ (throttleDuration + WS_DEVICE_PING_MS - 1 ) / WS_DEVICE_PING_MS;
17581763 // block the run() loop
17591764 while (throttleLoops > 0 ) {
1760- delay (pingDelayMs );
1765+ delay (WS_DEVICE_PING_MS );
17611766 WS.feedWDT ();
17621767 WS._mqtt ->ping ();
17631768 throttleLoops--;
0 commit comments