Skip to main content

imp.net.info()

Returns comprehensive imp network details

Availability

Device (from impOS™ 34)

Returns

Table containing the network configuration information (see below)

Description

This method returns a table populated with the imp’s stored network information. The table contains a number of keys some of whose values are themselves tables of data. Only relevant tables are returned. For example, if the method is called on an imp001, imp002, imp003, imp004m or impC001, it will not contain an interface record for Ethernet — only the imp005 currently provides Ethernet support.

These are the top-level keys:

Key Type Notes
interface Array of tables One table per available interface, see below
active Integer The index in the interface array of the current active (connected to the server) interface. If the active key is not present, no interface is active
ipv4 Table Network configuration data for the active connection, see below. Note This entry is not present on the impC001
lasterror Integer The last network error code, see server.connect(). Not present if there was no error, ie. server is connected

Do not assume that the tables contained in the array interface will be ordered in any specific way. It is not guaranteed that, for example, the first entry in the array will always be the WiFi interface.

Note The presence of the active key in the table can be used as a proxy for server.isconnected(), ie. the following two snippets are functionally equivalent:

if (server.isconnected()) { ... }
if ("active" in imp.net.info()) { ... }

The top-level ipv4 table, where present (it is not included in the impC001, for example), contains the following keys:

ipv4 Key Type Notes
dhcpserver String The DHCP server’s IP address. Absent if the imp has a static IP address
address String The imp’s IP address, eg. "192.168.0.3"
netmask String The network’s mask eg. "255.255.255.0"
broadcast String The network router’s broadcast IP address eg. "192.168.0.255"
gateway String The network’s gateway IP address eg. "192.168.0.1"
dnsserver Array One or two DNS server addresses each in "www.xxx.yyy.zzz" form
proxy Table A proxy server’s details (see below). Absent if a proxy has never been set with imp.setproxy()
server Table The imp server’s connection details (see below)

The ipv4 table’s proxy key’s value is a table with the following keys:

proxy Key Type Notes
type Integer The proxy type (see imp.setproxy())
address String The proxy’s IP address, eg. "192.168.0.2"
port Integer The proxy’s port, eg. 80
user String The proxy username, when configured

The ipv4 table’s server key’s value is a table with the following keys:

server Key Type Notes
port Integer The server’s port, eg. 31314
errorpolicy Integer SUSPEND_ON_ERROR (0) or RETURN_ON_ERROR (1)
tcpwaitfor Integer WAIT_TIL_SENT (0) or WAIT_FOR_ACK (1)
tcptimeout Float Timeout in seconds
tcpsendwindow Integer TCP window size in bytes

The top-level interface array (above) contains type-specific tables. For WiFi interfaces:

interface Key Type Notes
type String "wifi"
macaddress String The imp’s WiFi MAC address
bands String The imp’s supported WiFi bands, ie. "2.4G", "5G" or "2.4G,5G". For multi-band imps, this is not the band actually in use
country String The regulatory region code (see imp.getcountry())
powersave Bool Whether Powersave mode is active (see imp.getpowersave())
channel Integer The WiFi channel in use (see imp.getchannel())
rssi Integer The signal strength at the time of the request. Only present when WiFi is up
ssid String The network SSID
connectedssid String The SSID of the network to which the imp is actually connected. Only present when WiFi is up (from impOS 36)
bssid String The router’s BSSID. Only present when WiFi is up
encryption String The encryption type, eg. "WPA2-PSK (AES)". Only present after first association. This parameter does not provide the network password

For Ethernet interfaces (imp005 only):

interface Key Type Notes
type String "ethernet"
macaddress String The imp’s Ethernet MAC address. This is not the WiFi address returned by imp.getmacaddress()
link String "10M" or "100M". Only present when link detected
duplex String "half" or "full". Only present when link detected

For cellular interfaces (impC001 only):

Key Type Notes
type String "cell"
manufacturer String The modem manufacturer, eg. "Cinterion"
model String The modem model number, eg. "ELS61-E"
imei String The imp’s International Mobile Equipment Identity number
imsi String The imp’s International Mobile Subscriber Identity number
swver String Modem software revision, eg. "REVISION 01.000"

In addition, the interface table will contain the following state-specific keys:

Key Type imp State When Data Available Notes
voltage Integer Connecting, Connected Modem voltage in mV, eg. 3807
rssi Integer Connected The signal strength, eg. -78
cellinfo String Connected Cellular connection information, eg. "4G,6300,20,10,10,FDD,262,02,BF75,0345103,350,90,-94,-7,CONN"

For more information on the data contained in the cellinfo string, which varies according to the connected network type (2G, 3G, 4G etc), please see Cinterion ELS61-E AT Command Set, section 8.11.2.

Known Issue

Under impOS 36, the Ethernet interface is not present in net.info() output when the Ethernet is not powered up. Ethernet is not powered up when the imp005 is disconnected.

Expected Fix This issue is scheduled to be addressed in a future impOS release.

Example Code

The following example shows a simple use of net.info(): to log what network interfaces an imp has available and which one, if any, it is connected to.