Stephen Borsay
Published © GPL3+

Almost Real-Time Analytics with AWS and the Soracom Wio LTE

This project will show you how to program and connect your Soracom Wio LTE to AWS IoT using the Soracom Beam service and an Arduino Sketch

IntermediateWork in progress3 hours1,181
Almost Real-Time Analytics with AWS and the Soracom Wio LTE

Things used in this project

Story

Read more

Schematics

WIo LTE Docs and github

Code

Lambda Function in Node.js

JavaScript
This is our Lambda function for data enrichment using AWS IoT Anlytics. No additional Node modules are needed.
// Handler called by IoT Analytics
exports.handler = function handler(event, context, callback) {
    
//add timesteamp to incoming data and name it "ServersideTimestam"
        event[0].ServersideTimestamp = Date.now();
        
        // Return the data        
        callback(null, event);
 //   });
};

Graphing website to be hosted on S3

HTML
This is our static website to be hosted on S3 which reads data from IoT Analytics held in a partition on S3. The webpage ingests data with an AJAX GET, then parses the data with RegEx's placing the data into arrays for each variable. Finally, the data is graphed using Google Charts brought in to our website from a CDN. Make sure to keep this in a public bucket, giving everyone read permission unless you want to customize it with API Gateway or assign federated or other access with Cognito. Do not store passwords or other sensitive information in a public S3 partition.
<!DOCTYPE html>
<html>
<!–– project by Stephen Borsay for Soracom AWS Contest www.Embedded-IoT.net  ––> 
<!–– My AWS IoT Course on Udemy https://www.udemy.com/exploring-aws-iot ––> 
<head>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
  <div id="chart_div"></div>
	<script>
  
$(document).ready(function(){
  $("button").click(function(){
$.get( "https://mykbucket14.s3.amazonaws.com/dataSet522", function( data ) {
		//alert( "Data Loaded: " + data );
		
		var temperature = data.match( /(?<=^")[0-9.]+/gm );
		var humidity = data.match( /(?<=^"\d\d",")[0-9.]+/gm );
		var timestamps = data.match( /(?<=^"\d\d","\d\d",")[0-9.]+/gm )
		
		//use a string literal to output our values before graphing
		alert(`Values in our temerature array to grap ${temperature}`);
		alert(`Valuesin our humidity array to graph ${humidity}`);
		alert(`Values in our timestamp array to graph ${timestamps}`);
    
google.charts.load('current', {packages: ['corechart', 'line']});
google.charts.setOnLoadCallback(drawBasic);  
function drawBasic() {
      var data = new google.visualization.DataTable();
      data.addColumn('number', 'time');
      data.addColumn('number', 'temperature');
      data.addColumn('number', 'humidity');
  
      
//the followig three loops convert our strings in into numbers      
for(var ts=0; ts<timestamps.length;ts++) timestamps[ts] = parseInt(timestamps[ts], 10);
for(var tem=0; tem<temperature.length;tem++) temperature[tem] = parseInt(temperature[tem], 10);
for(var hum=0; hum<humidity.length;hum++) humidity[hum] = parseInt(humidity[hum], 10);
for (i = 0; i < timestamps.length; i++) { 
      data.addRows([
        [timestamps[i],temperature[i],humidity[i]]
      ]);
      }
      
      var options = {
        hAxis: {
          title: 'Time'
        },
        vAxis: {
          title: 'Environmental Data'
        }
      };
      var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
      chart.draw(data, options);
    }
      
		});	
    }); 
}); 
	</script>
</head>
<body>
<img src="YOUR_IMAGE.jpg" alt="Your Soracom AWS Project"> 
<br>
<button>Press to display our most recent data</button>
	
</body>
</html>

My AWS IoT Github

This link points to the code for this project, as well as other projects utilizing Mongoose OS, Zerynth, and Node-Red etc. All are related to AWS-IoT

MQTT Data to AWS IoT - No Sensor

This Arduino sketch (mqtt-client2.ino) connects your Wio LTE to AWS IoT Core if you don't have an external sensor. It generates a fake data JSON data package to publish to AWS IoT Core.

MQTT Data to AWS IoT -DHT Sensor

This Sketch (mqtt-dht11.ino) connects to AWS IoT from the Wio LTE utilizing real sensor data from a connected DHT device.

Credits

Stephen Borsay

Stephen Borsay

11 projects • 73 followers
Computer Engineer: Embedded Systems and IoT. AWS IoT Hero www.udemy.com/user/stv/ device2cloud.net

Comments