In my current project, we are trying to implement a dashboard that display different sensor values. The following shows functionality. Here, the functionality is -- humidity
and temperature
sensors periodically sending their values. Displaycontroller
receives these values and send it to the dashboard for visualization.
For experiments purpose and exploring new technologies, We have been implementing the above four components using the following way:
TemperatureSensor
andHumiditySensor
innode.js
that publishes the value using MQTT publisher.DisplayController
inNode-RED
that can receive both temperature and humidity sensor values through MQTT subscriber inNODE-RED
.DashBoard
inHTML
andJavascript
Now, here is my question --- How can we connect DisplayController
and DashBoard
components? The problem could be complicated because Displaycontroller
component is implemented in Node-RED
and DashBoard
is implemented in HTML
and JavaScript
. Is it possible to connect these components ? If yes, then How can we connect them?
For further clarity, I am adding Dashboard
component code. The dashborad component polls continuously DisplayController
component (written in Nodejs
, not in Node-RED)
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript"
src="https://www.google.com/jsapi?autoload={
'modules':[{
'name':'visualization',
'version':'1',
'packages':['corechart']
}]
}">
</script>
</head>
<body>
<div id="chart" style="width: 1500px; height: 700px"></div>
<script>
$(document).ready(function () {
var maxDataPoints = 10;
var chart = new google.visualization.LineChart($('#chart')[0]);
var data = google.visualization.arrayToDataTable([
['Time', 'Temperature','Humidity'],
[getTime(), 0,0]
]);
var options = {
title: 'Temperature',
hAxis: {title: 'Time', titleTextStyle: {color: '#333'}}, //Added hAxis and vAxis label
vAxis: {title: 'TempValue', minValue: 0, titleTextStyle: {color: '#333'}},
curveType: 'function',
animation: {
duration: 1000,
easing: 'in'
},
legend: {position: 'bottom'}
};
function addDataPoint(dataPoint) {
if (data.getNumberOfRows() > maxDataPoints) {
data.removeRow(0);
}
data.addRow([getTime(), dataPoint.value,dataPoint.value1]);
chart.draw(data, options);
}
function getTime() {
var d = new Date();
return d.toLocaleTimeString();
}
function doPoll() {
$.getJSON('http://localhost:8686/temperatureData',
function (result) {
addDataPoint(result);
setTimeout(doPoll,5000);
});
}
doPoll();
});
</script>
</body>
</html>