Skip to main content

imp.environment()

Returns information about the imp’s type

Availability

Device + Agent

Returns

Integer — the value of the imp’s environment constant

Description

This method returns information about what type of imp (card or module) the Squirrel code is executing on. It will also signal that the imp is a virtual one, ie. an agent. This is useful when writing portable code that might need to run in different places and know where it is being run.

The return value is one of the constants below:

Constant Value Type imps
ENVIRONMENT_CARD 0 Card imp001
ENVIRONMENT_MODULE 1 Module imp002, imp003, imp004m, imp005, impC001
ENVIRONMENT_AGENT 2 Agent N/A

The values assigned to the constants may change in a future impOS™ release.

From impOS 36, you can call imp.info() to determine exactly specific imp type your code is running on and thus the availability of certain peripheral buses and GPIO pin names. Prior to impOS 36, imp type identification is only possible by checking for the presence of certain pin and/or bus objects in the hardware object:

local eType = imp.environment();
if (eType == ENVIRONMENT_CARD) {
    // Running on an imp001
} else if (eType == ENVIRONMENT_MODULE) {
    // Running on an imp module: but which one?
    if ("spi0" in hardware) {
        // Running on an imp005
    } else if ("pinY" in hardware) {
        // Running on an imp003
    } else {
        // Running on an imp004m
    }
} else {
    // Running as an agent
}