Skip to content

Forked from redhat-iot/Virtual_IoT_Gateway then took apart Software_Sensor

Notifications You must be signed in to change notification settings

alezzandro/iotgw_Software_Sensor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

IoT Summit Lab 2016 - Software Sensor

Content

This repository contains the material needed to build and run the Software Sensor for the 2016 Red Hat Summit IoT Lab

What does this Module do?

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.

How data is simulated

The way the sensor creates the random data is rather simple and can be described with the following steps

  1. Start with an initial value, which is defined via an environment variable

  2. Create a random number between 0 and 1000

  3. If the random number is lower then a defined threshold, reduce the 'measured' value by '1'

  4. if the random number is higher then a defined threshold, increase the 'measured' value by '1'

  5. Send updated 'measured' value to defined MQ TT Broker

  6. Wait 1 second

  7. re-start at step 3. until a defined count has been reached

How date is transmitted to MQTT

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.

Configuration

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

Building the Software Sensor

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.

Running the Software Sensor

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.

runSensor.sh

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

runHighSensor.sh

This script comes with the following environment variables

Variable Value

deviceType

temperature

deviceID

4711

initialValue

70

count

1

receiverURL

localhost

brokerUID

admin

brokerPassword

change12_me

highWater

800

lowWater

200

About

Forked from redhat-iot/Virtual_IoT_Gateway then took apart Software_Sensor

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages