hybridgroup / cylon-firmata

Cylon adaptor for the Firmata protocol
http://cylonjs.com
Other
45 stars 10 forks source link

Timing issue, in many cases when running node firmata, it will hang. #34

Closed born2net closed 9 years ago

born2net commented 9 years ago

Timing issue, in many cases when running node firmata, it will hang. Happens about 50% of the time.

See below:

I, [2014-10-24T19:25:53.682Z] INFO -- : Initializing connections. I, [2014-10-24T19:25:53.704Z] INFO -- : Initializing connection 'arduino'. D, [2014-10-24T19:25:53.714Z] DEBUG -- : Loading adaptor 'firmata'. D, [2014-10-24T19:25:56.319Z] DEBUG -- : Registering Firmata adaptor for Robot 76175 D, [2014-10-24T19:25:56.542Z] DEBUG -- : Registering i2c BlinkM driver for Robot 76175 D, [2014-10-24T19:25:57.013Z] DEBUG -- : Registering i2c HMC6352 driver for Robot 76175 D, [2014-10-24T19:25:57.048Z] DEBUG -- : Registering i2c MPL115A2 driver for Robot 76175 D, [2014-10-24T19:25:57.055Z] DEBUG -- : Registering i2c BMP180 driver for Robot 76175 D, [2014-10-24T19:25:57.058Z] DEBUG -- : Registering i2c MPU6050 driver for Robot 76175 D, [2014-10-24T19:25:57.062Z] DEBUG -- : Registering i2c LCD driver for Robot 76175 D, [2014-10-24T19:25:57.065Z] DEBUG -- : Registering i2c LSM9DS0G driver for Robot 76175 D, [2014-10-24T19:25:57.069Z] DEBUG -- : Registering i2c LSM9DS0XM driver for Robot 76175 I, [2014-10-24T19:25:57.093Z] INFO -- : Initializing devices. I, [2014-10-24T19:25:57.098Z] INFO -- : Initializing device 'led'. D, [2014-10-24T19:25:57.110Z] DEBUG -- : Loading driver 'led'. I, [2014-10-24T19:25:57.124Z] INFO -- : Initializing device 'servo'. D, [2014-10-24T19:25:57.128Z] DEBUG -- : Loading driver 'servo'. I, [2014-10-24T19:25:57.138Z] INFO -- : Initializing device 'button'. D, [2014-10-24T19:25:57.141Z] DEBUG -- : Loading driver 'button'. I, [2014-10-24T19:25:57.171Z] INFO -- : Starting connections. I, [2014-10-24T19:25:57.187Z] INFO -- : Connecting to 'arduino' on port /dev/ttyATH0.

born2net commented 9 years ago

I wouldn't mind hiring / paying you to help me resolve this issue as I really need this to be stable and connect 100% of the time ...

edgarsilva commented 9 years ago

No need, we maintain this for free as open source, let me try to replicate right now that I have some time.

born2net commented 9 years ago

thanks SO much... My setup is basically this: http://cylonjs.com/documentation/platforms/yun/

edgarsilva commented 9 years ago

What exactly do you do to reproduce this error? just reboot, I setup my Yun from scratch I'm up to the point where I create a small nodejs server and blink a led passing a value through the server, firmata seems to be working fine using the 57600 baud rate ane everything I wrote on the guide you mentioned above.

I gotta leave today, but tomorrow I'll be back to install cylon and test with it.

Let me know if you have any issues up to that point. This is the code that I'm running in the yun:

console.log('WWW blink start ...');
var firmata = require('firmata');
var ledPin = 12;

var board = new firmata.Board("/dev/ttyATH0", function(err) {
  if (err) {
    console.log('err:', err);
    console.log(err);
    board.reset();
    return;
  }

  console.log('connected...');
  console.log('board.firmware: ', board.firmware);

  board.pinMode(ledPin, board.MODES.OUTPUT);

  var url = require('url');
  var http = require('http');

  http.createServer(function(request, response) {
    var params = url.parse(request.url, true).query;

    console.log('params: ', params);

    if (params.value != null) {
      if (params.value.toLowerCase() == 'high') {
        board.digitalWrite(ledPin, board.HIGH);
      } else {
        board.digitalWrite(ledPin, board.LOW);
      }
    }

    response.writeHead(200);
    response.write("The value written was: " + params.value);
    response.end();
  }.bind(this)).listen(8080);

  console.log('Listening on port 8080 ...');
});

I just run node www-blink.js, and on my computer connected to the same network I open a browser and hit it like this to blink an LED on pin 12:

http://192.168.1.140:8080/?value=low http://192.168.1.140:8080/?value=high

Did you made sure to remove serialport from the firmata/node_modules folder and use the global one you installed with opkg?

born2net commented 9 years ago

first of all, thank you for spending the time. These are the 2 (odd) issues I have founds.

  1. if I set my sketch to anything higher > 9600 baud, my linux won't come up, go figure, I did find some other people online having issue with 9600+ baud, that's why I tried reducing my baud to 9600 on both firmata (which of course is passed to the serial node driver, and yes I removed it and using the node installed one like mentioned in the tutorial) as well as in the StandardFirmata Sketch. Once both are at 9600 linux comes up and all is well.
  2. this issue is VERY weird. If I connect and USB that powered my Yun, it will come up MOST of the time, but not always... the bridge serial 1 (serial connection between Linux and microcontroller) will just hang sometimes. However, i found today that if I disconnect the entire circuit from the wall (120V power source that connects to the USB) instead of just the USB, it seems to come up find 100% of the time. I am a software developer, very technical so I know how this sounds... very odd.. it's almost as if connecting USB by hand has a small windows of time that the Yun gets <5V on plugin and it screws up Yun serial1, tried 2 diff Yuns and I get same behavior... on Rev 4 latest. Very weird I know...
edgarsilva commented 9 years ago

Nah, that is pretty normal the circuits behaving weird when not enough power is provided and when the batteries are below 25%, we see it all the time with many different devices.

I got up to the point right before installing cylon and I have seen no problems with the Yun connected to my computer's USB, I tried the server example and besides an issue with the server (or chrome itself) putting two requests the firmata and node-serialport were working fine.

What I did noticed is that once you increase the available disk space it takes a long time for the board to load, like 5 mins sometimes or more, I just leave it until I see the white USB led flash and then I test the connection using SSH, then I start working.

I'll continue setting up everything tomorrow morning PDT, and let you know what I find, but so far seems solid, it could be other things like an Yun with issues, or the install failed for some reason.

Anyways we can check it out tomorrow and if all fails we can start from scratch with your board see how far we get, the entire process should takes us like an hour or so.

Regards, TTYT.

born2net commented 9 years ago

the issue with the 9600 is ok by me, since it's fast enough to send the IO bits... what really bothers me now is the fact that sometimes when I reboot the Arduino Yun, the Serial bridge does't seem to connect... it's a hit and miss :( tried different power USB adapters... and seems to be the same...

and gets stuck with:

I, [2014-10-26T00:55:29.466Z] INFO -- : Starting connections. I, [2014-10-26T00:55:29.482Z] INFO -- : Connecting to 'arduino' on port /dev/ttyATH0.

edgarsilva commented 9 years ago

@born2net: Did you ever find a solution for this? I'll give it another try today but I was not able to reproduce last time, only think I noticed is that it takes a long time for the board to reboot. Other than that it seem to work fine.

Anyways I'll check it out again and let you know if I'm able to reproduce.

edgarsilva commented 9 years ago

This is an old issue, seems to be working with a different rate, so I'm closing it.