Skip to main content

server.isconnected()

Indicates to the imp whether or not it is currently connected to the server

Availability

Device

Returns

Bool — true if the device is connected to the server, or false otherwise

Description

This method is typically used when the imp is operating on a RETURN_ON_ERROR disconnection policy in order to check whether the device is currently connected. If it is not, the code will first need to call server.connect before it can interact with the server and its agent.

To be connected, the device’s current network interface (WiFi, Ethernet or cellular) must be enabled and a TCP socket established with the impCloud™ server.

If the device receives no network traffic from the server for a period of around 60 seconds, it will try to elicit a response from the server (a ‘keepalive’). Calls to server.isconnected() will continue to return true during this period. If no acknowledgement is forthcoming within approximately 45 seconds, the device will close the socket and record the server as being unavailable, and server.isconnected() will return false.

Example Code

This example will tell the user whether or not the device is currently connected to the server when a button is pressed. If the device is connected, a green LED will come on. If the device is disconnected, a red LED will light.