grover / homebridge-ranger

A HomeKit range extender for Bluetooth Low Energy (BLE) accessories.
MIT License
73 stars 15 forks source link

UnhandledPromiseRejectionWarning: Error: HAP-BLE request failed with status 4 #9

Closed samgeorge closed 5 years ago

samgeorge commented 5 years ago

[2018-11-11 10:12:24] [Ranger] Discovered GATT services and characteristics of Eve Thermo 0514 [2018-11-11 10:12:24] [Ranger] Connected to Eve Thermo 0514 (node:1732) UnhandledPromiseRejectionWarning: Error: HAP-BLE request failed with status 4 at HapExecutor._getResponsePayload (/usr/lib/node_modules/homebridge-ranger/src/hap/HapExecutor.js:135:13) at HapExecutor._executeCommand (/usr/lib/node_modules/homebridge-ranger/src/hap/HapExecutor.js:64:34) at (node:1732) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:1732) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. [2018-11-11 10:12:45] [Ranger] Reported reachability for Eve Thermo 0514: true

samgeorge commented 5 years ago

Debugging by adding "throw new Error(packet.readUInt8())" to line 135

returns (node:2275) UnhandledPromiseRejectionWarning: Error: 2

Jc2k commented 5 years ago

I get the same error with an Eve Energy. If i'm reading the code right - is this error 4 as in invalid instance id? From the spec: 'The HAP Request\'s characteristic Instance Id did not match the addressed characteristic\'s instance Id'

Jc2k commented 5 years ago

So are we hitting https://github.com/grover/homebridge-ranger/commit/bc41917df3ba4cd56f9a1bb402d9463cf448952b but our node version can't handle the catch?

Jc2k commented 5 years ago

Yep - all the throws in HapExecute are no good because they are called from an async function. I stuck a big try {} around most of the packet reading/parsing code and now it skips the non-standard characteristics and pairs

Jc2k commented 5 years ago

Or not - it tries to pair, and eventually starts without pairing, instead probing the device without a secure session, which fails with error 5.

Luehrsen commented 5 years ago

Yeah, this is affecting me to at the moment with an Eve Energy.

achirus-code commented 5 years ago

Same here with Eve Window/Door. :(

Luehrsen commented 5 years ago

It's strange to meet the same people in different repositories. :D @TillmannD (b4f)

achirus-code commented 5 years ago

It's strange to meet the same people in different repositories. :D @TillmannD (b4f)

the world is smaller than you think :))

BTT: I could fix my issue by going to Node 9.10. Its easy to change cause ranger runs on my Pi in a dockercontainer. ;-)

palasinio commented 5 years ago

Is there any workaround for nondevelopers?

hansvangent commented 5 years ago

Running into the same problem here with my Eve Energy:

Dec 29 12:48:42 unifipi homebridge[29683]: (node:29683) UnhandledPromiseRejectionWarning: Error: HAP-BLE request failed with status 4 Dec 29 12:48:42 unifipi homebridge[29683]: at HapExecutor._getResponsePayload (/opt/node-v9.3.0-linux-armv7l/lib/node_modules/homebridge-ranger/src/hap/HapExecutor.js:135:13) Dec 29 12:48:42 unifipi homebridge[29683]: at HapExecutor._executeCommand (/opt/node-v9.3.0-linux-armv7l/lib/node_modules/homebridge-ranger/src/hap/HapExecutor.js:64:34) Dec 29 12:48:42 unifipi homebridge[29683]: at <anonymous> Dec 29 12:48:42 unifipi homebridge[29683]: (node:29683) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) Dec 29 12:48:42 unifipi homebridge[29683]: (node:29683) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Running Node 9.3.0 @TillmannD did you downgrade from 9.3.0 to 9.10 or did you upgrade from an older version?

edit: at first I thought it was something because of it being the second device in the config.json but even when I change it and remove my other Eve device (a thermo) it still gives me the same error message. Anyone found a potential solution, or should I downgrade my Node to 9.10 as suggested by @TillmannD

palasinio commented 5 years ago

Can anyone confirm Node 9.10 working (with Eve Thermo)? I downgraded to Node 8 without success.

achirus-code commented 5 years ago

Hey, sorry for the late reply. I run homebridge on my pi in a dockercompose.
As I changed the main library to "arm32v7/node:9.10.0-stretch" I don't see the error anymore on Eve window.

BR

gsi095 commented 5 years ago

Hi TillmanD,

Im new to running apps in docker, how do you do that?

When I install ranger it homebridge goes into loop and wont run

Thanks Dave

palasinio commented 5 years ago

Hi, I didn't got it work with node 8.x, node 9.3.0, node 9.10.1, node 10.y. This is what I got (Eve Thermo 2017):

[2019-1-2 01:55:41] [Ranger] Initializing Ranger platform... [2019-1-2 01:55:41] [Ranger] Ranger Platform Plugin Loaded [2019-1-2 01:55:41] [Ranger] Found device in config: "Eve Thermo 7890" [2019-1-2 01:55:41] [Ranger] Waiting for accessory: Eve Thermo 7890 [2019-1-2 01:55:41] [Ranger] Not all accessories have their devices. Not publishing yet. [2019-1-2 01:55:41] Loading 0 accessories... [2019-1-2 01:55:41] [Ranger] DidFinishLaunching [2019-1-2 01:55:41] [Ranger] Starting to scan for BLE HomeKit accessories [2019-1-2 01:55:41] [Ranger] Found paired accessory Eve Energy 1234 address=d8:42:aa:2a:xx:cc rssi=-87dB [2019-1-2 01:55:43] [Ranger] Found paired accessory Eve Thermo 4567 address=ef:hh:8e:zz:vv:99 rssi=-88dB [2019-1-2 01:55:43] [Ranger] Found unpaired accessory Eve Thermo 7890 address=d5:qq:b4:ww:yy:f1 rssi=-69dB [2019-1-2 01:55:43] [Ranger] Accessory 'Eve Thermo 7890' found. [2019-1-2 01:55:44] [Ranger] Scanning stopped externally. Restarting in 2s. [2019-1-2 01:55:44] [Ranger] Discovered services. [2019-1-2 01:55:45] [Ranger] Discovered GATT services and characteristics of Eve Thermo 7890 [2019-1-2 01:55:45] [Ranger] Connected to Eve Thermo 7890 (node:25189) UnhandledPromiseRejectionWarning: Error: HAP-BLE request failed with status 4 at HapExecutor._getResponsePayload (/usr/local/lib/node_modules/homebridge-ranger/src/hap/HapExecutor.js:135:13) at HapExecutor._executeCommand (/usr/local/lib/node_modules/homebridge-ranger/src/hap/HapExecutor.js:64:34) at (node:25189) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:25189) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. [2019-1-2 01:55:53] [Ranger] Found paired accessory Eve Energy 6543 address=c5:53:zz:qq:88:66 rssi=-99dB [2019-1-2 01:56:21] [Ranger] Eve Thermo 7890: First advertisement after 38119ms. [2019-1-2 01:56:21] [Ranger] Disconnected from Eve Thermo 7890 [2019-1-2 01:56:29] [Ranger] Reported reachability for Eve Thermo 7890: true [2019-1-2 03:38:15] [Ranger] Device Eve Thermo 7890 issued a disconnected event.

Edited for appearance. Hombridge won't start. No further events in log after 3:38.

hansvangent commented 5 years ago

I downgraded to "node-v9.10.0-linux-armv7l.tar.xz" as the node version, still seeing this:

Jan 02 20:13:18 unifipi homebridge[6829]: (node:6829) UnhandledPromiseRejectionWarning: Error: HAP-BLE request failed with status 4 Jan 02 20:13:18 unifipi homebridge[6829]: at HapExecutor._getResponsePayload (/opt/node-v9.10.0-linux-armv7l/lib/node_modules/homebridge-ranger/src/hap/HapExecutor.js:135:13) Jan 02 20:13:18 unifipi homebridge[6829]: at HapExecutor._executeCommand (/opt/node-v9.10.0-linux-armv7l/lib/node_modules/homebridge-ranger/src/hap/HapExecutor.js:64:34) Jan 02 20:13:18 unifipi homebridge[6829]: at <anonymous> Jan 02 20:13:18 unifipi homebridge[6829]: (node:6829) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) Jan 02 20:13:18 unifipi homebridge[6829]: (node:6829) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

It's driving me crazy :-/

hansvangent commented 5 years ago

Mmm I think it has something to do with Eve, I updated my Thermo to the latest firmware and now it gives me the same error, will contact their support as well see what they can tell me.

Maybe @grover has an idea to fix this?

Jc2k commented 5 years ago

This is the commit that causes the Eve issue:

https://github.com/grover/homebridge-ranger/commit/bc41917df3ba4cd56f9a1bb402d9463cf448952b

I don't know on what version of JS thats valid, and which version its not but apparently its a common trap when writing async JS? I'm not a JS developer, I had hoped someone on here would be, but it seems like getting rid of the try/catch there would fix the promise rejection? Apparently you can catch and then await. Someone could try:

 const signature = await device.run(op).catch((err) => console.log(err));
 console.log(`Service signature: ${JSON.stringify(signature)}`);

I'm guessing - I dont have the VM where i was playing with this.

Eve support probably can't help get us past this hurdle, this is definitely just a code bug that we need to fix. The other error I see in these logs a lot is

Error: HAP-BLE request failed with status 4

This stands for:

'The HAP Request's characteristic Instance Id did not match the addressed characteristic's instance Id'

Thats because homebridge-ranger is (AFAICT) speaking the homekit protocol to a non-homekit extension on the bluetooth device. It would be better if it didn't even try to poke non-homekit parts of the bluetooth device but when it does (as shown by the error message) we are just triggering an error.

Upgrading the firmware probably added extra features that only work in the Eve app, not via HomeKit, and thats why the upgrade made it break for you on the other device all of a sudden. So not sure Eve support will be able to help.

palasinio commented 5 years ago

Sorry, that’s to hard for me: https://stackoverflow.com/questions/39716569/nodejs-unhandledpromiserejectionwarning

Jc2k commented 5 years ago

The other thing to try is to edit here:

for (let svc of serviceSignature) {
    const op = new ServiceSignatureReadRequest(svc.address, svc.cid);
    console.log(svc.cid);
    try {
      const signature = await device.run(op);
      console.log(`Service signature: ${JSON.stringify(signature)}`);
    }
    catch (e) {
      console.log(`Failed to read service signature: ${util.inspect(e)}`);
    }
}

This will still error but it will print a bunch of cids. I think the last one it prints will be the none-homekit one that is causing the error. We want to build a list of them, and then skip them. To do this we can do:

var ignore = ["cid-you-printed", "other-cid-you-found"];

for (let svc of serviceSignature) {
    const op = new ServiceSignatureReadRequest(svc.address, svc.cid);
    console.log(svc.cid);

    // skip known incompatible service characteristics
    if (ignore.includes(svc.cid)) {
        continue;
    }

    try {
      const signature = await device.run(op);
      console.log(`Service signature: ${JSON.stringify(signature)}`);
    }
    catch (e) {
      console.log(`Failed to read service signature: ${util.inspect(e)}`);
    }
}

You will have to do this multiple times, each time you block a non-homekit characteristic id you should get a different one the next time. Eventually you will have blocked all the Eve non-homekit ones and it might start working... Might...

But I dont have an environment to try any of this in, so good luck!

palasinio commented 5 years ago

Wow!

Sounds great. So with this: const signature = await device.run(op).catch((err) => console.log(err)); console.log(Service signature: ${JSON.stringify(signature)}); the lines 303/304 should be replaced? How can I do that as a non developer? Can I edit the files in the local modules directory and do a npm rebuild on my pi?

Jc2k commented 5 years ago

Sorry @palasinio i'm not enough of a javascript dev to say! For figuring this out I /think/ editing the local module files directly is enough, and you shouldnt even have to touch npm?

And yes, just replace the existing ones!

palasinio commented 5 years ago

Okay - big thx @Jc2k - I‘ll try your ideas the next days if the kids let me.

hansvangent commented 5 years ago

@palasinio same here, although I'm even less of a javascript dev. Hopefully will find some time as well, and will report back looking forward to your results in the meantime as well.

palasinio commented 5 years ago

@Jc2k 🥇 your're the best!

Really interesting: I found a "homebridge-ranger-0.2.0.tgz" in the "/usr/local/lib/node_modules/homebridge-ranger" folder.

Next I wanted to edit "AccessoryDatabase.js" in "/usr/local/lib/node_modules/homebridge-ranger/src/hap".

Surprisingly the content didn't look like here.

It looked that way w/o try/catch:

  for (let svc of serviceSignature) {
    const op = new ServiceSignatureReadRequest(svc.address, svc.cid);
    const signature = await device.run(op);
    console.log(`Service signature: ${JSON.stringify(signature)}`);
  }

Exchanging it with the "try/catch" thing didn't change behaviour. Your first guess does: const signature = await device.run(op).catch((err) => console.log(err)); (I didn't expect Node to be something like a BASIC interpreter).

While pairing I got three undefined cids:

Jan 03 15:57:54 raspberrypi homebridge[5135]: ********** CID: 11 *********************************************************************
Jan 03 15:57:54 raspberrypi homebridge[5135]: Error: HAP-BLE request failed with status 4
Jan 03 15:57:54 raspberrypi homebridge[5135]:     at HapExecutor._getResponsePayload (/usr/local/lib/node_modules/homebridge-ranger/src/hap/HapExecutor.js:135:13)
Jan 03 15:57:54 raspberrypi homebridge[5135]:     at HapExecutor._executeCommand (/usr/local/lib/node_modules/homebridge-ranger/src/hap/HapExecutor.js:64:34)
Jan 03 15:57:54 raspberrypi homebridge[5135]:     at <anonymous>
Jan 03 15:57:54 raspberrypi homebridge[5135]: Service signature: undefined
Jan 03 15:57:54 raspberrypi homebridge[5135]: ********** CID: 27 *********************************************************************
Jan 03 15:57:54 raspberrypi homebridge[5135]: Error: HAP-BLE request failed with status 4
Jan 03 15:57:54 raspberrypi homebridge[5135]:     at HapExecutor._getResponsePayload (/usr/local/lib/node_modules/homebridge-ranger/src/hap/HapExecutor.js:135:13)
Jan 03 15:57:54 raspberrypi homebridge[5135]:     at HapExecutor._executeCommand (/usr/local/lib/node_modules/homebridge-ranger/src/hap/HapExecutor.js:64:34)
Jan 03 15:57:54 raspberrypi homebridge[5135]:     at <anonymous>
Jan 03 15:57:54 raspberrypi homebridge[5135]: Service signature: undefined
Jan 03 15:57:54 raspberrypi homebridge[5135]: ********** CID: 44 *********************************************************************
Jan 03 15:57:54 raspberrypi homebridge[5135]: Error: HAP-BLE request failed with status 4
Jan 03 15:57:54 raspberrypi homebridge[5135]:     at HapExecutor._getResponsePayload (/usr/local/lib/node_modules/homebridge-ranger/src/hap/HapExecutor.js:135:13)
Jan 03 15:57:54 raspberrypi homebridge[5135]:     at HapExecutor._executeCommand (/usr/local/lib/node_modules/homebridge-ranger/src/hap/HapExecutor.js:64:34)
Jan 03 15:57:54 raspberrypi homebridge[5135]:     at <anonymous>
Jan 03 15:57:54 raspberrypi homebridge[5135]: Service signature: undefined

But this didn't prevent hombridge to start. Once paired the undefined cids didn't show up again and my "Eve Thermo" (2017, FW 1.2.7 (1132)) is running through Ranger.

So there is only one line to edit,

Many, many THX.

How can we continue? Is a change request in GIT a "pull" Request? have you ever done this?

Jc2k commented 5 years ago

GitHub calls it a pull request indeed. And you are right it’s probably the place to start here. I’ve done it quite a bit for python projects. Do you want to have a go?

hansvangent commented 5 years ago

@palasinio you've only edited this line:

const signature = await device.run(op);

to this line:

const signature = await device.run(op).catch((err) => console.log(err));

Almost at the end of the document? I just did the same thing myself, and I'm seeing the same error still in the log file for my Eve Energy.

However, this seems to have fixed it for my Eve Thermo, so I'm a little bit closer.

Second time trying to start homebridge however it hangs again because it sees an unpaired device (my Eve Energy) and doens't continue.

palasinio commented 5 years ago

@jcvangent yes, I only edited this line and as you can see two posts above I get still this error: "Error: HAP-BLE request failed with status 4", but Homebridge starts. This is my first time with Ranger, so I'm not very experienced. Can you start Ranger with only one Energy in the devices part ans see, what the log says and if homebridge starts? I get my Energy back, when the christmastree leaves ;)

palasinio commented 5 years ago

@Jc2k I just never done something like this before. Lets see whats up @jcvangent and I'll try to start my first "pull" ;).

hansvangent commented 5 years ago

I only added one Eve Energy, HomeBridge is not starting and the log says this:

Jan 03 21:19:39 unifipi homebridge[5790]: [2019-1-3 21:19:39] [Ranger] noble failed to establish a BLE connection to Eve Energy Jan 03 21:19:39 unifipi homebridge[5790]: (node:5790) UnhandledPromiseRejectionWarning: Error: noble failed to establish a BLE connection to Eve Energy Jan 03 21:19:39 unifipi homebridge[5790]: at HapBleDevice.connect (/opt/node-v9.10.0-linux-armv7l/lib/node_modules/homebridge-ranger/src/hap/HapBleDevice.js:75:13) Jan 03 21:19:39 unifipi homebridge[5790]: at Jan 03 21:19:39 unifipi homebridge[5790]: (node:5790) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) Jan 03 21:19:39 unifipi homebridge[5790]: (node:5790) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. Jan 03 21:19:43 unifipi homebridge[5790]: [2019-1-3 21:19:43] [Ranger] Reported reachability for Eve Energy: true

After that nothing in the logfile so it doesn't continue. I also tried downloading the master files from git here and use those (there are 5 commits already done to the git but not merged yet so hence you saw the difference in the file) but that code isn't working at all.

palasinio commented 5 years ago

Hi @jcvangent , seems to be the same topic in a different file? I wondered already, how @Jc2k concluded from "HapExecutor.js" to "AccessoryDatabase.js" - there must be kind of includes. The error is similar, cause its not captured. I guess, if we find the right file/position, its the same change nescessary.

if you run this: /usr/local/lib/node_modules/homebridge-ranger/src/hap $ grep -rnw -e 'await' you get something like this:

HapCharacteristicAccessor.js:23:      const result = await this._executor.run(request);
HapCharacteristicAccessor.js:44:      const result = await this._executor.run(request);
HapExecutor.js:35:      await this._establishSecureConnection();
HapExecutor.js:36:      const result = await this._executeCommand(cmd);
HapExecutor.js:59:      await this._device.write(c, encryptedPacket);
HapExecutor.js:62:      let rxPacket = await this._device.read(c);
HapExecutor.js:68:        rxPacket = await this._device.read(c);
HapExecutor.js:174:      newConnection = await this._connectToBleDevice();
HapExecutor.js:175:      isConnected = await this._establishSessionSecurity();
HapExecutor.js:196:      await this._device.connect();
HapExecutor.js:216:        this._previousSessionKeys = await this._executeCommand(pairVerify);
HapExecutor.js:233:        await this._device.disconnect();
AccessoryDatabase.js:81:    accessoryDatabase = await loadFromFile(filePath);
AccessoryDatabase.js:94:    await device.connect();
AccessoryDatabase.js:95:    accessoryDatabase = await generateAccessoryDatabase(device);
AccessoryDatabase.js:99:    await device.connect();
AccessoryDatabase.js:101:    accessoryDatabase.services = await generateServices(device);
AccessoryDatabase.js:107:    await accessoryDatabase.save();
AccessoryDatabase.js:143:  const hapServices = await generateServices(device);
AccessoryDatabase.js:168:  const cids = await discoverCharacteristicIDs(allCharacteristics);
AccessoryDatabase.js:169:  const characteristics = await discoverCharacteristicMetadata(device, cids);
AccessoryDatabase.js:170:  const metadata = await discoverServiceMetadata(device, cids);
AccessoryDatabase.js:218:      const instanceIdDescriptor = await discoverInstanceIDDescriptor(c.characteristic);
AccessoryDatabase.js:225:        cid: await readDescriptor(instanceIdDescriptor),
AccessoryDatabase.js:281:    const signature = await device.run(r);
AccessoryDatabase.js:303:    const signature = await device.run(op).catch((err) => console.log(err));
HapBleDevice.js:69:      await this._connect();
HapBleDevice.js:70:      await this._sleep(100);
HapBleDevice.js:78:    await this._discoverServicesAndCharacteristics();
HapBleDevice.js:108:    await this._disconnect();

Maybe there is more to do ;) i.e. here: HapBleDevice.js:78: await this._discoverServicesAndCharacteristics();

Please add the same here: .catch((err) => console.log(err));

Edit: Or better line 69 - maybe (HapBleDevice.connect) -- sounds weird... Is this device listed as paired or unpaired when the devices section is empty?

palasinio commented 5 years ago

@jcvangent What "Eve Energy" do you have exactly, so I can test, when the tree is away (maybe sunday)?

hansvangent commented 5 years ago

@palasinio There is only one no?

https://www.evehome.com/en/eve-energy

Using the latest firmware.

hansvangent commented 5 years ago

@palasinio yes it is listed as unpaired. I unpaired it as per the instruction in the manual.

This is the output

