Search code examples
javascriptnode.jsarduino-unotwitter-streaming-apijohnny-five

Nodejs modules not working as expected in different devices


I am using twitter streaming api & johnny-five with some other modules http , express& socket.io with arduino uno

My script is working fine in laptop. But my production will be on a tablet. I have two tablets and both are responding differently. On hp omni tablet i am receiving following error

enter image description here

Also i have arduino-uno connected on port COM3 but its shows device connected on COM1

As far as i know this error is caused when standard firmata is not uploded in arduino. I have uploaded this program and it work fine in laptop

On Acer Tablet i am not receiving any errors program starts perfectly fine without any issues but i am not receiving tweets with twitter streaming api

I have crossed checked many times it runs perfectly fine on laptop every time i run it but gives two different issues with the tablets

Here is the code i am using

var Twitter = require('twitter');
var five = require("johnny-five");
var express = require('express')
  , app = express()
  , http = require('http')
  , server = http.createServer(app)  
  , io = require('socket.io').listen(server);

server.listen(8080);

// routing
app.use(express.static(__dirname + '/http'));
app.use(function (req, res, next) {
        res.setHeader('Access-Control-Allow-Origin', "http://"+req.headers.host+':80');

        res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
        res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
        next();
    }
);

var client = new Twitter({
  consumer_key: 'abc',
  consumer_secret: 'abc',
  access_token_key: 'abc',
  access_token_secret: 'abc'
});

var board = new five.Board();

board.on("ready", function() {
    this.pinMode(5, five.Pin.OUTPUT);
    this.pinMode(10, five.Pin.INPUT);
      //Ask to visit url
      console.log("Visit http://localhost:8080");
    var randomHashtag = Math.floor((Math.random() * 10000) +1);
    var count = 0;//Initialize counter
    io.sockets.on('connection', function (socket) {     
        console.log('Ready to recieve tweets');//Prints Message when Socket.io is ready to recieve tweets
        io.emit('stream',{number:randomHashtag});//Send random no when socket initzilize
        client.stream('statuses/filter', {track: '#tweetMe'}, function(stream) {
            stream.on('data', function(tweet) {
                if(tweet.text.search(randomHashtag) > 0){
                    count++;//Increment pending tweets              
                    randomHashtag  = Math.floor((Math.random() * 10000) +1);                
                    io.emit('stream',{number:randomHashtag});                   
                    board.digitalWrite(5,1);
                    console.log(tweet.text);                    
                }
                else{
                    console.log("Tweet Without random No");
                }
            });

        stream.on('error', function(error) {
            throw error;
        });
        });
    });
});

Solution

  • I resolved issue with HP OMNI tablet by manually telling johnny-five on which port my arduino is connected as mentioned in OFFICIAL DOCUMENTATION

    new five.Board({ port: "COM3" });//FOR WINDOWS ONLY
    

    Also i had to reinstall all modules to make it work

    (Still not working with Acer tablet though)