StartSleep Method

Enter sleep state for the specified duration.

Syntax

public void startSleep(int duration);

Remarks

When this method is called, the gateway will buffer all incoming messages for the client until the next time it awakes. To receive all currently buffered messages, call StopSleep or FetchMessages.

While in the sleep state, the client no longer must abide by the KeepAliveInterval, but must awake before the end of the sleep duration. If it does not send the gateway any messages in this interval, it will be considered lost and will disconnect.

If FetchMessages is called, the client will return to sleep after receiving the messages and the sleep timer will restart. If StopSleep is called, the client will enter the active state.

Sleep Examples

mqttsn1.StartSleep(8); // sleep for 8 seconds
// ... wait for 5 seconds
mqttsn1.FetchMessages(); // MessageIn will fire for each message buffered during that time
// ... wait for 5 more seconds (ok because <8 seconds since last packet sent)
mqttsn1.StopSleep();

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks IoT 2020 Java Edition - Version 20.0 [Build 8265]