Skip navigation links

Package org.apache.edgent.samples.apps.sensorAnalytics

The Sensor Analytics sample application demonstrates some common continuous sensor analytic application themes.

See: Description

Package org.apache.edgent.samples.apps.sensorAnalytics Description

The Sensor Analytics sample application demonstrates some common continuous sensor analytic application themes. See Sensor1 for the core of the analytics processing and SensorAnalyticsApplication for the main program.

The themes include:

Prerequisites:

The default configuration is for a local MQTT broker. A good resource is mosquitto.org if you want to download and setup your own MQTT broker. Or you can use some other broker available in your environment.

Alternatively, there are some public MQTT brokers available to experiment with. Their availability status isn't guaranteed. If you're unable to connect to the broker, it's likely that it isn't up or your firewalls don't allow you to connect. DO NOT PUBLISH ANYTHING SENSITIVE - anyone can be listing. A couple of public broker locations are noted in the application's properties file.

The default mqttDevice.topic.prefix value, used by default in generated MQTT topic values and MQTT clientId, contains the user's local login id. The SensorAnalytics sample application does not have any other sensitive information.

Edit <edgent-release>/java8/scripts/apps/sensorAnalytics/sensoranalytics.properties to change the broker location or topic prefix.

Application output:

The application periodically (every 30sec), publishes a list of the last 10 outliers to MQTT. When enabled, it also publishes full details of individual outliers as they occur. It also subscribes to MQTT topics for commands to dynamically change the threshold range and whether to publish individual outliers.

All MQTT configuration information, including topic patterns, are in the application.properties file.

The application logs outlier events in local files. The actual location is specified in the application.properties file.

The application generates some output on stdout and stderr. The information includes:

Sample console output:

 [1] MqttDevice serverURLs [tcp://localhost:1883]
 [2] MqttDevice clientId id/012345
 [3] MqttDevice deviceId 012345
 [4] MqttDevice event topic pattern id/012345/evt/+/fmt/json
 [5] MqttDevice command topic pattern id/012345/cmd/+/fmt/json
 [6] Edgent Console URL for the job: http://localhost:57324/console
 [7] sensor1.outside1hzMeanRange[124..129]: {"id":"sensor1","reading":{"N":1000,"MIN":0.0,"MAX":254.0,"MEAN":130.23200000000006,"STDDEV":75.5535473324351},"msec":1454623874408,"agg.begin.msec":1454623873410,"agg.count":1000,"AvgTrailingMean":128,"AvgTrailingMeanCnt":4}
 ...
 [8] ===== Changing range to [125..127] ======
 sensor1.outside1hzMeanRange[125..127]: {"id":"sensor1","reading":{"N":1000,"MIN":0.0,"MAX":254.0,"MEAN":129.00099999999978,"STDDEV":74.3076080870567},"msec":1454624142419,"agg.begin.msec":1454624141420,"agg.count":1000,"AvgTrailingMean":127,"AvgTrailingMeanCnt":30}
 [9] ===== Changing isPublish1hzOutsideRange to true ======
 ...
 

Running, observing and controlling the application:


 $ ./runSensorAnalytics.sh
 

To observe the locally logged outlier events:


 $ tail -f /tmp/SensorAnalytics/logs/.outside1hzMeanRange
 

To observe the events that are getting published to MQTT:


 $ ./runDeviceComms.sh watch
 

To change the outlier threshold setting:
The command value is the new range string: [<lowerBound>..<upperBound>].


 $ ./runDeviceComms.sh send sensor1.set1hzMeanRangeThreshold "[125..127]"
 

To change the "publish individual 1hz outliers" control:


 $ ./runDeviceComms.sh send sensor1.setPublish1hzOutsideRange true
 

Alternative MQTT clients

You can use any MQTT client but you will have to specify the MQTT server, the event topics to watch / subscribe to, and the command topics and JSON for publish commands. The MqttDevice output above provides most of the necessary information.

For example, the mosquitto_pub and mosquitto_sub commands equivalent to the above runDeviceComms.sh commands are:


 # Watch the device's event topics
 $ /usr/local/bin/mosquitto_sub -t id/012345/evt/+/fmt/json
 # change the outlier threshold setting
 $ /usr/local/bin/mosquitto_pub -m '{"value":"[125..127]"}' -t id/012345/cmd/sensor1.set1hzMeanRangeThreshold/fmt/json
 # change the "publish individual 1hz outliers" control
 $ /usr/local/bin/mosquitto_pub -m '{"value":"true"}' -t id/012345/cmd/sensor1.setPublish1hzOutsideRange/fmt/json
 
Skip navigation links
Apache Edgent (incubating)

Copyright © 2017 The Apache Software Foundation. All Rights Reserved - 4744f56-20170226-1707