Initialization - oihanagarciaa/GBL-IoTMonitoringSTREL Wiki

Setting up the middleware

In the beginning, the middleware setups just one service, the runner service.

These are the necessary properties that each service needs to start. The subscribers and the publishers work using MQTT connection. It shouldn't be difficult to implement new connection protocols.

Runner service

  1. Subscriber: Subscriber is a java class that extends the Subscriber interface
  2. ServiceBuilders map (Map<String, ServiceBuilder>): A map to add new service builders

Sensor service

  1. Subscriber: Subscriber is a java class that extends the Subscriber interface
  2. Sensor message class (Class extends CommonSensorsMessage>>): This class implements CommonSensorsMessage interface, it has to override these methods:
    int getId();
    double getTime();
    T getValue();
    This class is use to transform the JSON to a java class.

Moonlight service

  1. Formula
  2. Spatial Model
  3. Atomic Propositions
  4. Distance functions
  5. Buffer size
    The first four elements are used to initialize the Moonlight monitor.

Thingsboard service

  1. Broker: The broker to publish data to Thingsboard
  2. Topic: The topic to publish data to Thingsboard
  3. Device Access tokens (Map<String, String>): The key must be the ID to identify the sensor and the value is the access token of the device on Thingboard.

Client

The runner service expects a JSON file with a services list. This is an example with one service of each type:

{
	"services": [
		{
			"serviceId": "sensorService",
			"command": "start",
			"serviceType": "sensors",
			"connection": {
				"type": "mqtt",
				"settings": {
					"broker": "tcp://stefanschupp.de:1883",
					"topic": "institute/thingy/#",
					"username": "oihana",
					"password": "22oihana22"
				}
			}
		},
		{
			"serviceType": "moonlight",
			"serviceId": "moonlightService",
			"command": "stop",
			"formula": "import dsl.* \nval temp = \"temperature\" greaterThan 10 \nval humidity = \"humidity\" lessThan 10 \nval f1 = temp and (eventually(humidity) within interval(0, 1)) or somewhere(humidity) \nSpecification.formula = f1"
		},
		{
			"serviceId": "thingsboardService",
			"command": "start",
			"serviceType": "thingsboard",
			"connection": {
				"type": "mqtt",
				"settings": {
				"broker": "tcp://thingsboard.stefanschupp.de:1884",
				"topic": "v1/devices/me/telemetry"
				}
			},
			"devices": [
				{
					"identifier": "1",
					"accessKey": "v8iK9AKNXuRZNhIrzROu"
				},
				{
					"identifier": "2",
			    	        "accessKey": "q1qbXmY3KR51xhD24iHP"
			        }
		        ]
	        }
        ]
}

Settings

Settings.java

There are some properties that the client can't specify.

The information for the subscriber. With the information to get the client's commands

String SETTINGS_BROKER = "tcp://stefanschupp.de:1883";
String SETTINGS_TOPIC = "v1/board/runner";
String SETTINGS_USERNAME = "oihana";
String SETTINGS_PASSWORD = "22oihana22";

This is for the conversion from the sensors message to a java class. The sensor service requires it.

Class receivingMessage = OfficeSensorMessage.class;

The buffer size for the moonlight service.

Integer bufferSize = 6;

The spatial model is specified in the Settings for now. The client can't change it.

public static SpatialModel<Double> buildSpatialModel(int size){
        HashMap<Pair<Integer, Integer>, Double> cityMap = new HashMap<>();
        cityMap.put(new Pair<>(0, 1), 11.0);
        cityMap.put(new Pair<>(1, 0), 11.0);
        cityMap.put(new Pair<>(1, 2), 7.0);
        cityMap.put(new Pair<>(2, 1), 7.0);
        cityMap.put(new Pair<>(1, 3), 8.0);
        cityMap.put(new Pair<>(3, 1), 8.0);
        cityMap.put(new Pair<>(2, 3), 8.0);
        cityMap.put(new Pair<>(3, 2), 8.0);
        return Utils.createSpatialModel(size, cityMap);
    }
⚠️ **GitHub.com Fallback** ⚠️