I found a public fiddle that I am trying to modify for my purposes. It reads analog values from a BeagleBone and displays them on the screen. It works well and updates the values when I run it from the original author's fiddle. But when I fork the fiddle and access it from my dashboard though, it does not appear to work. The values do not update.
I have confirmed it is running from my beaglebone, as it stops updating when I remove power. I also thought it might be a port conflict or something, the two fiddles fighting for access, but that does not seem to be the case. I disproved this by opening multiple instances of the original author's fiddle and they all update in unison, I can even modify them without causing a problem, but nothing works when saved in my dashboard.
... I don't get it, does some weird setting change occur when I fork the file?
HTML:
<h1>BoneScript Analog Value Monitor</h1>
<p>AIN0 = <span id="ain0"></span> </p>
<p>AIN1 = <span id="ain1"></span> </p>
<p>AIN2 = <span id="ain2"></span> </p>
<p>AIN3 = <span id="ain3"></span> </p>
<p>AIN4 = <span id="ain4"></span> </p>
<p>AIN5 = <span id="ain5"></span> </p>
<p>AIN6 = <span id="ain6"></span> </p>
Javascript:
setTargetAddress('beaglebone.local', {
initialized: run
});
setTargetAddress('192.168.7.2', {
initialized: run
});
// The demo BoneScript application within the 'run()' function
function run() {
/*
* Setup
*/
var b = require('bonescript');
var ain = [];
for (var j = 0; j <= 6; j++) {
for (var i = 0; i < b.bone.pinIndex.length; i++) {
if (b.bone.pinIndex[i].name == 'AIN' + j) {
ain[j] = b.bone.pinIndex[i].key;
}
}
}
var index = 0;
doRead();
function doRead() {
b.analogRead(ain[index], onRead);
}
function onRead(x) {
try {
$('#ain' + index).html(x.value.toFixed(3));
} catch (ex) {
$('#ain' + index).html('XXXXX');
}
index++;
if (index > 6) {
index = 0;
setTimeout(doRead, 100);
} else {
doRead();
}
}
}
Original Author's Fiddle: http://jsfiddle.net/jkridner/gC6um/
My forked Fiddle: https://jsfiddle.net/Kjorkis/97002L1m/