-
-
Save ToeJamson/92e22f0419b39707844c to your computer and use it in GitHub Desktop.
Streaming Sensor Readings to a Realtime Gauge Chart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var five = require("johnny-five"); | |
var board = new five.Board(); | |
var pubnub = require("pubnub")({ | |
ssl : true, // <- enable TLS Tunneling over TCP | |
publish_key : "pubnub_publish_key", | |
subscribe_key : "pubnub_subscribe_key", | |
no_wait_for_pending : true | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
board.on("ready", function() { | |
var sensor = new five.Sensor({ | |
pin: "A0", | |
freq: 1000 | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sensor.scale([0, 10]).on("data", function() { | |
reading = this.value.toFixed(2); | |
console.log(reading); | |
pubnub.publish({ | |
channel : 'pubnub-eon-iot', | |
message : { | |
columns:[ | |
['data', reading] | |
] | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var five = require("johnny-five"); | |
var board = new five.Board(); | |
var pubnub = require("pubnub")({ | |
ssl : true, | |
publish_key : "demo", | |
subscribe_key : "demo", | |
no_wait_for_pending : 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); | |
pubnub.publish({ | |
channel : 'pubnub-eon-iot', | |
message : { | |
columns:[ | |
['data', reading] | |
] | |
} | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment