Skip to main content

imp.getcountry()

Returns the imp’s specified WiFi regulatory territory

Availability

Device

Returns

String — the imp’s set region

Description

This method tells you which geographical region the imp has been set to operate within.

An imp’s specified region primarily affects the number of channels within the 2.4GHz band that it is permitted to use by the region’s regulatory bodies. In the US, the device is limited to channels 1 through 11; elsewhere, this range is extended to channels 12 and 13.

As such, imp.getcountry() will return one of the following values:

  • "00005355" — US/Canada, may be returned by any imp
  • "00004247" — The rest of the world, may be returned by any imp
  • "00005A58" — Global, returned only by an imp005 running impOS™ 34 or up when connected by WiFi
  • "00235A58" — Global, returned only by an imp005 running impOS 34 or up when connected by Ethernet
  • "03B64143" — Canada, returned only by an imp005 running impOS 34 or up when connected by Ethernet
  • "037F3045" — Europe, returned only by an imp005 running impOS 34 or up when connected by Ethernet

Note Though imp.getcountry() returns region codes as strings, the regions are set by passing numeric constants into imp.setcountry(). You should also note that, for the imp005, there are two possible strings that may be returned by imp.getcountry() even though only a single numeric constant, 0x235A58, is used to select the global region.

Module-specific Information

Cellular-only imps: impC001, imp006c

imp.getcountry() is not available in any impOS version on imps that do not support WiFi, specifically the impC001 and imp006c. If your code spans devices that provide WiFi and devices that don't, you can either wrap the call to imp.getcountry() in a try... catch block; check the prefix of the device's ID (see the imp006 design guide for details); or test for the availability of the method: if ("getcountry" in imp) { ... }.

Example Code

The following function can be used to identify the number of WiFi channels a device is able to utilize. You might use this information to provide, for example, debugging data to the device’s user through your mobile app. If the imp has been set to the US region, you can warn the user to make sure their WiFi router is not set to make use of channels 12 and 13. Many modern routers will automatically choose the least busy channel; if that is 12 or 13, this can prevent a device limited to channels 1 to 11 from connecting.