数据未发送到小区

时间:2019-04-24 09:32:13

标签: node.js raspberry-pi plotly

我在raspberryPI上编写了一个小脚本,以从mongo中获取数据并构建一个可绘制的图,这周我发生了系统崩溃,需要恢复几个月前的数据... 整个过程正在像这样工作:

var express = require('express');
var app = express();
var MongoClient = require('mongodb').MongoClient;
var url = 'mongodb://user:pass@localhost:port';
var str = "";

MongoClient.connect(url, function (err, db) {
if (err) throw err;
var dbo = db.db("DB");

var cursor = dbo.collection("ColectionA").find();
if (cursor == null) {
    console.log('cursor is null');
} else {
    console.log('cursor not null');
    var xArray = [];
    var yArray = [];
    cursor.each(function (err, item) {
        if (item != null) {
            xArray.push(item.item1);
            yArray.push(item.item2)
            console.log(item.item1 + ' ' + item.item2);
        } else {
            var plotly = require('plotly')("user", "APIkey");

            var data = [{
                x: xArray,
                y: yArray,
                type: "scatter"
            }];
            var layout = {
                title: "Title1",
                xaxis: {
                    title: "Date/Time",
                    rangemode: "nonnegative",
                    autorange: true,
                    titlefont: {
                        family: "Courier New, monospace",
                        size: 18,
                        color: "#7f7f7f"
                    }
                },
                yaxis: {
                    title: "Users",
                    rangemode: "nonnegative",
                    autorange: true,
                    titlefont: {
                        family: "Courier New, monospace",
                        size: 18,
                        color: "#7f7f7f"
                    }
                }
            };
            var graphOptions = {
                layout: layout,
                filename: "date-axes",
                fileopt: "overwrite"
            };
            plotly.plot(data, graphOptions, function (err, msg) {
            console.log(msg);
            console.log(err);
            });

            dbo.close();
        }
    });
}
});
setTimeout(function() {
console.log('done...');
process.exit();
}, 20000);

现在,我不会将任何数据发送回去。 我什至尝试将较小的数据数组发送回图表,例如

var data = [{x:[0,1,2], y:[3,2,1], type: 'scatter'}]; 

没有成功,尝试npm install时以为是“崩溃”可能会对过程产生影响, 更改了仪表板上的APIkey,在这里...

我从“ plotly.plot”日志中得到的都是“ Done”消息...

所以...没有成功...我还有什么可以调试的主意吗?

0 个答案:

没有答案