Last active
September 10, 2018 14:48
-
-
Save ElectricImpSampleCode/0aa284ac1e40c954f0001ce089a47d14 to your computer and use it in GitHub Desktop.
Electric Imp imp API device.info() example code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local address = ""; | |
function checkIP() { | |
local connectionData = device.info(); | |
if (connectionData.isconnected) { | |
server.log(format("Device %s is connected", connectionData.id); | |
if (address.len() == 0) { | |
server.log(format("Device %s has connected with IP address %s", connectionData.id, connectionData.ipaddress)); | |
} else if (connectionData.ipaddress != address) | |
server.log(format("Device %s has connected and changed IP address from %s to %s", connectionData.id, address, connectionData.ipaddress)); | |
} | |
address = connectionData.ipaddress; | |
} else { | |
server.log(format("Device %s is not connected", connectionData.id); | |
} | |
} | |
device.onconnect(checkip); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment