Skip to content

Sensors Simulator

Ron Gatenio edited this page Jul 3, 2017 · 6 revisions

Table of Content


Configuring a Simulator

The SensorsSimulator is an object managing all the simulated sensors you've created.

  • use addSensor method to add a senor to the simulator.
  • use addSentMsgLogger and addInstructionReceivedLogger to set uniform loggers to all simulated sensors
  • use setGeneralStreamingInteval to set a uniform streaming rate for all sensors
  • use startSendingMsgsInAllSensors to initiate sending messages on all sensors
  • use stopSendingMsgsInAllSensors to terminate the current streaming of messages on all sensors

Creating a sensor

Sensors cannot be created directly, but through the class SensorBuilder which allows setting all required properties: id, mac, alias, information paths, instruction paths, message. All the properties can be set through the builder's setter methods.

Notice that the builder API is fluent, so consuctive calls to setter can be concated as follows:

new SensorBuilder().setAlias("my sensor")
                    .setCommname("iShowerBoiler")
                    .addInfoSendingPath("boiler.temperature", Double.class)
                    .addInfoSendingPath("boiler.isOn", Boolean.class)
                    .addInfoSendingPath("boiler.time", Integer.class)
                    .addInstructionsReceiveingPath("boiler.set.temperature");

NB a path in which a sensor sends data is deifined with a path as well as class. The classes supported are: Integer.class, Double.class, Boolean.class, String.class

In order to create a sensor instance from a builder, call the build method: GenericSensor s = builder.build();

Defining messages

messages can be defined through the builder in the methods:

public SensorBuilder addStreamingRange(String path, List values);
public SensorBuilder setMessageSupplier(Supplier<Map<String, Object>> msgsGenerator);
addStreamingRange

Set a legal range for a single path. When streaming is initialized the sensor will generate a message who's values are within the given ranges and send to the system. This is usful for stress testing for example. Ranges are defined according to the class the path was registered to:

  • Integer.class, Double.class - expect a list of size 2, containing a lower bound (inclusive) and a higher bound (exclusive)
  • Boolean.class - list of legal values, contains in the following list: Arrays.asList(true,false)
  • String.class - list of legal values
setMessageSupplier

the supplier receives a supplier method that generates a map of legal values each times it is called. This gives the developer a full freedom in message generation. e.g. - a vitals simulated sensor could generate legal heart beat pattern.

Launching App in Developer Mode with a Simulator

Use the following main:

public static void main(String[] args) throws Exception {
    launch(simulator, shouldOpenGui);
}

Rememeber to set shouldOpenGui value to true if you would like to load the simulator GUI as well, and false otherwise.

The GUI can help you with testing and debugging, since it includes consoles showing messages sent from the simulated sensors, and messages received from sensors (separately). For extensive GUI description look here.

Clone this wiki locally