I have and it did help a lot. However my HTML knowledge is quite limited. I’ve got something working using the following code, however I don’t want to see the return API confirmation
You should switch to Javascript as in the tutorial, I think. It is not that hard–instead of using a form and POST, you use button click callbacks and some AJAX style code.
<html>
<head>
<title>Spark function buttons Example</title>
</head>
<body>
<button type="button" onclick="functionCall('functionName', 'functionArgument')">function 1</button>
<button type="button" onclick="functionCall('functionName', 'functionArgument')">function 2</button>
<button type="button" onclick="functionCall('functionName', 'functionArgument')">function 3</button>
<button type="button" onclick="functionCall('functionName', 'functionArgument')">function 4</button>
<script src="http://cdn.jsdelivr.net/sparkjs/1.0.0/spark.min.js"></script>
<script>
//you can use your accesstoken, or your email/passsword to log in. Uncomment accordingly below.
var accessToken = "accesstoken here";
var deviceID = "deviceID here";
spark.on('login', function(response) {
console.log(response);
});
// callback to be executed by each core
var callback = function(err, data) {
if (err) {
console.log('An error occurred while getting core attrs:', err);
} else {
console.log('Core attr retrieved successfully:', data);
}
};
function functionCall(functionName, functionArgument){
// The function needs to be defined in the firmware uploaded to the
// the Spark core and registered to the Spark cloud, same thing we do
// with variables. You pass along the name of the function and the params.
spark.callFunction(deviceID, functionName, functionArgument, callback);
}
// Uncomment a line below depending on your preferred log-in method.
//spark.login({ username: 'email@example.com', password: 'password' });
spark.login({ accessToken: accessToken });
</script>
</body>
</html>
Edit the values accordingly, and you should be able to trigger your functions. It works for me. Let me know if you face any troubles.
Just to clear that up, variables aren't pushed, they're requested. You need to contact the API to tell it that you'd like a variable returned.
SSEs are pushed, to which you only have to subscribe.
There's a big difference between the two, and each has its pros and cons. Check the tutorials by @bko to find out how to use either
And to clear it up a bit more: Particle.variables() are exposed (made public) by the device (by use of the Particle.variable() function) to be requested via the cloud (by use of an appropriately formatted GET request)