Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Invalid response from Ambient module #54

Open
snollygolly opened this issue Apr 9, 2016 · 12 comments
Open

Error: Invalid response from Ambient module #54

snollygolly opened this issue Apr 9, 2016 · 12 comments
Assignees
Labels

Comments

@snollygolly
Copy link

I'm following the example on http://tessel.github.io/t2-start/modules/ambient.html but I can't get my module to work. This is what I get:

INFO Looking for your Tessel...
INFO Connected to Charmander.
INFO Building project.
INFO Writing project to RAM on Charmander (42.496 kB)...
INFO Deployed.
INFO Running index.js...
/tmp/remote-script/index.js:1
(function (exports, require, module, __filename, __dirname) { var t=require("tessel"),n=require("ambient-attx4"),e=n.use(t.port.A);e.on("ready",function(){setInterval(function(){e.getLightLevel(function(t,n){if(t)throw t;e.getSoundLevel(function(e,t){if(e)throw e;console.log("Light level:",n.toFixed(8)," ","Sound Level:",t.toFixed(8))})})},500)}),e.on("error",function(e){console.log(e)});
                                                                                                                                                                                                                                                                ^

Error: Invalid response from Ambient module
    at Error (native)
    at null.<anonymous> (/tmp/remote-script/node_modules/ambient-attx4/index.js:1:2516)
    at null.<anonymous> (/usr/lib/node/tessel-export.js:296:31)
    at emitNone (events.js:67:13)
    at Socket.emit (events.js:166:7)
    at emitReadable_ (_stream_readable.js:411:10)
    at emitReadable (_stream_readable.js:405:7)
    at readableAddChunk (_stream_readable.js:157:11)
    at Socket.Readable.push (_stream_readable.js:110:10)
    at Pipe.onread (net.js:523:20)

I also tried running the ambient triggers example, and it doesn't crash like this one, but it doesn't seem to register sound or light.

@corymickelson
Copy link

I get the same response running the demo code

@johnnyman727 johnnyman727 self-assigned this Apr 10, 2016
@johnnyman727
Copy link
Contributor

Thanks, I'll check that out this week.

@draco2003
Copy link

@johnnyman727
Copy link
Contributor

Thanks everyone. It's likely that because T2 is faster than T1, we're running into issues that we haven't seen before. I think it can likely be fixed by making sure all messages sent between the Tessel and the module are serialized (ie don't send the next packet until you got a response from the previous) but I won't get a chance to work on this until later this week (currently working on install issues). @corymickelson or @draco2003 if you want to work on a fix, I can help advise in the meantime.

@draco2003
Copy link

I won't get a chance to work on it this week, but i did notice that it randomly updates the firmware as well, which might be a related issue when it's asking for the firmware version info.

@johnnyman727
Copy link
Contributor

Thanks for the extra info @draco2003.

@corymickelson
Copy link

I can give it a go this weekend.

@seiyria
Copy link
Contributor

seiyria commented Apr 18, 2016

Just wanted to note that this happens to me regularly. I take a reading of data every 5 minutes for a chart for my place of residence, and the ambient module seems to just die randomly. Same error as stated in the topic.

@johnnyman727
Copy link
Contributor

@seiyria thanks for the feedback. I worked on this a bit early this weekend and this PR should fix a good number of these issues. I'm going to continue investigating though.

@seiyria
Copy link
Contributor

seiyria commented Apr 18, 2016

@johnnyman727 thanks, I've subscribed to that PR. I'll watch and update you if my situation changes.

@Frijol Frijol added the bug label Sep 2, 2016
@johnnyman727
Copy link
Contributor

Some investigation into this problem. I have a screen grab of when the error occurs based on this example code:

var tessel = require('tessel');
var ambientlib = require('../'); // Replace '../' with 'ambient-attx4' in your own code

var ambient = ambientlib.use(tessel.port['A']);

ambient.on('ready', function () {
 // Get points of light and sound data.
  setInterval( function () {
    ambient.getLightLevel( function(err, lightdata) {
      if (err) throw err;
      ambient.getSoundLevel( function(err, sounddata) {
        if (err) throw err;
        console.log("Light level:", lightdata.toFixed(8), " ", "Sound Level:", sounddata.toFixed(8));
      });
    });
  }, 500); // The readings will happen every .5 seconds
});

screen shot 2016-09-02 at 5 09 53 pm

The problem occurs with the second transaction (requesting the sound data).

The first transaction can be analyzed as:

Tessel

0x2 = Send me light data
0x1 = Just send me one reading
0x0 = Dummy byte
0x0 = Dummy byte
0x0 = Dummy byte
0x16 = End of transaction

Ambient

0x55 = Confirming we are starting a transaction
0x2 = Confirming you want light data
0x1 = Confirming you want 1 reading (16 bits)
0x0 = High data byte
0x6F = Low data byte
0x16 = End of transaction

Then we can see the problem with the second transaction when we request sound data:

Tessel

0x3 = Send me sound data
0x1 = Just send me one reading
0x0 = Dummy byte
0x0 = Dummy byte
0x0 = Dummy byte
0x16 = End of transaction

Ambient

0x0 = Confirmation byte (SHOULD BE 0x55)
0x05 = Confirming command type (SHOULD BE 0x03)
0x51 = Confirming you want 1 reading (SHOULD BE 0x1)
0x0 = High data byte
0x0 = Low data byte
0x0 = End of transaction (SHOULD BE 0x16)

I'm not yet sure why the ATTINY is not able to respond correctly to such a simple command. My guess is that the SPI protocol or timing is not what it's expecting.

@johnnyman727
Copy link
Contributor

This should be fixed with a combination of c11274f and tessel/t2-firmware#209.

Should be closed once tessel/t2-firmware#209 is merged and a new firmware build is released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants