Check Device Connection Status Via Scripting

One way: system.device.listDevices()

Another path:

[System]Gateway/Devices/DeviceName/Status

Third way (and best, IMO): use a heartbeat.