Allows a static network configuration to be applied to the device
Device (from impOS™ 33)
The desired static IPv4 address, eg.
The network’s IPv4 address mask, eg.
The network gateway’s IPv4 address, eg.
|DNS||Array of strings||
An array of one or two strings, each the IPv4 address of a DNS server
This method can be used to provide a device with a fixed IPv4 address and network configuration settings, including the addresses of a number of DNS servers.
These settings are stored within the device and applied on the next connection attempt.
You should note that settings applied using imp.setstaticnetworkconfiguration() should be chosen with care and a full understanding of the architecture of the target network. If the settings are not selected carefully, it is possible that the device may not be able to communicate with the network, for instance if it is pre-set with an IP address that has already been assigned (statically or via DHCP) to another device on the target network, or the netmask, gateway address or DNS entries are not correct for the network.
The IP, netmask and gateway settings should be passed as a string of the form
w.x.y.z where w, x, y and z are one- to three-digit decimal values between 0 and 255 (dotted quads). The DNS parameter is an array of one or two strings of this type. All of the parameters are mandatory, ie. you must provide at least one DNS server address.
The method does not return success or failure information; instead, a runtime error will be thrown if any of the address strings are malformed, or fewer than one or more than two DNS server addresses are included.
A device without static network settings will obtain these values by DHCP. To reset a device with static network settings to dynamic ones, call:
The new settings will be applied whenever the device next connects to the server. If it is already connected when the settings change, it will need to disconnect first for the settings to be applied at a subsequent connection:
imp.clearconfiguration(CONFIG_STATIC_NETWORK); server.disconnect(); server.connect();
The following example shows a simple use of imp.setstaticnetworkconfiguration(). As soon as the device starts running Squirrel, we disconnect from the existing connection, set its static IP address and network settings, and then attempt to reconnect. Of course, in a real-world setting, we might register the setting of the static configuration as a flag which can be persisted and then checked at start-up: if the flag is
true, there’s no need to disconnect and re-apply the static setting.