0.0.7 • Published 9 months ago

iot-device-sim v0.0.7

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

IoT Device Simulator

Basic Usage:

Define Parameters (variables) to be simulated:

const battery_voltage : NumberParameter = {
    id: 'battery_voltage',
    name: 'Battery Voltage',
    unit: 'V',
    value: [0, 4.0]
}

const temperature: NumberParameter = {
    id: 'temperature',
    name: 'Temperature',
    unit: '°C',
    value: [0, 20.0]
}

Define simulation generator functions for a certain parameter:

const battery_discharge = new GenerateLinearFunction(4.2, 3.0, 60_000, 0.02);

Attach the generator to a Parameter using a Simulator<T>:

const battery_sim = new Simulator<number>(battery_voltage, battery_discharge);

Create the controller object and attach all simulators:

const controller = new SimulationController();
controller.addSimulator(battery_sim);

Accessing Values

Per default, it is possible to access simulation values by:

  • listening on an EventEmitter
  • calling a function to return all or certain values

Event listening

It is possible to listen for values automatically by using the listenData or listenAllData functions, which will output either one specified parameter value or all of them, respectively.

// listens for only the 'battery_voltage' parameter
controller.listenData('battery_voltage', (data: [number, number][]) => {
        console.log('Voltage:', data);
    });

// returns the current values for all parameters
controller.listenAllData((data: [number, number][]) => {
    console.log(data)
})

Returning through API

Alternatively, parameter values can be accessed by receiving them manually from the controller. It is possible to access current values from the a single or from every parameter.

// receives all parameter values
let data = controller.getAllData();

// returns only the value for the battery_voltage parameter.
let battery = controller.getData('battery_voltage')
0.0.7

9 months ago

0.0.5

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago