Skip to content

Instantly share code, notes, and snippets.

@stephenlb
Forked from domadev812/1.js
Created November 15, 2017 21:06
Show Gist options
  • Save stephenlb/9134f6e1d937bc30c3490a6b8a95e1ea to your computer and use it in GitHub Desktop.
Save stephenlb/9134f6e1d937bc30c3490a6b8a95e1ea to your computer and use it in GitHub Desktop.
Streaming Sensor Readings to a Realtime Gauge Chart
var five = require("johnny-five");
var board = new five.Board();
var pubnub = new PubNub({
subscribeKey: "mySubscribeKey",
publishKey: "myPublishKey",
ssl: true
})
board.on("ready", function() {
var sensor = new five.Sensor({
pin: "A0",
freq: 1000
});
});
sensor.scale([0, 10]).on("data", function() {
reading = this.value.toFixed(2);
console.log(reading);
var publishConfig = {
channel : "pubnub-eon-iot",
message : {such: 'object'}
}
pubnub.publish(publishConfig, function(status, response) {
console.log(status, response);
})
var five = require("johnny-five");
var board = new five.Board();
var pubnub = new PubNub({
subscribeKey: "mySubscribeKey",
publishKey: "myPublishKey",
ssl: true
})
var reading, message;
board.on("ready", function() {
var sensor = new five.Sensor({
pin: "A0",
freq: 1000
});
sensor.scale([0, 10]).on("data", function() {
reading = this.value.toFixed(2);
console.log(reading);
var publishConfig = {
channel : "pubnub-eon-iot",
message : {columns:[['data', reading]]}
}
pubnub.publish(publishConfig, function(status, response) {
console.log(status, response);
})
});
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript" src="http://pubnub.github.io/eon/lib/eon.js"></script>
<link type="text/css" rel="stylesheet" href="http://pubnub.github.io/eon/lib/eon.css" />
</head>
<body>
<div id="gauge"></div>
</body>
<script>
eon.chart({
channel: "pubnub-eon-iot",
generate: {
bindto: '#gauge',
data: {
type: 'gauge'
},
gauge: {
min: 0,
max: 10
},
color: {
pattern: ['#FF0000', '#F6C600', '#60B044'],
threshold: {
values: [3, 6, 9]
}
}
}
});
</script>
</html>
<script type="text/javascript" src="//pubnub.github.io/eon/v/eon/1.0.0/eon.js"></script>
<link type="text/css" rel="stylesheet" href="//pubnub.github.io/eon/v/eon/1.0.0/eon.css"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment