Skip to content

Instantly share code, notes, and snippets.

@ElectricImpSampleCode
Last active April 19, 2024 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ElectricImpSampleCode/1ca881b1bd75f2378ae8 to your computer and use it in GitHub Desktop.
Save ElectricImpSampleCode/1ca881b1bd75f2378ae8 to your computer and use it in GitHub Desktop.
Electric Imp imp API imp.net.info() example
local netData = imp.net.info();
if ("active" in netData) {
local type = netData.interface[netData.active].type;
// We have an active network connection - what type is it?
if (type == "cell") {
// The imp is on a cellular connection
local imei = netData.interface[netData.active].imei;
server.log("The imp has IMEI " + imei + " and is connected via cellular");
} else {
// The imp is connected by WiFi or Ethernet
if ("address" in netData.ipv4) {
local ip = netData.ipv4.address;
server.log("The imp has IP address " + ip + " and is connected via " + type);
} else {
server.error("The imp does not have an IP address");
}
}
if (netData.interface.len() > 1) {
// The imp has more than one possible network interface
// so note the second (disconnected) one
local altType = netData.active == 0 ? netData.interface[1].type : netData.interface[0].type;
server.log("(It can also connect via " + altType + ")");
}
} else {
server.log("The imp is not connected");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment