Skip to content

Commit

Permalink
make WOL setup more resilient to platform (?) specific issues
Browse files Browse the repository at this point in the history
- HACK: TO BE FIXED properly as soon as core issue fully understood

  on macOs we get Error: send EADDRNOTAVAIL 255.255.255.255:9
  when sending the magic packets.

  targeting TV's address fixes that and WOL then works...

  OTOH this is not a general purpose solution as elsewhere we actually
  need to target 255.255.255.255 for WOL to work.

  issue spoted while chasing #90

- en passant src/upnpsub.ts renamed to src/networkUtils.ts

Signed-off-by: António Meireles <antonio.meireles@reformi.st>
  • Loading branch information
AntonioMeireles committed Jan 22, 2022
1 parent 301aa34 commit bec3768
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,17 @@ class VieramaticPlatformAccessory {
else if (nextState === this.Characteristic.Active.ACTIVE && this.userConfig.mac) {
this.log.info('sending WOL packets to awake TV')
// takes 1 sec (10 magic qpkts sent with 100ms interval)
await wakeOnLan(this.userConfig.mac, { address: this.device.address, packets: 10 })
try {
await wakeOnLan(this.userConfig.mac, { packets: 10 })
} catch {
// XXX on macOs above returning: Error: send EADDRNOTAVAIL 255.255.255.255:9
// setting TV's address fixes that and WOL then works...
// OTOH that is not a general purpose solution as elsewhere we actually need to
// target 255.255.255.255 for WOL to work
// XXX fully understand root issue here as this is too hackish...
this.log.warn('fallback WOL route. (%s instead of 255.255.255.255)', this.device.address)
await wakeOnLan(this.userConfig.mac, { address: this.device.address, packets: 10 })
}
// wait another sec for older sets with slowish CPUs
await sleep(1000)
await this.updateTVstatus(nextState)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/ui/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HomebridgePluginUiServer, RequestError } from '@homebridge/plugin-ui-utils'

import { Abnormal, Outcome } from '../helpers'
import { vieraFinder } from '../upnpsub'
import { vieraFinder } from '../networkUtils'
import { VieraAuth, VieraSpecs, VieraTV } from '../viera'

const enum UIServerRequestErrorType {
Expand Down
2 changes: 1 addition & 1 deletion src/viera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { decode } from 'html-entities'
import { InputVisibility } from './accessory'
import { Abnormal, EmptyObject, isEmpty, isValidIPv4, Ok, Outcome, prettyPrint } from './helpers'
import { xml2obj, xml } from './helpers.server'
import { UPnPSubscription } from './upnpsub'
import { UPnPSubscription } from './networkUtils'

// helpers and default settings
const AudioChannel: string = xml({ Channel: 'Master', InstanceID: 0 })
Expand Down

0 comments on commit bec3768

Please sign in to comment.