System Commands

restart()

deepSleep()

The restart function reboots the device.

The deepSleep schedules the system to enter deep sleep.

getRunlevel()

Example:

function setup() {
  // Check if we are running on internal battery
  if (getRunlevel() == 2) {
    print("Running on battery");
  } else {
    print("Running on power supply");
  }
}

Returns the current system run-level. This can be one of:

LevelAliasDescription
0x00RUNLEVEL_BOOTEarly boot sequence.
0x01RUNLEVEL_EXT_POWERThe device is externally powered.
0x02RUNLEVEL_BAT_POWERThe device is powered by the internal battery.
0xFERUNLEVEL_RESTARTRestart system.
0xFFRUNLEVEL_SHUTDOWNShut down system (eg. deep sleep)

setRunlevel(level)

Example:

function restart() {
  // Switch system to restart runlevel
  setRunlevel(0xfe);
}

This function changes the system runlevel to the given number. This function is intended to be used in cases where you have implemented custom run-levels that you want to use.