by awarns | v1.0.1
AwarNS Framework package that gives access to the current battery level
npm i --save @awarns/battery


npm (scoped) npm

This framework module includes a task that allows to access phone's battery level on demand.

Install the plugin using the following command line instruction:

ns plugin add @awarns/battery


After installing and setting up this plugin, you'll have access to a task that allows to acquire the current phone's battery level and the BatteryLevel record that it will output on demand.


Task name Description
acquirePhoneBatteryLevel Acquires phone's current battery level

Acquire phone's battery level

To register this task for its use, you just need to import it and call its generator function inside your application's task list:

import { Task } from '@awarns/core/tasks';
import { acquireBatteryLevelTask } from '@awarns/battery';

export const demoTasks: Array<Task> = [
// ... other tasks
// ...

Task generator parameters:

The task generator takes no parameters.

Task output events:

Example usage in the application task graph:

on('startEvent', run('acquirePhoneBatteryLevel')
.every(1, 'minutes')

on('batteryLevelAcquired', run('writeRecords'))

Note: To use the writeRecords task, the persistence package must be installed and configured. See persistence package docs.


Name Payload Description
batteryLevelAcquired BatteryLevel Indicates that a new battery level snapshot (record) has been acquired



Property Type Description
id string Record's unique id
type string Always battery-level
change Change Always none. Never starts or ends, always exists
timestamp Date The local time when the battery level was acquired
value number The battery level. Always an integer. Ranges from 0 to 100


Apache License Version 2.0