StartSleep Method

Enter sleep state for the specified duration.

Syntax

ANSI (Cross Platform)
int StartSleep(int iDuration);

Unicode (Windows)
INT StartSleep(INT iDuration);
- (void)startSleep:(int)duration;
#define MID_MQTTSN_STARTSLEEP 14

IPWORKSIOT_EXTERNAL int IPWORKSIOT_CALL IPWorksIoT_MQTTSN_Do(void *lpObj, int methid, int cparam, void *param[], int cbparam[], int64 *lpllVal);

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();

Error Handling (C++)

This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)

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