root@unifipi:/opt/node/lib/node_modules/homebridge-ranger/src/hap# grep -rnw -e 'await' HapBleDevice.js:69: await this._connect(); HapBleDevice.js:70: await this._sleep(100); HapBleDevice.js:78: await this._discoverServicesAndCharacteristics(); HapBleDevice.js:108: await this._disconnect(); HapExecutor.js:35: await this._establishSecureConnection(); HapExecutor.js:36: const result = await this._executeCommand(cmd); HapExecutor.js:59: await this._device.write(c, encryptedPacket); HapExecutor.js:62: let rxPacket = await this._device.read(c); HapExecutor.js:68: rxPacket = await this._device.read(c); HapExecutor.js:174: newConnection = await this._connectToBleDevice(); HapExecutor.js:175: isConnected = await this._establishSessionSecurity(); HapExecutor.js:196: await this._device.connect(); HapExecutor.js:216: this._previousSessionKeys = await this._executeCommand(pairVerify); HapExecutor.js:233: await this._device.disconnect(); HapCharacteristicAccessor.js:23: const result = await this._executor.run(request); HapCharacteristicAccessor.js:44: const result = await this._executor.run(request); AccessoryDatabase.js:81: accessoryDatabase = await loadFromFile(filePath); AccessoryDatabase.js:94: await device.connect(); AccessoryDatabase.js:95: accessoryDatabase = await generateAccessoryDatabase(device); AccessoryDatabase.js:99: await device.connect(); AccessoryDatabase.js:101: accessoryDatabase.services = await generateServices(device); AccessoryDatabase.js:107: await accessoryDatabase.save(); AccessoryDatabase.js:143: const hapServices = await generateServices(device); AccessoryDatabase.js:168: const cids = await discoverCharacteristicIDs(allCharacteristics); AccessoryDatabase.js:169: const characteristics = await discoverCharacteristicMetadata(device, cids); AccessoryDatabase.js:170: const metadata = await discoverServiceMetadata(device, cids); AccessoryDatabase.js:218: const instanceIdDescriptor = await discoverInstanceIDDescriptor(c.characteristic); AccessoryDatabase.js:225: cid: await readDescriptor(instanceIdDescriptor), AccessoryDatabase.js:281: const signature = await device.run(r); AccessoryDatabase.js:301: //const signature = await device.run(op); AccessoryDatabase.js:302: const signature = await device.run(op).catch((err) => console.log(err));

So only this line:

HapBleDevice.js:69: await this._connect();

Should be changed to:

await this._connect().catch((err) => console.log(err));

?

edit: readability of console output

hansvangent commented 5 years ago

When I do that, I get the following:

Jan 03 22:08:10 unifipi homebridge[8298]: (node:8298) UnhandledPromiseRejectionWarning: Error: noble failed to establish a BLE connection to Eve Energy Jan 03 22:08:10 unifipi homebridge[8298]: at HapBleDevice.connect (/opt/node-v9.10.0-linux-armv7l/lib/node_modules/homebridge-ranger/src/hap/HapBleDevice.js:75:13) Jan 03 22:08:10 unifipi homebridge[8298]: at Jan 03 22:08:10 unifipi homebridge[8298]: (node:8298) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) Jan 03 22:08:10 unifipi homebridge[8298]: (node:8298) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. Jan 03 22:08:14 unifipi homebridge[8298]: [2019-1-3 22:08:14] [Ranger] Reported reachability for Eve Energy: true

palasinio commented 5 years ago

Give it a try; there are 4 lines in this file - as far I can see 69, 70, 78 and 108? After unpairing check if the hardwareaddress is the same.

hansvangent commented 5 years ago

Okay done all of them, moved my Raspberry Pi closer to the Eve Energy to make the paring go easier.

The first time it showed me the error messages, but it ended up pairing by the looks of it, it shows up in my Eve app. Then I added the Thermo as well in the config, it worked and showed up in the Eve app.

I can see both devices in the "ranger" directory of my config.

However, both devices are not controllable via the Eve app and show up as unreachable in the home app. The error I can read in the Eve is is "The bridged accessory is not reachable. Make sure Wi-Fi is enabled and try again." << which sounds a bit weird since there is no Wi-Fi in the Eve devices.

palasinio commented 5 years ago

Hm, so both devices are paired now and show up in the Eve app? That’s a big step forward, I think. Can you control the devices if you have only one in the config? Ranger is not really fast. Do you have a RaspberryPi Zero? Maybe you have to play with the advanced parameters in the config (reachabilityTimeout).

hansvangent commented 5 years ago

Indeed already a big step forward!

Using a Raspberry Pi 3 model B+ here and already added the following to the config:

"reachability": "true",
   "reachabilityTimeout": "120000",
    "rssi": "false"

To make it deal with the timeouts etc. Only one device doesn't let me control it either.

palasinio commented 5 years ago

Do you get „pair verify request“ in the log? Can you see Ranger talking with your device? I saw, that the RPI bluetooth device is not the most reliable one and sometimes needs to be reset.

hansvangent commented 5 years ago

I just restarted homebridge to see what happens on start, this is the logfile:

