Nick BezembinderErwin
Published © GPL3+

Dialog IoT Sensor Starter Guide

Communicate with your Dialog IoT Sensor via Bluetooth Low Energy using Evothings Studio.

IntermediateProtip1.5 hours546
Dialog IoT Sensor Starter Guide

Things used in this project

Software apps and online services

Evothings Studio
Evothings Studio
SmoothieCharts

Story

Read more

Code

app.js

JavaScript
JavaScript code for Evothings mobile application.
document.addEventListener('deviceready',	
	function() { evothings.scriptsLoaded(initialize) }, false
);

var iotsensor;

var chart = new SmoothieChart({minValue: -2, maxValue: 2});
var line_x = new TimeSeries();
var line_y = new TimeSeries();
var line_z = new TimeSeries();

function initialize() 
{ 
	console.log("Initialize function called"); 
	iotsensor = evothings.iotsensor.createInstance(evothings.iotsensor.SFL);
	iotsensor.accelerometerCallback(handleAccelerometerData);
	initializeChart();
}

function initializeChart()
{
	chart.streamTo(document.getElementById("chart_canvas"));
	chart.addTimeSeries(line_x, {lineWidth:3, strokeStyle: "rgb(255, 0, 0)"});
	chart.addTimeSeries(line_y, {lineWidth:3, strokeStyle: "rgb(0, 255, 0)"});
	chart.addTimeSeries(line_z, {lineWidth:3, strokeStyle: "rgb(0, 0, 255)"});
}

function initWatcher()
{
	window.accel_xyz = 0;
	window.evo.watcher.watch('acceleroPlot', window, 'accel_xyz', 'plot');
}

function connect()
{
	iotsensor.connectToClosestSensor(
		7500, // Scan for 7500 ms
		function() { console.log("Connected to IoT Sensor"); },
		function(error) { console.log('Disconnect error ' + error); }
	);
}

function accelerometerOn()
{
	iotsensor.accelerometerOn();
}

function handleAccelerometerData(data)
{
	console.log('x: ' + data.x + ' y: ' + data.y + ' z: ' + data.z);
	var now = Date.now();

	line_x.append(now, data.x);
	line_y.append(now, data.y);
	line_z.append(now, data.z);

	window.accel_xyz = data;
}

index.html

HTML
HTML code for Evothings mobile application
<!DOCTYPE html>
<html>

<head>

	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, user-scalable=no,
		shrink-to-fit=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />

	<title>Dialog IoT Sensor</title>

	<style>
		@import 'ui/css/evothings-app.css';
	</style>

	<script>
	// Redirect console.log to Evothings Workbench.
	if (window.hyper && window.hyper.log) { console.log = hyper.log }
	</script>

</head>

<body ontouchstart=""><!-- ontouchstart="" enables low-delay CSS transitions. -->

	<header>
		<button class="back" onclick="history.back()">
			<img src="ui/images/arrow-left.svg" />
		</button>

		<img class="logotype" src="ui/images/logo.svg" alt="Evothings" />

		<!--<button class="menu" onclick=""><img src="ui/images/menu.svg" /></button>-->
	</header>

	<button class="blue wide" onclick="connect()">Connect</button>

	<button class="blue wide" onclick="accelerometerOn()">Accelerometer On</button>

	<canvas width="300" height="200" id="chart_canvas"></canvas>

	<button class="blue wide" onclick="initWatcher()">Instrumentation</button>

	<script src="cordova.js"></script>
	<script src="libs/evothings/evothings.js"></script>
	<script src="libs/evothings/ui/ui.js"></script>
	<script src="libs/evothings/dialog-iotsensor/iotsensor.js"></script>
	<script src="libs/smoothie/smoothie.js"></script>
	<script script src="app.js"></script>
	<!-- TODO: Add libraries that you need -->

</body>

</html>

evothings-libraries

Evothings Studio JavaScript libraries

evothings-examples

Examples for Evothings Studio. http://www.evothings.com

nbezembinder1.github.io

GitHub repository containing the latest IoT Sensor library version and other (Evothings) example applications.

Credits

Nick Bezembinder

Nick Bezembinder

2 projects • 1 follower
Erwin

Erwin

2 projects • 2 followers

Comments