7

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;
        });
        });
    });
});
Skyyy
  • 1,539
  • 2
  • 23
  • 60
  • 1
    What's the front-end coded in? Have you heard of cordova and or phone gap? They use a wrapper to make webapps compatible/downloadable through an app store for iOS and Android systems, it also has support for native coding to add additional functionality where needed. – Ravenous Nov 28 '15 at 18:07
  • I don't know how that can help me? Both end are in javascript. – Skyyy Nov 28 '15 at 18:18
  • Cordova builds a simple native app but uses webviews to display your Webapp (javascript app). So you can code your web app once and get cross compatibility to iOS and Android (I.e. tablets or phones). – Ravenous Nov 28 '15 at 18:40
  • Still don't know how that helps me? – Skyyy Nov 28 '15 at 18:42
  • My app is not complied or anything. It directly runs inside nodejs. I am using same version of nodejs in all 3 devices except tablets are 32bit system. – Skyyy Nov 28 '15 at 18:43
  • 2
    Because you wouldn't download node on every device you want to support, node won't work the same on every device. So you run node on a server and ping the server API to make your app work. Node will treat the device kernels differently and node isn't supported on every kernel in the world anyways which is why it works on some of the devices. Nodes big shebang is the fact that it runs an easily implementable server. If you want client side node try using node WebKit also renamed Nwjs. Also some node modules may have underlying C to make them function and that C code might not be compatible. – Ravenous Nov 28 '15 at 18:56
  • Well i want to run node only on single device and that would be the Tablet – Skyyy Dec 07 '15 at 14:51
  • @Ravenous is probably right on this one. Can we see the script just to make sure? – Max Baldwin Dec 07 '15 at 15:07

2 Answers2

1

As you said it works perfectly fine with other devices and also managed to fix issue with other tablet the possible reason i can think of is corrupt installation of nodejs or other modules you are using

Try to clean re-installation of Nodejs and all modules. May be there is some problem in your modules not in your code.

Another reason you have following issue nodejs maintain two different version both handle installing of modules a different way.

Use the same version you are using in your laptop.

Hemant Parihar
  • 732
  • 1
  • 6
  • 19
0

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)

Skyyy
  • 1,539
  • 2
  • 23
  • 60