AlexGustafsson / homebridge-wol

A Wake on Lan plugin for Homebridge
MIT License
297 stars 30 forks source link

Cannot read property 'length' of undefined #10

Closed Finch106 closed 7 years ago

Finch106 commented 7 years ago

When starting Homebridge, everything runs fine. The app shows the computer as off, but when I try to power on, I see homebridge stop and provide the following:

Call get for undefined, return true /usr/local/lib/node_modules/homebridge-wol/node_modules/wake_on_lan/wake_on_lan.js:12 if (mac.length == 2 * mac_bytes + (mac_bytes - 1)) { ^

TypeError: Cannot read property 'length' of undefined at Object.exports.createMagicPacket (/usr/local/lib/node_modules/homebridge-wol/node_modules/wake_on_lan/wake_on_lan.js:12:10) at Object.exports.wake (/usr/local/lib/node_modules/homebridge-wol/node_modules/wake_on_lan/wake_on_lan.js:46:30) at wake (/usr/local/lib/node_modules/homebridge-wol/index.js:69:9) at Computer. (/usr/local/lib/node_modules/homebridge-wol/index.js:41:11)

AlexGustafsson commented 7 years ago

Seems to be an error with a dependency. I will check to see if there is a fix. Thanks for the heads up.

AlexGustafsson commented 7 years ago

What does your configuration look like?

Finch106 commented 7 years ago

}, "accessories": [{ "accessory": "Computer", "name": "My Computer" "mac": "##:##:##:##:##:##", "ip": "192.168.1.##" }], "platforms": [{

AlexGustafsson commented 7 years ago

It seems to be an error in your configuration. The mac mentioned in the error (if (mac.length...) is taken from the config object, that is

{
"accessory": "Computer",
"name": "My Computer"
"mac": "##:##:##:##:##:##", <-- this
"ip": "192.168.1.##"
}

Since we have not faced this error earlier it does not seem to be directly related to homebridge-wol. If you copied your configuration and pasted it here, you can see that there is in fact an error in your configuration.

"accessories": [{
"accessory": "Computer",
"name": "My Computer" <--- missing semicolon
"mac": "##:##:##:##:##:##",
"ip": "192.168.1.##"
}],

If there is no error in your actual configuration, try to paste it in a JSON-parser (for example this one) and make sure that it parses correctly. If it does parse, check to see that the value "mac" is indeed available in the parsed tree.

Finch106 commented 7 years ago

{ "bridge": { "name": "Homebridge", "username": "CC:22:3D:E3:CE:30", "port": 51826, "pin": "031-45-154" }, "accessories": [{ "accessory": "Computer", "name": "The Computer", "mac": "##:##:##:##:##:##", "ip": "192.168.1.11" }], "platforms": [{ "platform": "Nest", "token": "numbersandtbings$"clientId": "otheritems$"clientSecret": "tjwifjew$"code": "disks", "username": "myacxoubt.com", "password": "djs" }, { "platform": "Wink", "name": "Wink",

"hide_groups": ["garage_doors"], "hide_ids": [] }] }

Finch106 commented 7 years ago

This is all scrambled now, but the Bridge and Accessories portion are the main bit.

Finch106 commented 7 years ago

{ "bridge": { "name": "Homebridge", "username": "CC:22:3D:E3:CE:30", "port": 51826, "pin": "031-45-154" }, "accessories": [{ "accessory": "Computer", "name": "The Computer", "mac": "##:##:##:##:##:##", "ip": "192.168.1.11" }] }

Finch106 commented 7 years ago

WARNING The program 'node' uses the Apple Bonjour compatibility layer of Avahi. WARNING Please fix your application to use the native API of Avahi! WARNING For more information see http://0pointer.de/avahi-compat?s=libdns_sd&e=node WARNING The program 'node' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi. WARNING Please fix your application to use the native API of Avahi! WARNING For more information see http://0pointer.de/avahi-compat?s=libdns_sd&e=node&f=DNSServiceRegister [12/16/2016, 3:37:04 AM] Loaded plugin: homebridge-nest [12/16/2016, 3:37:04 AM] Registering platform 'homebridge-nest.Nest' [12/16/2016, 3:37:04 AM] --- [12/16/2016, 3:37:07 AM] Loaded plugin: homebridge-wink [12/16/2016, 3:37:08 AM] Registering platform 'homebridge-wink.Wink' [12/16/2016, 3:37:08 AM] --- [12/16/2016, 3:37:08 AM] Loaded plugin: homebridge-wol [12/16/2016, 3:37:08 AM] Registering accessory 'homebridge-wol.Computer' [12/16/2016, 3:37:08 AM] --- [12/16/2016, 3:37:08 AM] Loaded config.json with 1 accessories and 2 platforms. [12/16/2016, 3:37:08 AM] --- [12/16/2016, 3:37:08 AM] Loading 2 platforms... [12/16/2016, 3:37:08 AM] Initializing Nest platform... [12/16/2016, 3:37:08 AM] Fetching Nest devices. [12/16/2016, 3:37:08 AM] [Wink] Initializing Wink platform... [12/16/2016, 3:37:08 AM] [Wink] Fetching Wink devices. [12/16/2016, 3:37:09 AM] Loading 1 accessories... [12/16/2016, 3:37:09 AM] [My Computer] Initializing Computer accessory... [12/16/2016, 3:37:09 AM] [My Computer] Starting timer on 5000ms interval for undefined. [12/16/2016, 3:37:12 AM] [Wink] Device Ignored Not In HomeKit - Group hubs, ID 120872, Name LR Hub [12/16/2016, 3:37:12 AM] [Wink] Device Added - Group light_bulbs, ID 466364, Name Lamp [12/16/2016, 3:37:12 AM] [Wink] Device Added - Group light_bulbs, ID 466438, Name Guest Bedroom [12/16/2016, 3:37:12 AM] [Wink] Device Added - Group binary_switches, ID 41029, Name Camera Switch [12/16/2016, 3:37:12 AM] [Wink] Device Added - Group light_bulbs, ID 486051, Name Living Room [12/16/2016, 3:37:12 AM] [Wink] Device Added - Group sensor_pods, ID 62872, Name Front Door Sensor [12/16/2016, 3:37:12 AM] [Wink] Device Added - Group sensor_pods, ID 62885, Name Back Door Sensor [12/16/2016, 3:37:12 AM] [Wink] Device Added - Group sensor_pods, ID 65791, Name Sensor [12/16/2016, 3:37:12 AM] [Wink] Device Ignored Not In HomeKit - Group hubs, ID 120872, Name Tapt Smart Switch [12/16/2016, 3:37:12 AM] [Wink] Device Added - Group binary_switches, ID 61095, Name Office [12/16/2016, 3:37:12 AM] [Wink] Device Ignored Not In HomeKit - Group hubs, ID 120872, Name Bottom Tapt Button [12/16/2016, 3:37:12 AM] [Wink] Device Ignored Not In HomeKit - Group hubs, ID 120872, Name Top Tapt Button [12/16/2016, 3:37:12 AM] [Wink] Device Added - Group binary_switches, ID 207285, Name Backlight [12/16/2016, 3:37:12 AM] [Wink] Device Ignored Not In HomeKit - Group hubs, ID undefined, Name Egg Minder [12/16/2016, 3:37:12 AM] [Wink] Device Ignored Not In HomeKit - Group hubs, ID undefined, Name Camera [12/16/2016, 3:37:12 AM] [Wink] Initializing platform accessory 'Lamp'... [12/16/2016, 3:37:12 AM] [Wink] Initializing platform accessory 'Guest Bedroom'... [12/16/2016, 3:37:12 AM] [Wink] Initializing platform accessory 'Camera Switch'... [12/16/2016, 3:37:12 AM] [Wink] Initializing platform accessory 'Living Room'... [12/16/2016, 3:37:12 AM] [Wink] Initializing platform accessory 'Front Door Sensor'... [12/16/2016, 3:37:12 AM] [Wink] Initializing platform accessory 'Back Door Sensor'... [12/16/2016, 3:37:12 AM] [Wink] Initializing platform accessory 'Sensor'... [12/16/2016, 3:37:12 AM] [Wink] Initializing platform accessory 'Office'... [12/16/2016, 3:37:12 AM] [Wink] Initializing platform accessory 'Backlight'... [12/16/2016, 3:37:13 AM] Software version for Hallway Thermostat is: 5.6-7 [12/16/2016, 3:37:13 AM] Temperature unit for Hallway Thermostat is: Fahrenheit [12/16/2016, 3:37:13 AM] Current temperature for Hallway Thermostat is: 67 F [12/16/2016, 3:37:13 AM] Current humidity for Hallway Thermostat is: 45% [12/16/2016, 3:37:13 AM] Target temperature for Hallway Thermostat is: 67 F [12/16/2016, 3:37:13 AM] Target heating for Hallway Thermostat is: Heating/Cooling [12/16/2016, 3:37:13 AM] Away for Hallway Thermostat is: 0 [12/16/2016, 3:37:13 AM] Initializing platform accessory 'Hallway Thermostat'... Scan this code with your HomeKit App on your iOS device to pair with Homebridge:

┌────────────┐     
│ 031-45-154 │     
└────────────┘     

[12/16/2016, 3:37:14 AM] Homebridge is running on port 51826. [12/16/2016, 3:37:14 AM] [My Computer] Pinging undefined [12/16/2016, 3:37:17 AM] [My Computer] Call get for undefined, return false [12/16/2016, 3:37:19 AM] [My Computer] Pinging undefined [12/16/2016, 3:37:24 AM] [My Computer] Pinging undefined [12/16/2016, 3:37:26 AM] [My Computer] Call get for undefined, return false [12/16/2016, 3:37:26 AM] [My Computer] Set value for My Computer from undefined to 1 [12/16/2016, 3:37:26 AM] [My Computer] Attempting to wake undefined (undefined) [12/16/2016, 3:37:26 AM] [My Computer] Updating state for undefined false -> true [12/16/2016, 3:37:26 AM] [My Computer] Call get for undefined, return true /usr/local/lib/node_modules/homebridge-wol/node_modules/wake_on_lan/wake_on_lan.js:12 if (mac.length == 2 * mac_bytes + (mac_bytes - 1)) { ^

TypeError: Cannot read property 'length' of undefined at Object.exports.createMagicPacket (/usr/local/lib/node_modules/homebridge-wol/node_modules/wake_on_lan/wake_on_lan.js:12:10) at Object.exports.wake (/usr/local/lib/node_modules/homebridge-wol/node_modules/wake_on_lan/wake_on_lan.js:46:30) at wake (/usr/local/lib/node_modules/homebridge-wol/index.js:69:9) at Computer. (/usr/local/lib/node_modules/homebridge-wol/index.js:41:11) at emitMany (events.js:108:13) at emit (events.js:182:7) at Characteristic.setValue (/usr/local/lib/node_modules/hap-nodejs/lib/Characteristic.js:155:10) at Bridge. (/usr/local/lib/node_modules/hap-nodejs/lib/Accessory.js:740:22) at Array.forEach (native) at Bridge.Accessory._handleSetCharacteristics (/usr/local/lib/node_modules/hap-nodejs/lib/Accessory.js:685:8) at emitMany (events.js:108:13) at HAPServer.emit (events.js:182:7) at HAPServer._handleCharacteristics (/usr/local/lib/node_modules/hap-nodejs/lib/HAPServer.js:972:10) at HAPServer. (/usr/local/lib/node_modules/hap-nodejs/lib/HAPServer.js:209:39) at emitNone (events.js:67:13) at IncomingMessage.emit (events.js:166:7) at endReadableNT (_stream_readable.js:905:12) at nextTickCallbackWith2Args (node.js:437:9) at process._tickCallback (node.js:351:17)

Parser didn't show any errors for the updated script, and it still crashes when trying to wake the PC.

AlexGustafsson commented 7 years ago

It definitely seems to be some error regarding the configuration, however, your configuration has no obvious errors. The homebridge-wol simply never gets the values from the configuration, which it expects it does, making it use non-existing values. I'll try to see if I can replicate this somehow and make homebridge-wol more resilient against configuration mishaps. Until then, exclude homebridge-wol from your accessories. I'm sorry for the inconvenience. I'll try to get it done today.

Finch106 commented 7 years ago

No problem! I pasted the entire configuration below my homebridge mac, etc so it was just the accessories (Computers) and that was the result. I did enter my IP and mac. I placed the entire confing in the parser and it was clean, and in the json validatior. Even with homebridge-wol in place, everything works unless i tap the on button for computer.

blubber commented 7 years ago

@Gamer106 I have removed those oauth credentials from the config that you posted, I suggest you take care to remove private information from configuration files before you post them in the future :).

AlexGustafsson commented 7 years ago

I can't seem replicate the problem that you're facing.

What version of Homebridge are you running? homebridge --version

What version of Node are you running? node --version

What version of homebridge-wol are you using? npm list -g homebridge-wol

AlexGustafsson commented 7 years ago

I've recently refactored homebridge-wol. The new version handles configuration mistakes more gracefully. Could you try it out, @Gamer106? Read #13 for more information if so. If the issue persists, please open the issue again, but until then this issue will be closed.