95-733 Internet Technologies February 16, 2017 Project 3 Edge Analytics using Edgent Due: 11:59 PM, Thursday March 2, 2017 In the paper on Sensor Andrew, three tiers were described. There is the sensor tier - the sensors themselves, the gateway tier - able to connect to the internet, and the server tier - able to receive data from many gateways and perform back end analytics. We might also add a visualization tier - able to display sensor values in an appealing way. In this project, you will work at the gateway tier using Apache Edgent, the server tier using MQTT and the visualization tier using Google Charts. Part 1. Installing Apache Edgent 20 Points ============================================== Apache Edgent is an API and runtime designed by IBM for edge analytics. Your first task is to download and install Apache Edgent from the Apache Edgent web site: http://edgent.incubator.apache.org. The original download will come with a build.xml file. In the same directory as build.xml, run the ant command. This will execute the code in the build.xml file. You may need to first install ant. Apache ant may be found here: https://ant.apache.org/bindownload.cgi. There is Javadoc documentation available here: http://edgent.incubator.apache.org/javadoc/latest/index.html. There is sample code available. One of the sample programs consists of a temperature sensor (TempSensor.java) and it is designed to generate temperature values whenever its get method is called. In effect, it acts as an Edgent Supplier - supplying an infinite stream of Java Doubles. Another file is called TempSensorApplication.java. This file illustrates the filtering of a stream to create a new stream. The temperature values are filtered and only those outside of the range [50..80] are placed in the new stream. In Part 1, your task is to get this system running. You will need to import the appropriate jar files into Netbeans (right click the project, select properties and library and add jar files to the compile time library.) Part 2. Modifying the TempSensorApplication 20 Points ======================================================= Modify your program in part 1 so that it reports on all values that are greater than 70 or less than 60. Modify it so that it only polls the sensor once every 0.5 seconds. Add a new stream that reads each value in the filtered stream and generates a JSON string in a Schema.org, JSON-LD format. You may use, for example: {"@context": "http://schema.org/", "@type": "Sensor", "temperature": " 59.84095121646695, "units": "fahrenheit", "url": "http://www.sensorInfo.com/1234" } Part 3. Generate the JSON to an MQTT provider 20 points ========================================================= Browse the documentation and help files at http://edgent.incubator.apache.org. Learn how to generate output to a remote MQTT implementation. As we did in Project 2, you may use a local MQTT provider (Mosquito) or a service on the cloud (HiveMQ). The necessary jar files are found in the installation directories of Edgent. You will need to look around for these. Modify your program in Part 2 so that it publishes the JSON messages to MQTT. Part 4. Subscribe to the MQTT service with Javascript and Websockets 20 Points ============================================================================== Build a simple browser based application using web sockets and Google Charts. This application will receive the JSON strings (in JSON-LD format) from MQTT and display the data using a Gauge. The detail design of this Gauge is in your hands. You need to show that a) you are parsing JSON-LD data from MQTT and 2) you are displaying that data in a Gauge. The Gauge should be appropriately configure and labelled and show changes in temperatures as reported by the sensor. Part 5. Documentation 20 Points ================================== There are four programming parts to this project (worth 80 points). The last 20 points will be earned by thoroughly documenting your four solutions. The grader will be looking to see how well you explain the code each part of the system you are building. It is OK to include notes from the web (and from the Javadoc) in your documentation. But the grader will assess the overall quality of these comments as well as their careful placement within your code. That is, are the comments found appropriate to the code being explained? Do the comments help or hinder the reader in understanding this part of the project? The documentation should be solid. It should be well written or well selected. It should show that the student has a clear understanding of the four parts of Project 3. //================================ TempSensor.java ======================= import java.util.Random; import org.apache.edgent.function.Supplier; /** * Every time get() is called, TempSensor generates a temperature reading. */ public class TempSensor implements Supplier { double currentTemp = 65.0; Random rand; TempSensor(){ rand = new Random(); } @Override public Double get() { // Change the current temperature some random amount double newTemp = rand.nextGaussian() + currentTemp; currentTemp = newTemp; return currentTemp; } } import java.util.concurrent.TimeUnit; import org.apache.edgent.providers.direct.DirectProvider; import org.apache.edgent.topology.TStream; import org.apache.edgent.topology.Topology; public class TempSensorApplication { public static void main(String[] args) throws Exception { TempSensor sensor = new TempSensor(); DirectProvider dp = new DirectProvider(); Topology topology = dp.newTopology(); TStream tempReadings = topology.poll(sensor, 1, TimeUnit.MILLISECONDS); TStream filteredReadings = tempReadings.filter(reading -> reading < 50 || reading > 80); filteredReadings.print(); dp.submit(topology); } }