Moors7
August 21, 2015, 7:42pm
4
This is a good one:
Here’s a tutorial to get you started using Spark.publish().
Let’s imagine you want to monitor your core’s uptime, that is, how many hours, minutes, and seconds since the last time the core was reset or powered-up and view it on a web page that you can leave open all the time.
You can use the millis() function to measure time and for this example, you can ignore the fact that it can wrap-around back to zero after many days. So you need two things, code for your Spark core and code for a web page…
Here's an example for the subscribing: (You'll have to adjust that for HTML/javascript. The example as-is is for node.js)
/*jslint node: true */
"use strict";
var spark = require('../../lib/spark');
//var spark = require('spark');
//example code to re open the SSE stream when it ends
var openStream = function() {
//Get your event stream
var req = spark.getEventStream(false, 'mine', function(data) {
console.log("Event: " + JSON.stringify(data));
});
req.on('end', function() {
console.log("ended! re-opening in 3 seconds...");
setTimeout(openStream, 3 * 1000);
});
};
This file has been truncated. show original
This is for playing your audio, in combination with your own link:
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
Swapping out the PIR sensor for a button should be trivial. Just make sure you debounce the button to make sure if doesn't trigger repeatedly, or you might cross the publish threshold.
2 Likes