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

Bluetooth scanner version 2 #478

Conversation

taulfsime
Copy link
Contributor

In this script version, a queue is established to store packets, and a timer is employed to flush the queue.
Additionally, it addresses the issue where the device owns the scan process, but the script attempts to initiate a new one, which causes the script to not work.

@taulfsime taulfsime changed the title Update the script template to v2, https://github.com/home-assistant-libs/aioshelly/issues/477 Update the script template to v2 Jan 9, 2024
@taulfsime
Copy link
Contributor Author

Issue: #477

1 similar comment
@taulfsime
Copy link
Contributor Author

Issue: #477

Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @taulfsime

I think this is a good change. Please see comment above

@chemelli74
Copy link
Collaborator

Applied this PR to my production instance that suffer script memory overflow for Shelly BLU Gateway (hw: SNGW-BT01, fw 20231219-133956/1.1.0-g34b5d4f)

@bdraco
Copy link
Member

bdraco commented Jan 12, 2024

I did some tweaks to make it backwards compatible

@bdraco bdraco changed the title Update the script template to v2 Bluetooth scanner version 2 Jan 12, 2024
@bdraco
Copy link
Member

bdraco commented Jan 12, 2024

I've just about got it wired up to habluetooth so it can be used in a dev env outside of HA. I'll take care of the core PR shortly

bdraco added a commit to home-assistant/core that referenced this pull request Jan 12, 2024
@bdraco
Copy link
Member

bdraco commented Jan 12, 2024

@bdraco bdraco added the breaking-change Breaking changes label Jan 12, 2024
Comment on lines 24 to 26
const burstSendCount = 5; // number if events, emitted on timer event
const maxQueue = 80; // if the queue exceeds the limit, all new events are ignored until it empties
const packetsInSingleEvent = 5; // max number of packets in single event
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taulfsime Can we put 16 (to match ESPHome) in an event or is that too large?

Copy link
Member

