Hello everyone,
I am working on a university project at the moment where we have an exhibition of an interactive art installation that will be placed in my local city for 3 days. On our website about the art installation we want to implement a counter that simply counts the amounts of interactions that people have done with our installation in these 3 days. The signal that an interaction has taken place would come from the Arduino which is connected to the Photon.
I have done a prototype of this where I used a simple pushbutton that substitutes the signal coming from the Arduino.
The html/js code for this:
<script type="text/javascript">
function start() {
// document.getElementById("flower").innerHTML = "Waiting for data...";
var deviceID = "CENSORED";
var accessToken = "CENSORED";
var eventSource = new EventSource("https://api.spark.io/v1/devices/" + deviceID + "/events/?access_token=" + accessToken);
eventSource.addEventListener('open', function(e) {
console.log("Opened!"); },false);
eventSource.addEventListener('error', function(e) {
console.log("Errored!"); },false);
eventSource.addEventListener('+1', function(e) {
//console.log("received '" + e-data + "'" );
var parsedData = JSON.parse(e.data);
var flowerSpan = document.getElementById("flower");
var tsSpan = document.getElementById("tstamp");
localStorage.flowercount = Number(localStorage.flowercount)+1;
//tempSpan.innerHTML = "Core: " + parsedData.coreid + " flower: " + parsedData.data + " (h:m:s)";
//tempSpan.innerHTML = "flower";
flowerSpan.innerHTML = "There have been " + localStorage.flowercount + " interactions with the flower.";
flowerSpan.style.fontSize = "28px";
tsSpan.innerHTML = "At timestamp " + parsedData.published_at;
tsSpan.style.fontSize = "9px";
}, false);
}
`
This works, the problem is that it stores the counter variable only locally in the browser.
What I actually need is storing the counter number somewhere on a web server and then display the number on my project website, where it gets updated regulary.
I’ve already researched a lot and tried to work with a MySQL database, unfortunately I’m lacking the experience and skills in these fields.
I’ve also followed this tutorial, as it looks like something that I need. Unfortunately it gives me a hook error in the console.particle event log. I can’t seem to find where the error is so I am looking for a different(possibly easier) solution for my problem.
At the moment I am quite desperate and any help or tips are appreciated!