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

Feat emulated device #974

Closed
wants to merge 9 commits into from
Closed

Feat emulated device #974

wants to merge 9 commits into from

Conversation

DimaWittmann
Copy link
Contributor

Overview

This PR integrates a new async ble plugin and blelib.

Tim Burke has created asyncio based ble plugin that should increase the throughtput and get rid of multiple wrapperers inside of current thread based ble plugin. I integrated code from another branch https://github.com/iotile/coretools/tree/feat-async-wrapper as well.

At the moment only scanning is fully implemented. Major functionality is in place but some parts of code are missed.

#How to

In order to run a new plugin user should install iotile-transport-bled112 and iotile-transport-blelib modules from this PR.
Instantiate the hardware manager with the new plugin:
iotile hw --port=async_bled112

To run iotile-gateway with new pluging a user needs to update name entry in config.


#FIXME: Raise an exception here

async def request_scan(self, tag: str, active: bool, delegate: BLEScanDelegate = None):
Copy link
Member

Choose a reason for hiding this comment

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

@DimaWittmann The BLEScanDelegate concept I believe is old and can be removed. Previously scan events came via callbacks made on the BLEScanDelegate object passed in but we moved to centralizing that through the events in the async central so this shouldn't be needed anymore and can just be removed completely.

@timothyfroehlich
Copy link
Contributor

Haven't had a chance to experiment yet, but does it gracefully handle someone removing a bled112 dongle? See this: https://app.zenhub.com/workspaces/archfx-nodes-5d8141feed817a000174f16b/issues/iotile/arch_node_tasks/114

Copy link
Contributor

@ekkizogloy ekkizogloy left a comment

Choose a reason for hiding this comment

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

Since this is a large feature PR, I will defer final approval to Tim B.
I will approve when I see test output and the final throughput results from Tim F.

@timothyfroehlich
Copy link
Contributor

timothyfroehlich commented Apr 29, 2020

I've been unable to get the plugin to work, either on the AP or on my laptop.

Here are the commands I'm running. Is there anything that I'm missing here, @DimaWittmann?

ID:0x2a/42 tfroehlich@tfroehlich-ThinkPad-P52s:~/proj/archrepos/coretools_asyncbled
$ python3.7 -m venv async_bled
ID:0x2a/42 tfroehlich@tfroehlich-ThinkPad-P52s:~/proj/archrepos/coretools_asyncbled
$ source async_bled/bin/activate
(async_bled) ID:0x2a/42 tfroehlich@tfroehlich-ThinkPad-P52s:~/proj/archrepos/coretools_asyncbled
$ pip install -e iotilecore/ transport_plugins/blelib/ transport_plugins/bled112/
Processing ./transport_plugins/blelib
Processing ./transport_plugins/bled112
Obtaining file:///home/tfroehlich/proj/archrepos/coretools_asyncbled/iotilecore
<...>
Installing collected packages: entrypoints, msgpack, six, python-dateutil, sortedcontainers, decorator, typedargs, iotile-core, iotile-transport-blelib, pyserial, iotile-transport-bled112
  Running setup.py install for iotile-transport-blelib ... done
  Running setup.py install for iotile-transport-bled112 ... done
Successfully installed decorator-4.4.2 entrypoints-0.3 iotile-core-5.0.15 iotile-transport-bled112-3.0.4 iotile-transport-blelib-0.0.1 msgpack-0.6.2 pyserial-3.4 python-dateutil-2.8.1 six-1.14.0 sortedcontainers-2.1.0 typedargs-1.0.1
(async_bled) ID:0x2a/42 tfroehlich@tfroehlich-ThinkPad-P52s:~/proj/archrepos/coretools_asyncbled
$ iotile hw --port=async_bled112
HardwareError: Could not find transport object registered to handle passed transport type
Additional Information:
transport: async_bled112
(async_bled) ID:0x2a/42 tfroehlich@tfroehlich-ThinkPad-P52s:~/proj/archrepos/coretools_asyncbled
$ git status
On branch feat-emulated-device
Your branch is up to date with 'origin/feat-emulated-device'.

@timburke
Copy link
Member

@timothyfroehlich It looks like there may be an importerror causing the device adapter to be ignored, can you turn up the logging and see if iotile logs any errors:

$ iotile -vvvvv hw --port=async_bled112

