Description

This library provides two methods of data generation:

Polling

generated data are returned to the user by calling the requestData(params) method on Device. This allows the user to get data on demand with custom parameters. The number and types of parameters for this method depends mostly on the DataFeed implementation provided for the Device.

Wrapping Device with ActiveDevice

In this case the requestData() method is called periodically by ActiveDevice and it can be used as a standalone device.

For data manipulation, the user is advised to perform the following additional steps:

  1. Configure a NetworkAdapter to enable data handling. (This is done the same way as in real-life applications.) This way data can be sent to valid endpoint using the REST protocol.

  2. For testing purposes, it is recommended to create an Observer. Using the Observer pattern, the user is able to catch important information from the data creation process without using debugging tools or viewing log messages. For information on deploying

Users can utilize three main data generators types:

Sensor

interface adds possibility to define List of DataFeed to Device. This provides possibility to simulate data generation for multiple data sources. For example commonly known DHT11 temperature-humidity sensor is working with two values simultaneously. This requires possibility to define multiple DataFeeds for one device.

SimpleSensor

extends Sensor and restrict its functionality to use only one DataFeed as it is convenient to sometimes utilize sensor that is monitoring only one value.

Actuator

different type of Device than Sensor. Offers methods to simulate real life behaviour of actuators. Important part of this concept is StateMachine.class which holds information about current state and time duration, that is needed for actuator to finish simulated action. Handles any transitions between states if necessary.

The library provides few preconfigured devices that are ready for use. The idea behind them is to simplify the creation process for the user in case he wants to create commonly known devices but to offer him freedom in configuring his own.

Sensors:

  • Default

  • Hygrometer

  • Thermometer

  • DHT11

Actuators:

  • LinearActuator

  • RotaryActuator

Functionality

The packages currently offered are the following:

DataFeed

tool to provide data streams to different components (e.g. time simulation, simulated devices). This interface is ready for further user customization, as it is not possible to define all situations that could be needed in the future. So far the library provides examples, that can be divided into three parts: SSJ (Stochastic Simulation in Java) - Java library providing a tool for stochastic data simulation developed at Université de Montréal (https://www.iro.umontreal.ca/~lecuyer/ssj-gh-pages/html/index.html) Expression approach, where a user defines an expression (function) which solutions represents expected data stream “Logic” driven approach. A user is fully capable to customize data generating class as long as it implements DataFeed interface

Device

(Sensor, SingleSensor, Actuator) back and bone of library, brings parts of the library together. Gives meaning for generated data which are acquired from individual data feeds. Holds information like UUID, label, and description.

ActiveDevice

provides the possibility to simulate Device in time. Time intervals are determined with data feed like with device. Classes create an environment for a device where asynchronous tasks poll data from it. This is way how to simulate real, standalone devices (it is needed to configure NetworkAdapter for time simulated device, for it to be able to send data with a specific protocol to right destination)

DataObservable

simple Observer Pattern, designed for observing Device whenever it produces new data. This is important mostly because time simulation polls data automatically, therefore users ability to retrieve a generated value from the device is denied. Observer fills this gap by providing the tool for catching and reacting for a data creation event.

Usage

User needs to create new class that implements Observer.[1]. The device holds a list of Observables that will be notified as soon as new data are generated. This list is updated by registering the device to DataObservable class. As documented in Observer Pattern, for receiving notifications register our new Observer class to data observable by addObserver(observer)

DataWrapper

provides tools that allow to wrap data to common structures like JSON, XML e.t.c.

NetworkAdapter

provides classes when used with device allows the user to send data to the destination. All he needs is to select the desired protocol, REST, MQTT or design his own by implementing the NetworkAdapter interface and generated data will be delivered to right receiver.

Simple example - device with data on pooling

A base for our device is properly configured data feed. For this example

DataFeed dataFeed = new NormalDistributionDataFeed(18, 3);

Create Device with DataFeed. In this case, simple Sensor will be enough.

SimpleSensor device = new Thermometer("ThermometerExample", dataFeed);

Get generated data

device.requestData()

Simple example - device with data on pooling

The first example is nice, but it returns “random” value from definition scope of normal distribution. As in the first example we need data feed and device

DataFeed dataFeed = new NormalDistributionDataFeed(18, 3);
SimpleSensor device = new Thermometer("ThermometerExample", dataFeed);

Active Device example

Now, we know how to set up a simple device. Define device as we did in previous examples In order to simulate device in time - to be able to send data periodically in set intervals, we need to wrap it with running environment called time simulation Like device, ActiveDevice also needs some data feed to be able to determinate mentioned time intervals

DataFeed timeFeed = new LinearDataFeed(2000);

We create an instance of ActiveDevice to simulate our device in time.

ActiveDevice active = new ActiveDeviceImpl(timeFeed, device);

At this point, the device needs to configure. Finally, we start the simulation.

active.start();