Hi, thanks for having me on the forum. For a school project, I have been using plotly for approx 2 months with success displaying a serial stream originating from a sensor attached to an Arduino board, which is attached to raspbian Jessie. The pi runs a bare-bones hard-coded server (see code below) All of a sudden, using the same code, same everything, I am not getting stream data to plotly. It sets up the chart, but no data. We’ve tried everything. Worked great before, now we’re dead in water. Thanks in advance for any help
var serialport = require(‘serialport’),
plotly = require(‘plotly’)(‘xxxx’,‘xxxx’),
token = ‘xxxx’;
var portName = ‘/dev/ttyACM0’;
var sp = new serialport.SerialPort(portName,{
baudRate: 9600,
dataBits: 8,
parity: ‘none’,
stopBits: 1,
flowControl: false,
parser: serialport.parsers.readline("\r\n")
});
// helper function to get a nicely formatted date string
function getDateString() {
var time = new Date().getTime();
// 32400000 is (GMT+9 Japan)
// for your timezone just multiply +/-GMT by 36000000
var datestr = new Date(time - 28800000).toISOString().replace(/T/, ’ ').replace(/Z/, ‘’);
return datestr;
}
var initdata = [{x:[], y:[], stream:{token:token, maxpoints: 500}}];
var initlayout = {fileopt : “extend”, filename : “sensor-test”};
plotly.plot(initdata, initlayout, function (err, msg) {
if (err) return console.log(err)
console.log(msg);
var stream = plotly.stream(token, function (err, res) {
console.log(err, res);
});
sp.on('data', function(input) {
if(isNaN(input) || input > 1023) return;
var streamObject = JSON.stringify({ x : getDateString(), y : input });
console.log(streamObject);
stream.write(streamObject+'\n');
});
});