This repository contains the material needed to build and run the Software Sensor for the 2016 Red Hat Summit IoT Lab
This module simulates a physical sensor. Defined by a few environment variables this sensor creates random values and sends these to a MQTT Broker for further processing.
The way the sensor creates the random data is rather simple and can be described with the following steps
-
Start with an initial value, which is defined via an environment variable
-
Create a random number between 0 and 1000
-
If the random number is lower then a defined threshold, reduce the 'measured' value by '1'
-
if the random number is higher then a defined threshold, increase the 'measured' value by '1'
-
Send updated 'measured' value to defined MQ TT Broker
-
Wait 1 second
-
re-start at step 3. until a defined count has been reached
MQTT is a lightweight protocol, which works via a Publish / Subscribe mechanism. In the case of this IoT setup, the Software Sensor acts like a 'Publisher' sending out data to anyone who is interested ( 'subscribed' ). For the 'Publisher' and 'Subscriber' to be able to "find" each other, both sides need to work with an identifier. In other words, the 'Publisher' publishes his data via a 'Topic' to which the 'Subscriber' subscribes. If there are more then one 'Subscriber' subscribing to the same 'Topic' then all of them will get the same message. We are talking about a 1:n ( one to many ) communication.
In our IoT senario the 'Topic' is
iotdemo/<deviceType>/<deviceID>with '<deviceType>' and '<deviceID>' being the unique identifier of each sensor.
The data being send from 'Publisher' to 'Subscriber' from hereon call the 'payload' is very simple
<measured data>, <counter>with '<measured data>' being the randomly created data and '<counter>' being a sequential count of the message itself. At this point in time, we can ignore the '<counter>', as we will not validate him.
The Software Sensor can be configured via the following environment variables
| Variable | Description | Default Value |
|---|---|---|
deviceType |
The type of sensor this software should simulate. This is only required to differentiate the sensors from each other, if you should run multiple ones. |
temperature |
deviceID |
The unique ID of this sensor. The combination of 'deviceType' and the 'deviceID' should be unique. |
1 |
initialValue |
The starting value |
70 |
count |
The number of messages this sensor is supposed to create. |
1 |
receiverURL |
URL of the host running the MQTT Broker to which the sensor shall deliver the created data. |
localhost |
brokerUID |
The username to connect to the remote MQTT Broker. |
admin |
brokerPassword |
The password to connect to the remote MQTT Broker |
change12_me |
highWater |
The threshold to increase the generated value with '1' |
800 |
lowWater |
The threshold to decrease the generated value with '1' |
200 |
To be able to run the Software Sensor you will have to build it from it’s source files.
To do so, please open a terminal and perform the following commands
[demo-user@iotlab Desktop]$ cd [demo-user@iotlab ~]$ cd IoT_Summit_Lab/ [demo-user@iotlab IoT_Summit_Lab]$ cd Software_Sensor/ [demo-user@iotlab Software_Sensor]$ mvn clean install
Once the build procedure has completed, you are ready to proceed.
For your convenience we provided two simple script that you can use start the Software Sensor.
Note: Please be aware, that running them now will produce no visual results, as we still need to complete the other steps of this lab.
This script comes with the following environment variables
| Variable | Value |
|---|---|
deviceType |
temperature |
deviceID |
4711 |
initialValue |
20 |
count |
50 |
receiverURL |
localhost |
brokerUID |
admin |
brokerPassword |
change12_me |
highWater |
800 |
lowWater |
200 |