Skip to main content

imp.setproxy(proxyType, address, port, username, password)

Configures the imp for Internet access through a proxy server

Availability

Device (from impOS™ 33)

Parameters

Name Type Description
proxyType Constant Currently must be PROXY_TYPE_HTTP
address String The proxy server address in dotted quad or a resolvable form,
eg. "192.168.0.128" or "proxy.electricimp.com". Up to 64 characters in length
port Integer Port number between 0 and 65535
username String Optional, the server login username. Up to 32 characters in length
password String The server login password, only required when the username parameter is used.
Up to 32 characters in length

Returns

Nothing

Description

This method allows the imp to be configured to access the Internet through a proxy server which is specified using the method’s parameters. Settings are applied on the next connection attempt, ie. if the device is already connected when this method is called, the proxy settings will not be used until the device has first disconnected (by entering deep sleep, by being power-cycled, or manually in code).

The proxy’s address and port must be supplied; if they are not, or are incorrectly specified, an error will be thrown. The first parameter, proxyType is also mandatory but is currently limited to a single option: the constant PROXY_TYPE_HTTP.

Proxies that require username and password logins are supported through the method’s remaining, optional parameters. Though these are optional, if a value is passed into username, a corresponding value must be passed into password, or an error will be thrown.

To clear proxy settings from an imp, call imp.clearconfiguration(). To avoid also clearing the imp’s stored WiFi credentials, make sure you pass the constant CONFIG_PROXY into imp.clearconfiguration(). This will clear an imp’s proxy settings, if any have been applied, but leave other network settings untouched:

// Clear imp's proxy server settings ONLY
imp.clearconfiguration(CONFIG_PROXY);

Example Code

The following example shows a simple use of imp.setproxy(): to hard-code proxy connection information at runtime, to disconnect from an existing network then connect to the proxy. Of course, in a real-world setting, we might register the setting of the proxy 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.