Skip to main content

imp.net.getcurrentconfig()

Return the current Network Interface Configuration

Availability

Device (from impOS™ 42)

Returns

Table — a Network Interface Configuration

Description

This is draft documentation which covers impOS™ functionality that, though currently in internal development, has been made available to a number of customers for testing purposes only. Both the functionality described here and the documentation itself are subject to change, including breaking changes, and may differ significantly from their final release versions.


This method returns the Network Interface Configuration (NIC) through which the imp is currently connected to a server in the Electric Imp impCloud™.

A NIC is a table whose structure is described in server.connectwith(). As such, it can be passed in to that method should it be necessary to reconnect to the impCloud using the same interface.

When a device successfully establishes a connection to the server following a call to server.connectwith() — which can be detected through server.connectwith()’s callback function — or after the imp has had its network parameters set using BlinkUp™, the NIC returned by imp.net.getcurrentconfig() can be saved to persistent storage.

You should note that if an attempt to connect with a new NIC fails, imp.net.getcurrentconfig() will not return that NIC but rather the one that through which the imp was previously connected, even if the imp is no longer connected to the server.

Certain parameters in the returned NIC such as the wireless network key and proxy server password, if included, are encrypted with a per-device key for security purposes. Consequently, if you intend to save a NIC in persistent storage for later re-use, you should save the version retrieved using imp.net.getcurrentconfig() not the plain text NIC that was passed into server.connectwith() to initiate a connection.

Example

This simple example reads the current NIC on a WiFi-enabled imp and relays the stored wireless network configuration. Notice that the type of the variable value is checked to prevent server.log() outputting a list of hex values in place of a more useful message.

local nic = imp.net.getcurrentconfig();
server.log("NIC: \"" + nic.interface + "\"");
foreach (name, config in nic) {
    if (name == "interface") continue;
    foreach (key, value in config) {
        server.log(key + ": " + (typeof value == "string" ? value : ("raw data of length " + value.len() + " bytes")));
    }
}