Skip to content

Instantly share code, notes, and snippets.

@ElectricImpSampleCode
Last active September 10, 2018 14:48
Show Gist options
  • Save ElectricImpSampleCode/0aa284ac1e40c954f0001ce089a47d14 to your computer and use it in GitHub Desktop.
Save ElectricImpSampleCode/0aa284ac1e40c954f0001ce089a47d14 to your computer and use it in GitHub Desktop.
Electric Imp imp API device.info() example code
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