Jan 04 15:07:28 unifipi homebridge[14578]: [2019-1-4 15:07:28] Loading 1 platforms... Jan 04 15:07:28 unifipi homebridge[14578]: [2019-1-4 15:07:28] [Ranger] Initializing Ranger platform... Jan 04 15:07:28 unifipi homebridge[14578]: [2019-1-4 15:07:28] [Ranger] Ranger Platform Plugin Loaded Jan 04 15:07:28 unifipi homebridge[14578]: [2019-1-4 15:07:28] [Ranger] Found device in config: "Eve Energy" Jan 04 15:07:28 unifipi homebridge[14578]: [2019-1-4 15:07:28] [Ranger] Waiting for accessory: Eve Energy Jan 04 15:07:28 unifipi homebridge[14578]: [2019-1-4 15:07:28] [Ranger] Not all accessories have their devices. Not publishing yet. Jan 04 15:07:28 unifipi homebridge[14578]: [2019-1-4 15:07:28] [Ranger] DidFinishLaunching Jan 04 15:07:28 unifipi homebridge[14578]: [2019-1-4 15:07:28] [Ranger] Starting to scan for BLE HomeKit accessories Jan 04 15:07:31 unifipi homebridge[14578]: [2019-1-4 15:07:31] [Ranger] Found paired accessory Eve address=XX:XX:XX:XX:XX:XX rssi=-41dB Jan 04 15:07:32 unifipi homebridge[14578]: [2019-1-4 15:07:32] [Ranger] Found paired accessory Eve Energy XXXX address=XX:XX:XX:XX:XX:XX rssi=-91dB Jan 04 15:07:32 unifipi homebridge[14578]: [2019-1-4 15:07:32] [Ranger] Accessory 'Eve Energy ' found. Jan 04 15:07:32 unifipi homebridge[14578]: [2019-1-4 15:07:32] [Ranger] Connecting to Eve Energy Jan 04 15:07:32 unifipi homebridge[14578]: [2019-1-4 15:07:32] [Ranger] Scanning stopped externally. Restarting in 2s. Jan 04 15:07:34 unifipi homebridge[14578]: [2019-1-4 15:07:34] [Ranger] Discovered services. Jan 04 15:07:36 unifipi homebridge[14578]: [2019-1-4 15:07:36] [Ranger] Discovered GATT services and characteristics of Eve Energy Jan 04 15:07:36 unifipi homebridge[14578]: [2019-1-4 15:07:36] [Ranger] Connected to Eve Energy Jan 04 15:07:36 unifipi homebridge[14578]: [2019-1-4 15:07:36] [Ranger] Failed to retrieve characteristic Manufacturer for accessory information. Jan 04 15:07:36 unifipi homebridge[14578]: [2019-1-4 15:07:36] [Ranger] Failed to retrieve characteristic Model for accessory information. Jan 04 15:07:36 unifipi homebridge[14578]: [2019-1-4 15:07:36] [Ranger] Failed to retrieve characteristic Name for accessory information. Jan 04 15:07:37 unifipi homebridge[14578]: [2019-1-4 15:07:37] [Ranger] Failed to retrieve characteristic Serial Number for accessory information. Jan 04 15:07:37 unifipi homebridge[14578]: [2019-1-4 15:07:37] [Ranger] Failed to retrieve characteristic Firmware Revision for accessory information. Jan 04 15:07:37 unifipi homebridge[14578]: [2019-1-4 15:07:37] [Ranger] Failed to retrieve characteristic Hardware Revision for accessory information. Jan 04 15:07:37 unifipi homebridge[14578]: [2019-1-4 15:07:37] [Ranger] Publishing BLE service E863F007-079E-48FF-8F27-9C2605A29F52 via proxy Jan 04 15:07:38 unifipi homebridge[14578]: [2019-1-4 15:07:38] [Ranger] Publishing BLE service 00000047-0000-1000-8000-0026BB765291 via proxy Jan 04 15:07:38 unifipi homebridge[14578]: [2019-1-4 15:07:38] [Ranger] Initializing platform accessory 'Eve Energy'...

====

==== Jan 04 15:07:38 unifipi homebridge[14578]: [2019-1-4 15:07:38] Homebridge is running on port 52827. Jan 04 15:08:15 unifipi homebridge[14578]: [2019-1-4 15:08:15] [Ranger] Disconnected from Eve Energy Jan 04 15:08:17 unifipi homebridge[14578]: [2019-1-4 15:08:17] [Ranger] Eve Energy: rrsi=-92dB Jan 04 15:08:20 unifipi homebridge[14578]: [2019-1-4 15:08:20] [Ranger] Reported reachability for Eve Energy: true Jan 04 15:08:20 unifipi homebridge[14578]: [2019-1-4 15:08:20] [Ranger] Connecting to Eve Energy Jan 04 15:08:23 unifipi homebridge[14578]: [2019-1-4 15:08:23] [Ranger] Scanning stopped externally. Restarting in 2s. Jan 04 15:08:23 unifipi homebridge[14578]: [2019-1-4 15:08:23] [Ranger] Discovered services. Jan 04 15:08:24 unifipi homebridge[14578]: [2019-1-4 15:08:24] [Ranger] Discovered GATT services and characteristics of Eve Energy Jan 04 15:08:24 unifipi homebridge[14578]: [2019-1-4 15:08:24] [Ranger] Connected to Eve Energy Jan 04 15:08:24 unifipi homebridge[14578]: [2019-1-4 15:08:24] [Ranger] Connected to Eve Energy Jan 04 15:08:55 unifipi homebridge[14578]: [2019-1-4 15:08:55] [Ranger] Disconnected from Eve Energy Jan 04 15:09:03 unifipi homebridge[14578]: [2019-1-4 15:09:03] [Ranger] Eve Energy: rrsi=-92dB Jan 04 15:09:04 unifipi homebridge[14578]: [2019-1-4 15:09:04] [Ranger] Eve Energy: rrsi=-90dB

And then it just continuous forever with that last line.

The RPI Bluetooth device is the one on my raspberry pi? How can I reset that one?

palasinio commented 5 years ago

https://raspberry-projects.com/pi/pi-operating-systems/raspbian/bluetooth/bluetooth-commands

Strange, there is nothing about pairing. I don‘t know, why yours behaves different to mine. If you empty the devices part in the Ranger config, are your two devices shown as paired? I‘ll try to connect an Energy the next days. My Thermo is still working with Ranger.

Btw, how did you get the latest commits? With the @master option? I wonder, why @grover stopped working on these things(?).

hansvangent commented 5 years ago

You mean remove from the /var/lib/homebridge/ranger directory? Will try that in the morning and let you know.

I downloaded the zip from the "clone or download" link on the top here > https://github.com/grover/homebridge-ranger, downloaded the zip. Replaced the directory in /opt/node/lib/node_modules/homebridge-ranger/src

Maybe @grover doesn't have a need for them anymore?

palasinio commented 5 years ago

I meant:

{
  "platform": "Ranger",
  "devices": []
}
hansvangent commented 5 years ago

Ah yeah:

Jan 04 20:12:11 unifipi homebridge[29012]: [2019-1-4 20:12:11] [Ranger] Found paired accessory Eve Thermo 4DB4 address=XX:XX:XX:XX:XX:XX rssi=-58dB Jan 04 20:12:11 unifipi homebridge[29012]: [2019-1-4 20:12:11] [Ranger] Found paired accessory Eve address=XX:XX:XX:XX:XX:XX rssi=-103dB

probably because they are also still in that ranger directory, let me remove them from there as well

hansvangent commented 5 years ago

Nope, even if I remove them from the /var/lib/homebridge/ranger directory AND from the config.json they still show up as paired.

palasinio commented 5 years ago

I hope, you still have the files from the Ranger directory. These are containing the pairing information.

I didn‘t really noticed this information from you:

„However, both devices are not controllable via the Eve app and show up as unreachable in the home app. The error I can read in the Eve is is "The bridged accessory is not reachable. Make sure Wi-Fi is enabled and try again." << which sounds a bit weird since there is no Wi-Fi in the Eve devices.“

That means, your homebridge is not reachable from your iPhone - for whatever reason. WiFi is not weird, because your PI talks Bluetooth to the Eve devices, while the home app or Eve app are talking via WiFi with homebridge.

Maybe using https://www.npmjs.com/package/homebridge-config-ui-x is a good option, because this can help to discover if Ranger works or not and if it’s maybe a problem between your iPhone and homebridge and you can see if homebridge is really running or not.

hansvangent commented 5 years ago

Yeah I just moved them temporarily to a different directory no worries ;-)

The only way I connect to my Raspberry Pi is using WiFi so that would seem strange to me. But checking out the https://www.npmjs.com/package/homebridge-config-ui-x now

hansvangent commented 5 years ago

I installed https://www.npmjs.com/package/homebridge-config-ui-x and everything seem to be working fine:

screenshot 2019-01-05 at 11 53 57

I also moved my Raspberry Pi and my AppleTV both to static ip addresses in my router config as per suggestion somewhere as well.

So that is not really the issue I think.

hansvangent commented 5 years ago

And when I run Homebridge with the "-I" option so I can see the accessories, I can see both devices as "off", even though I know for a fact that the Energy is on at the moment.

screenshot 2019-01-05 at 12 20 21

Also, my other accessories in the house are not visible on that tab, is that normal? Will it only show accessories that are connected to Homebridge?