@@ -9,6 +9,9 @@
install_requires=[
"iotile-core>=5.0.0,<6"
Copy link
Contributor

Choose a reason for hiding this comment

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

Missed requirement for typing_extensions

@timothyfroehlich
Copy link
Contributor

After installing typing_extensions, the import failed with the below:

$ iotile -vvvvv hw --port=async_bled112
20-04-29 12:48:48.550 WAR iotile.core.dev.registry Unable to load async_bled112 from Distribution('iotile_transport_bled112', '3.0.4')
Traceback (most recent call last):
  File "/home/tfroehlich/proj/archrepos/coretools_asyncbled/async_bled/lib/python3.7/site-packages/iotile/core/dev/registry.py", line 167, in load_extensions
    ext = entry.load()
  File "/home/tfroehlich/proj/archrepos/coretools_asyncbled/async_bled/lib/python3.7/site-packages/entrypoints.py", line 82, in load
    mod = import_module(self.module_name)
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/tfroehlich/proj/archrepos/coretools_asyncbled/async_bled/lib/python3.7/site-packages/iotile_transport_bled112/hardware/__init__.py", line 3, in <module>
    from .async_bled112_adapter import BLED112Adapter
  File "/home/tfroehlich/proj/archrepos/coretools_asyncbled/async_bled/lib/python3.7/site-packages/iotile_transport_bled112/hardware/async_bled112_adapter.py", line 4, in <module>
    from iotile_transport_blelib.iotile import GenericBLEDeviceAdapter
  File "/home/tfroehlich/proj/archrepos/coretools_asyncbled/async_bled/lib/python3.7/site-packages/iotile_transport_blelib/iotile/__init__.py", line 9, in <module>
    from .generic_adapter import GenericBLEDeviceAdapter
  File "/home/tfroehlich/proj/archrepos/coretools_asyncbled/async_bled/lib/python3.7/site-packages/iotile_transport_blelib/iotile/generic_adapter.py", line 18, in <module>
    from ..iotile.advertisements import parse_v2_advertisement, parse_v1_advertisement
  File "/home/tfroehlich/proj/archrepos/coretools_asyncbled/async_bled/lib/python3.7/site-packages/iotile_transport_blelib/iotile/advertisements/__init__.py", line 33, in <module>
    from .generation import generate_v1_advertisement, generate_v2_advertisement, generate_advertisement
  File "/home/tfroehlich/proj/archrepos/coretools_asyncbled/async_bled/lib/python3.7/site-packages/iotile_transport_blelib/iotile/advertisements/generation.py", line 10, in <module>
    from ...interface import BLEAdvertisement
  File "/home/tfroehlich/proj/archrepos/coretools_asyncbled/async_bled/lib/python3.7/site-packages/iotile_transport_blelib/interface/__init__.py", line 7, in <module>
    from .abstract_central import AbstractBLECentral
  File "/home/tfroehlich/proj/archrepos/coretools_asyncbled/async_bled/lib/python3.7/site-packages/iotile_transport_blelib/interface/abstract_central.py", line 12, in <module>
    class AbstractBLECentral(Protocol):
  File "/home/tfroehlich/proj/archrepos/coretools_asyncbled/async_bled/lib/python3.7/site-packages/iotile_transport_blelib/interface/abstract_central.py", line 25, in AbstractBLECentral
    def events(self) -> OperationManager[messages.BluetoothEvent]:
TypeError: 'type' object is not subscriptable
HardwareError: Could not find transport object registered to handle passed transport type
Additional Information:
transport: async_bled112

@timburke
Copy link
Member

@timothyfroehlich Looks like that error is caused by using a released iotile-core rather than the one included in the branch. Could you try pip install -e ./iotilecore as well?

The error should have been fixed by this part of the PR:
https://github.com/iotile/coretools/pull/974/files#diff-e3ee2c6f8527dc10236b3f656c640d83R52

@timothyfroehlich
Copy link
Contributor

@timothyfroehlich Looks like that error is caused by using a released iotile-core rather than the one included in the branch. Could you try pip install -e ./iotilecore as well?

The error should have been fixed by this part of the PR:
https://github.com/iotile/coretools/pull/974/files#diff-e3ee2c6f8527dc10236b3f656c640d83R52

Well, that fixed it. I would have assumed that running pip install -e iotilecore/ transport_plugins/blelib/ transport_plugins/bled112/ would work but I suppose not.

@timothyfroehlich
Copy link
Contributor

Seems to be working, but I'm getting a significant number of these errors:
Apr 30 18:38:20 arch-ap-002a broadcast_forwarder[569]: 20-04-30 18:38:20.446 ERR iotile.core.utilities.async_tools.operation_manager Error running processor <coroutine object GenericBLEDeviceAdapter.on_advertisement at 0x7339ae40>: object of type 'BLEAdvertisement' has no len()
This is happening on both the AP and on my script that I use to count the number of incoming packets on my laptop: https://github.com/iotile/meta-arch-systems/blob/feat-async_bled/test/hackrf-testing/count_via_coretools.py

@timothyfroehlich
Copy link
Contributor

Performance-wise, with just 20 simulated Pods (175 broadcasts per second), I saw a significant amount of dropped packets. For my AP with the async bled, it dropped 77/519 from one SimPod. My AP running the latest released coretools and bled transport only dropped 19/521 from the same SimPod.

With 35 SimPods (320 broadcasts per second) the Async bled AP didn't fall behind or start queueing up packets, but it dropped almost half of the packets it received., and at one point missed an update from a Pod that updates it's value every second.

So I believe it was mentioned that this current build is less performant than the original code, and my tests show this as well.

@ekkizogloy
Copy link
Contributor

@timothyfroehlich
Thanks for that report. If you have any output files that may be of use, can you post them here in this pull request.

@timburke Do you think that we should leave this PR open or should we merge it now?

@timothyfroehlich
Copy link
Contributor

(Reposting since some of my comment got lost somehow)

@timothyfroehlich
Thanks for that report. If you have any output files that may be of use, can you post them here in this pull request.

My results output isn't very github friendly (I'm just printing graphs at the moment) but if it'd be useful then I could post something more detailed.

@timburke Do you think that we should leave this PR open or should we merge it now?

Also, this is still in draft and @DimaWittmann said there's more work to be done.

@DimaWittmann Let me know if you'd like me to run more performance tests for you, I have a branch set up for my AP so it's easy for me to try the latest.

@ekkizogloy
Copy link
Contributor

This is a great comparison. What I would like to do, is put the brakes on this PR and set it aside. Since there is a significant decrease in performance we should suspend work on it until we have time to dig deeper into debugging the plugin.

@dmaone dmaone closed this Jun 2, 2021
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.

5 participants