@bdraco bdraco Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2024-01-12 13:47:57.890 WARNING (MainThread) [aioshelly.ble.backend.scanner] parsed_advs: [('55:F2:94:5F:18:42', -47, (None, [], {}, {76: b'\t\x08\x13\xf1\xc0\xa8k\xbd\x1bX\x16\x08\x00\xda-\xed\xdd%h\\'}, None)), ('D4:B2:A1:7C:42:17', -64, ('RZSS', [], {}, {}, None)), ('C5:F0:B6:05:9A:B8', -65, (None, [], {}, {76: b'\x12\x02$\x01'}, None)), ('F6:EE:7E:AC:9F:EB', -55, (None, [], {}, {76: b'\x12\x02.\x03\x07\x11\x06(\x89\x8amE\x88C!\xde/\xa1#WD\xae\xa9'}, None)), ('FC:EE:36:CF:93:95', -68, (None, [], {}, {2409: b'\xfc\xee6\xcf\x93\x95\x13\x1fd\x12\x04'}, None)), ('D8:EF:2F:41:B1:34', -72, ('RZSS', [], {}, {}, None)), ('34:AB:95:85:66:6D', -74, ('LOOKin_98F33163', ['00001812-0000-1000-8000-00805f9b34fb'], {}, {}, None))]
2024-01-12 13:47:58.453 WARNING (MainThread) [aioshelly.ble.backend.scanner] parsed_advs: [('74:CD:9C:23:FC:C4', -43, (None, [], {}, {76: b'\x10\x05!\x98_oC'}, 8)), ('24:0B:2A:36:55:4B', -72, (None, [], {}, {76: b'\t\x08\x13\x08\xc0\xa8k[\x1bX'}, None)), ('63:8F:51:DD:CC:0C', -58, (None, [], {}, {76: b'\x13\x0b\x1b|\x02\xa4\xc4_?6\xa1\xbe\x00'}, None)), ('E2:88:93:E1:50:6E', -44, (None, [], {}, {76: b'\x12\x02\x00\x00'}, None)), ('67:AE:22:73:84:52', -55, (None, [], {}, {76: b'\x10\x070\x1f\x08\xcf\n^h'}, 12)), ('F8:04:2E:E1:9F:19', -74, (None, [], {}, {117: b'B\x04\x01\x80\xa0\xf8\x04.\xe1\x9f\x19\xfa\x04.\xe1\x9f\x18\x01\x00\x00\x00\x00\x00\x00'}, None))]
2024-01-12 13:47:59.516 WARNING (MainThread) [aioshelly.ble.backend.scanner] parsed_advs: [('D1:4B:33:1F:0A:FD', -69, (None, [], {}, {2409: b'\xd1K3\x1f\n\xfd?\x1dd\x11\x04'}, None)), ('68:60:7C:2F:C1:1B', -76, (None, [], {}, {76: b'\t\x08\x13\xc5\xc0\xa8k~\x1bX\x16\x08\x00\xe8\xad\x12\xca\xfeIW'}, None)), ('F1:D0:17:BA:C6:A2', -75, ('Nanoleaf Strip 3B32', [], {}, {}, None)), ('34:AB:95:85:6E:F9', -68, ('LOOKin_98F330B4', ['00001812-0000-1000-8000-00805f9b34fb'], {}, {}, None)), ('5A:DB:5D:53:1E:84', -48, (None, [], {}, {76: b'\x0c\x0e\x08\xd9\\,\xe0\x91\x94\x9a\xf2^\xf5F\xd8\xf8\x10\x06A\x1dR\xdf\xe9\x18'}, None)), ('6A:1D:DC:AD:36:E2', -47, (None, [], {}, {76: b'\x0c\x0e\x08\xd9\\,\xe0\x91\x94\x9a\xf2^\xf5F\xd8\xf8\x10\x06A\x1dR\xdf\xe9\x18'}, None)), ('CC:32:37:35:4E:05', -59, ('GVH5106_4E05', ['0000ec88-0000-1000-8000-00805f9b34fb'], {}, {1: b'\x01\x01\x0e\xa3s\xa8'}, None))]
2024-01-12 13:48:00.364 WARNING (MainThread) [aioshelly.ble.backend.scanner] parsed_advs: [('C0:95:6D:53:56:AD', -71, (None, [], {}, {76: b'\x10\x05\n\x14\x84\xfa\xce'}, 12)), ('7A:56:85:6A:6D:CD', -60, (None, ['0000fe07-0000-1000-8000-00805f9b34fb'], {}, {1447: b'\x05\x10\x01\x00\x00\x00\x00\x00\x00\x02#\x00\xca'}, 9)), ('6A:1D:DC:AD:36:E2', -42, (None, [], {}, {76: b'\x0c\x0e\x08\xda\\h\xab\xfd\x9f\xd7YcF_\xe3\x08\x10\x06A\x1dR\xdf\xe9\x18'}, None)), ('5A:DB:5D:53:1E:84', -42, (None, [], {}, {76: b'\x0c\x0e\x08\xda\\h\xab\xfd\x9f\xd7YcF_\xe3\x08\x10\x06A\x1dR\xdf\xe9\x18'}, None))]
2024-01-12 13:48:01.107 WARNING (MainThread) [aioshelly.ble.backend.scanner] parsed_advs: [('D4:B2:A1:7C:42:17', -71, ('RZSS', [], {}, {}, None)), ('FC:EE:36:CF:93:95', -71, (None, [], {}, {2409: b'\xfc\xee6\xcf\x93\x95\x13\x1fd\x12\x04'}, None)), ('34:AB:95:85:66:6D', -71, ('LOOKin_98F33163', ['00001812-0000-1000-8000-00805f9b34fb'], {}, {}, None)), ('55:F2:94:5F:18:42', -37, (None, [], {}, {76: b'\t\x08\x13\xf1\xc0\xa8k\xbd\x1bX\x16\x08\x00\xda-\xed\xdd%h\\'}, None))]
2024-01-12 13:48:01.670 WARNING (MainThread) [aioshelly.ble.backend.scanner] parsed_advs: [('CC:32:37:35:4E:05', -59, ('GVH5106_4E05', ['0000ec88-0000-1000-8000-00805f9b34fb'], {}, {1: b'\x01\x01\x0e\x94-\x80'}, None)), ('D8:EF:2F:41:B1:34', -70, ('RZSS', [], {}, {}, None)), ('74:CD:9C:23:FC:C4', -52, (None, [], {}, {76: b'\x10\x05!\x98_oC'}, 8)), ('63:8F:51:DD:CC:0C', -45, (None, [], {}, {76: b'\x13\x0b\x1b|\x02\xa4\xc4_?6\xa1\xbe\x00'}, None))]

It seems to work ok to go to 16

@bdraco
Copy link
Member

bdraco commented Jan 13, 2024

diagnostics look good overnight

@bdraco
Copy link
Member

bdraco commented Jan 13, 2024

Retesting with the above timing tweaks. We can revert them if needed

bdraco added a commit that referenced this pull request Jan 14, 2024
@bdraco bdraco mentioned this pull request Jan 14, 2024
Copy link
Collaborator

@bieniu bieniu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested for several hours and works without problems, thanks 👍

@bdraco
Copy link
Member

bdraco commented Jan 14, 2024

Thanks @taulfsime

We will get this shipped in 2024.2.x

@bdraco bdraco merged commit feb1a50 into home-assistant-libs:main Jan 14, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Breaking changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants