TheThingSystem / steward

The Thing System is a set of software components and network protocols that aims to fix the Internet of Things. Our steward software is written in node.js making it both portable and easily extensible. It can run on your laptop, or fit onto a small single board computer like the Raspberry Pi.
http://thethingsystem.com
Other
347 stars 81 forks source link

LIFX discovery takes too long #133

Closed RussNelson closed 10 years ago

RussNelson commented 10 years ago

Making progress. I have two bulbs, but only one is being discovered. If I just print the bulb information (which is a hash containing the Ethernet address and assigned name of the bulb) and immediately return, it prints both bulbs reliably. If, on the other hand, I create the info struct and call devices.discover(info), it only ever finds one bulb. It's like the lifxjs code is failing to report the second bulb if the reporting of the first one takes too long. The RPi is clearly receiving both UDP packets according to TCPdump, so the problem seems that something is not queuing, but instead discarding an 'on' event. Suggestions for where to fix this?

RussNelson commented 10 years ago

How do other drivers solve this problem?

mrose17 commented 10 years ago

i've never heard of a driver having this problem. can you create gist with the constructor() and start() methods so i can see how they are structured? thanks!

RussNelson commented 10 years ago

Well, I tried the example code in the library by putting a sleep.sleep(10); in the bulb discovery routine, and that didn't fail. So it's not a question of something timing out, or getting overwritten in a buffer, or falling out of a queue.

https://gist.github.com/RussNelson/8682092 has the constructor and start methods.

mrose17 commented 10 years ago

hi. i have a simple theory. look at line 60, you have:

                                                   , udn         : 'LIFX:' +  + bulb.lifxAddress.toString('hex')

get rid of the first "+ "

then do this:

cd steward/steward ../scripts/jshint.sh

and fix whatever it complains about in your module.

i suspect that the two adjacent plus-signs is doing something unfortunate…

let me know.

thanks!

RussNelson commented 10 years ago

FYI, I don't know why a shell script should have [[ in it:

pi@raspberrypi ~/steward $ (cd steward/; ../scripts/jshint.sh) ../scripts/jshint.sh: 79: /home/pi/.nvm/nvm.sh: [[: not found ../scripts/jshint.sh: 79: /home/pi/.nvm/nvm.sh: [[: not found ../scripts/jshint.sh: 133: /home/pi/.nvm/nvm.sh: [[: not found -e N/A ../scripts/jshint.sh: 5: ../scripts/jshint.sh: jshint: not found

mrose17 commented 10 years ago

ok, try this:

npm install -g jshint

then do

../scripts/jshint.sh

RussNelson commented 10 years ago

Yes, it was doing something odd. Now, though, even though I'm calling devices.discover(info);, my constructor is not getting called. Instead, the bulbstate handler is getting called, and my device doesn't exist.

mrose17 commented 10 years ago

what is printed by the steward and console.log() when bulbs are discovered, there isn't much information for me to go on in the report above. thanks.

RussNelson commented 10 years ago

Added it to the gist. The key item is that "LIFX new bulb: Hallway" gets printed, but "create new bulb" does not.

RussNelson commented 10 years ago

Hmmmm.... it never says "found LIFX /...." which should be printed by devices.discover() at line 192. I don't see any exit path from that subroutine which would allow it to NOT print that nor any other error except for the very first return, which could happen if the device id already exists, and the 'bulb' handler would never even call devices.discover() if devices.devices[info.id] already exists. Color me confused.

mrose17 commented 10 years ago

that's odd. try using the contents of this gist as your start routine.

RussNelson commented 10 years ago

Didn't help. Am starting to doubt that I ever learned to program. I'm going to go through devices.discover() one basic block at a time.

deviceUID = info.id;...., this chunk is already tested for success before we even get into this code, and we know it succeeds, so we know this will succeed as well.

if ((!info.ipaddress).... neither ipaddress nor url are set, so this isn't executed.

It saves, or should save, the info block in a hash filed under "discovery".

deviceType = (makers[info.deviceType.... we don't get this message printed, so clearly we have a maker (or this code isn't getting executed at all).

db.get('SELECT deviceID FROM devices.... presumably this defined function gets executed.

if (!!info.ipaddress).... well, we never set that, so this is not

likely to be true; even if it was, it would only set a variables.

if (err) { .... obviously not true because the only thing it does

there is print an error, and we don't see that.

} else if (row !== undefined) { .... only gets executed if we

recognize this device, and if we do, we print 'found ....'

  if (!info.device.name) .... if we don't already have a name (but

we set one), create one.

  devices[deviceUID].device = new (makers[deviceType])(row.deviceID, deviceUID, info);

.... and now we've called the constructor, only we don't.

mrose17 commented 10 years ago

there is something wrong, obviously, but i don't know what. let's try this:

  1. make a copy of your lighting-lifx-led.js file
  2. use the version here https://gist.github.com/mrose17/8683006
  3. restart the steward

good luck!

RussNelson commented 10 years ago

Weird. The change that made it work was to move from .../led to .../bulb. Okay, I'm back on track now .... will keep you posted. Ski weekend, so don't hold your breath.

mrose17 commented 10 years ago

i'm glad it worked out. at some point, we're going to need a minimal driver working and in the repo… LIFX has started shipping in bulk now...

RussNelson commented 10 years ago

Oh, yes, totally. Now that I'm going again, I'll be making more progress to show to you.

mrose17 commented 10 years ago

groovy!