Understand impOS’ Mechanism of APN setting
impOS has long supported cellular communication but was limited to a predefined set of networks. By default, impOS selects an APN for the cellular modem from an internal list, based on the ICCID/IMSI prefix of the SIM card. Historically, this has meant that impOS was unable to support all private cellular networks (due to ICCID/IMSI conflicts) or an exhaustive set of third-party SIMs. if a customer wanted to use a private SIM with impOS, they had to submit a request and wait for a new impOS release, as there was no option to set a custom APN via Squirrel.
Release 47 introduces the ability to read, write and clear a custom APN; both from squirrel code and via BlinkUp™. When set, a custom APN overrides the internal list and persists through resets and power cycles until explicitly cleared. This frees customers to configure their fleet for a wider set of use cases (e.g. private cellular networks, cellular test equipment) without being dependent on impOS firmware release cadence, flash space constraints, or conflicts with needs of other customers.
Care is needed when changing the APN settings, because misconfiguration can result in devices being unable to make any further cellular connections. In this case, recovery may require either Wi-Fi (to send new squirrel) or physical access (for BlinkUp™).
The server.factoryblinkup() method now accepts an optional fifth parameter, which if present must be a squirrel string representing the custom APN, of between 1 and 63 characters. When a valid APN is provided by the factory squirrel code, the custom APN will be transmitted to the production device via BlinkUp™ during enrollment. A custom APN is persistently stored in internal flash and used for all subsequent cellular connections, until explicitly cleared. No APN settings are changed if the optional fifth parameter is omitted. A squirrel error is thrown if the optional fifth parameter is present but not a string. Both the factory device and production device must be running impOS release-47.0+.
Electric Imp's BlinkUp™ App version 4.7.0, now available on the Play Store, introduces a new feature allowing users to configure a custom APN for cellular connections, with the option to leave the field blank to use the default APN . Note: This app is intended for use with development devices only. For production devices, customers must create their own BlinkUp app using the Android BlinkUp™ SDK. Android SDK for BlinkUp™ Version 6.5.0 will support sending the APN_OVERRIDE BlinkUp™ packet. Refer to the GitHub repository for latest BlinkUp™ SDK.
When a device has its settings cleared via a mobile application’s CLEAR A DEVICE’S SETTINGS option, any custom APN will additionally be cleared. This also applies to any customer mobile app that uses the BlinkUp™ SDK to send a CLEAR_WIRELESS_CONFIG packet. This works for existing mobile apps, they do not need to be rebuilt with a new SDK. The device must be running release-47.0+.
The new imp.setapn(string) method can be used to set a custom APN via squirrel. A custom APN is persistently stored in internal flash and used for all subsequent cellular connections, until explicitly cleared. A squirrel error is thrown if the single parameter is missing or not a string. The device must be running release-47.0+.
The imp.clearconfiguration() method clears any existing custom APN from persistent storage. Any subsequent cellular connection attempts will revert to using the internal list based on ICCID/IMSI prefix of the SIM card. The method can either be called with no parameters, to clear all configuration settings including custom APN, or the new parameter CONFIG_APN (integer value 4) can be provided to clear only the custom APN setting. The device must be running release-47.0+. Factories that currently use imp.clearconfiguration() to clear temporary wifi settings should update their squirrel code to call imp.clearconfiguration(CONFIG_WIFI) to preserve custom APN settings.
The cellular interface table returned by imp.net.info() now includes a new element with key apn. The associated value is a squirrel string equal to the last APN sent to the modem. This also works for internally selected APNs. Note that the APN value returned relates to the current or last cellular connection attempt and will not reflect any changes made via squirrel or BlinkUp™ until the next reconnection. The device must be running release-47.0+.
Users now have the ability to test a custom APN before saving it to the imp's persistent store, preventing it from being locked due to an invalid APN. They can use the server.connectwith() API to test the custom APN and establish a connection. Once confirmed, they can then use imp.setapn() to write the APN into the device’s persistent store.
if (hardware.wakereason() == WAKEREASON_NEW_SQUIRREL) {
server.setsendtimeoutpolicy(RETURN_ON_ERROR, WAIT_FOR_ACK);
local nic = { "interface" : "cell0",
"cellconfig" : {"apn":"customapn"}};
server.connectwith(nic,function(result, interface) {
if (result == SERVER_CONNECTED) {
local netData = imp.net.info();
server.log("Active interface : " + netData.interface[netData.active].type)
server.log("Apn key value : " + netData.interface[netData.active].apn);
if (netData.interface[netData.active].apn == nic.cellconfig.apn){
// Persist the Cellular apn config across future reboots
imp.setapn(nic.cellconfig.apn);
}
}
});
}