Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/restructure ble #167

Merged
merged 25 commits into from
Mar 8, 2021
Merged

Conversation

SweVictor
Copy link
Collaborator

@SweVictor SweVictor commented Feb 20, 2021

Separate device management and BLE channel handling. Clean up event subscriptions and clarify emits.

@SweVictor
Copy link
Collaborator Author

So - finally I'm through with my main thoughts on refactoring the code base. One place where state is stored, BLE handling separate, device state management separately.

SweVictor and others added 16 commits February 22, 2021 09:50
- Set max retry count to 10 since BLE loop will set channel to disconnected after 5 retries (or known unrecoverable errors)
- when using includeRoomsAsLights setting
- Make deviceRegistry states/lists immutable
- Set max retry count to 10 since BLE loop will set channel to disconnected after 5 retries (or known unrecoverable errors)
@icanos
Copy link
Owner

icanos commented Feb 28, 2021

Really great work done here, love the new structure and the separation of BLE comm.

@SweVictor
Copy link
Collaborator Author

Thanks! Yeah, I'm thinking this is shaping up nicely too.

Has been some strange stuff with dbus exhausting internal resources, but sharing that instance seems to solve that. I'm long-term testing this now, but so far it looks promising.

Other testers are most welcome, I'll probably merge this next week to develop if nothing new comes up.

@SweVictor
Copy link
Collaborator Author

SweVictor commented Mar 2, 2021

So - after a few days working this error surfaced. Emitted from dbus-next

DBusError: Resource Not Ready
    at _methodReturnHandlers.<computed> (/plejd/node_modules/dbus-next/lib/bus.js:337:27)
    at handleMessage (/plejd/node_modules/dbus-next/lib/bus.js:96:11)
    at EventEmitter.<anonymous> (/plejd/node_modules/dbus-next/lib/bus.js:146:9)
    at EventEmitter.emit (events.js:314:20)
    at /plejd/node_modules/dbus-next/lib/connection.js:116:14
    at Socket.<anonymous> (/plejd/node_modules/dbus-next/lib/message.js:63:9)
    at Socket.emit (events.js:314:20)
    at emitReadable_ (_stream_readable.js:557:12)

Seems like the underlying error is org.bluez.Error.NotReady, also get the same in bluetoothctrl, also after power off / power on.

Anyone knows this error from before?

I managed to solve it temporarily, not sure what though (without restarting). The only command i run (in root console) were (in order)

  • bluemoon (which i think did nothing)
  • bluez-simple-agent (which crashed with a trace import 'dbus' => no module named dbus
  • bluetoothctl (which now as compared to before shows Agent registered before listing the command console)

The error came back after a while, and also persisted addon restart. Power off => wait for a slightly longer time (20+ seconds) seemed to fix it the second time.

Any ideas?

@SweVictor
Copy link
Collaborator Author

Hmm, so... This keeps happening (have not rebooted the computer, but at least HA supervisor).

Current guess is that bluetoothctl power off => bluemoon => ctrl+c (exit) => bluetoothctl power on might be what fixes the bad state. Any ideas what bluemoon does to get away from org.bluez.Error.NotReady?

Power cycling alone does not help. I think this is the source code of bluemoon, does not tell me much unfortunately. https://github.com/RadiusNetworks/bluez/blob/master/tools/bluemoon.c

@SweVictor
Copy link
Collaborator Author

So. I have in my installation had TONS of disconnects due to a (for now somewhat intentionally) bad placed BLE dongle. I have moved it to a better place now and have no disconnects (and therefore no issues). So - I'll merge this now and might break out the BLE discussion to a separate issue.

@SweVictor SweVictor merged commit 744230d into icanos:develop Mar 8, 2021
@SweVictor SweVictor deleted the feature/restructure-ble branch March 8, 2021 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants