🏥 🏭 Working on the COVID-19 response in Canada? Plotly & the Canadian government can help you and your organization. Learn more and get in touch.

TypeError: Cannot read property 'url' of undefined

console.log("View your streaming graph here: ", res.url);
                                                    ^

TypeError: Cannot read property ‘url’ of undefined
at C:\Users\lenovo\Desktop\plotly\3d.js:82:57
at C:\Users\lenovo\Desktop\plotly\node_modules\plotly\index.js:88:17
at IncomingMessage. (C:\Users\lenovo\Desktop\plotly\node_modules\plotly\index.js:321:
9)
at IncomingMessage.emit (events.js:194:15)
at IncomingMessage.EventEmitter.emit (domain.js:441:20)
at endReadableNT (_stream_readable.js:1125:12)
at process._tickCallback (internal/process/next_tick.js:63:19)

I think this error is happening because they changed the url, but I changed them in my library and it didn’t work.

here is my code:

var plotly_username = ‘mecty21’;

var plotly_api_key = ‘BkLxxai4HsBJMbNvHkl0’;

var plotly_stream_tokens = [‘pit0y0ouay’, ‘cel0p8ge6o’, ‘j0lz0jn3mo’];

var plotly = require(‘Plotly’)(plotly_username, plotly_api_key);

data = {

x: ,

y: ,

z: ,

uid: ‘86878a’,

mode: ‘markers’,

name: ‘up’,

type: ‘scatter3d’,

stream:{token: plotly_stream_tokens[0]},

stream:{token: plotly_stream_tokens[1]},

stream:{token: plotly_stream_tokens[2]},

xsrc: ‘muodov:111:XP6TA5S7RXRPU268FUMTE3AIOJ3EURF9?MN3JD7OH73EQ5N7WR9KU3WKQ1GLC9Z69=“up”’,

ysrc: ‘muodov:111:G1YCCOUXOFM3PMGU37N6493YUNF4U11G?MN3JD7OH73EQ5N7WR9KU3WKQ1GLC9Z69=“up”’,

zsrc: ‘muodov:111:RJ5LFL58LE3KWWJNKWAQ3UFMC1W3IQVJ?MN3JD7OH73EQ5N7WR9KU3WKQ1GLC9Z69=“up”’

};

var layout = {fileopt : “overwrite”, filename : “arduino-johnny5-demo”};

/*

  • Initialize Johnny-Five,

  • the communication layer between the Arduino and this node program.

*/

var five = require(“johnny-five”);

var board = new five.Board();

board.on(“ready”, function() {

/*

  • Initialize sensors

*/

var sensors = {

"A0": new five.Sensor({

        pin: "A0",

        freq: 50 // send reading every 50ms

      }),

"A1": new five.Sensor({

        pin: "A1",

        freq: 50 // send reading every 50ms

      }),

"A2": new five.Sensor({

        pin: "A2",

        freq: 50 // send reading every 50ms

      })

};

/*

  • Initialize a plotly graph

*/

plotly.plot(data,layout,function (err, res) {

if (err) console.log(err);

console.log("View your streaming graph here: ", res.url);

/*

 * Once the graph is initialized, initialize plotly streams

*/ 

var plotly_streams = {

  "A0": plotly.stream(plotly_stream_tokens[0], function (err, res) {

          if (err) console.log(err);

          console.log(res);

        }),

  "A1": plotly.stream(plotly_stream_tokens[1], function (err, res) {

          if (err) console.log(err);

          console.log(res);

        }),

  "A2": plotly.stream(plotly_stream_tokens[2], function (err, res) {

          if (err) console.log(err);

          console.log(res);

        })

};

/*

 * As each sensor receives data, write 

 * it to the plotly_stream. The plotly_stream

 * will pipe it through plotly's servers and

 * your graph will update with the sensor values

 * in real-time.

*/

sensors.A0.on("data", function(){

  data = {

    x: this.value

  };

  plotly_streams.A0.write(JSON.stringify(data)+"\n");

});

sensors.A1.on("data", function(){

  data = {

    y: this.value

  };

  plotly_streams.A1.write(JSON.stringify(data)+"\n");

});

sensors.A2.on("data", function(){

  data = {

    z: this.value

  };

  plotly_streams.A2.write(JSON.stringify(data)+"\n");

});

});

});

// helper function to get a nicely formatted date string

function getDateString () {

var time = new Date();

// 14400000 is (GMT-4 Montreal)

// for your timezone just multiply +/-GMT by 3600000

var datestr = new Date(time - 14400000).toISOString().replace(/T/, ’ ').replace(/Z/, ‘’);

return datestr;

}