mharsch / node-hdhomerun

low-level device control of HDHomeRun TV tuners for node.js
30 stars 9 forks source link

Undefined #3

Open onaclov2000 opened 9 years ago

onaclov2000 commented 9 years ago

With the following code:

var hdhr = require('hdhomerun');

hdhr.discover(function (err, res) {
    console.log(res);

    var device = hdhr.create({device_id: res[0]['device_id'],
                                             device_ip: res[0]['device_ip']});

    device.get('/sys/model', function (err, res) {
       console.log(res);
     });

    device.set('/tuner0/channel', 'auto:51', function (err, res) {
         console.log(res);
         console.log(err);
    });

});

I get the following results: [ { len: 15, device_id: '103DA852', device_type: 'tuner', tuner_count: 2, checksum: 120479540, _offset: 23, device_ip: '192.168.0.26' } ] { name: '/sys/model', value: 'hdhomerun3_atsc' } undefined [Error: request timeout]

I'm trying to track down whats wrong..... If you have any hints itd be helpful!

Thanks Tyson

mharsch commented 9 years ago

What's happening here is that both commands are getting dispatched to the HDHR immediately and the device can't handle two things at once. A work around would be to schedule the second command to run inside the callback of the first command. Another would be to delay one of the commands with a setTimeout(). To fix this properly, we could either throttle the rate at which we issue commands, or maybe build in some retry logic for timed out commands.

onaclov2000 commented 9 years ago

Makes sense, i saw the ===1 in the emit cts section (in fn _request) of devices.js, in the timeout that gets set i was surprised to see that it only checked for > 0, also the emit section (event handler is it called?) Only checks for > 0, for now an option would be to check for 1, and then anything greater would console log something like "please chain your commands since we cant overload the device" or something like that as a temp, but long term yea, some way of rate limiting the commands sent out to a slower pace would be nice, when i have time i can get a prototype of it out (the console log version, rate limiting might take more time to investogate).

mharsch commented 9 years ago

From what I can tell, the code looks like I was in the middle of trying to solve this problem when I stopped. It looks like I was trying to limit the device to only 1 outstanding request at a time. That doesn't seem to be working, which is why we have the above behavior.

onaclov2000 commented 9 years ago

I'm still very new to Node (and javascript) I'll claim, but I'll try to pick up what I can, I am still trying to understand the whole "outbox" and how it actually goes through the queue per se....LOL