-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
688 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
build* | ||
*.pyc | ||
*.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import asyncio | ||
import os | ||
import logging | ||
|
||
import bumble | ||
import click | ||
|
||
from bumble.colors import color | ||
from bumble.device import Device | ||
from bumble.transport import open_transport_or_link | ||
from bumble.keys import JsonKeyStore | ||
from bumble.smp import AddressResolver | ||
from bumble.device import Advertisement | ||
from bumble.hci import Address, HCI_Constant, HCI_LE_1M_PHY, HCI_LE_CODED_PHY | ||
|
||
|
||
adv_queue = asyncio.Queue() | ||
|
||
class AdvertisementPrinter: | ||
def __init__(self, resolver): | ||
self.resolver = resolver | ||
def on_advertisement(self, advertisement): | ||
print("Found advertisement ", advertisement.address) | ||
asyncio.run_coroutine_threadsafe(adv_queue.put(advertisement), asyncio.get_event_loop()) | ||
def on_advertising_report(self, report): | ||
pass | ||
|
||
|
||
|
||
TRANSPORT = "tcp-client:localhost:8001" | ||
|
||
|
||
async def check_connection(device: bumble.device): | ||
""" | ||
Task to send carl data to the M2B cloud | ||
:return: | ||
""" | ||
try: | ||
message = await asyncio.wait_for(adv_queue.get(), timeout=5.0) | ||
await device.connect(message.address) | ||
print("Connected") | ||
except asyncio.TimeoutError: | ||
print("No BLE Devices found") | ||
|
||
|
||
async def scan( | ||
passive, | ||
scan_interval, | ||
scan_window, | ||
phy, | ||
filter_duplicates | ||
): | ||
async with await open_transport_or_link(TRANSPORT) as (hci_source, hci_sink): | ||
device = Device.with_hci( | ||
'Bumble', 'F0:F1:F2:F3:F4:F5', hci_source, hci_sink | ||
) | ||
|
||
await device.power_on() | ||
resolving_keys = [] | ||
|
||
resolver = AddressResolver(resolving_keys) if resolving_keys else None | ||
|
||
printer = AdvertisementPrinter(resolver) | ||
|
||
device.on('advertisement', printer.on_advertisement) | ||
|
||
if phy is None: | ||
scanning_phys = [HCI_LE_1M_PHY, HCI_LE_CODED_PHY] | ||
else: | ||
scanning_phys = [{'1m': HCI_LE_1M_PHY, 'coded': HCI_LE_CODED_PHY}[phy]] | ||
|
||
await device.start_scanning( | ||
active=(not passive), | ||
scan_interval=scan_interval, | ||
scan_window=scan_window, | ||
filter_duplicates=filter_duplicates, | ||
scanning_phys=scanning_phys, | ||
) | ||
|
||
check_task = asyncio.create_task(check_connection(device)) | ||
await asyncio.gather(check_task) | ||
|
||
await hci_source.wait_for_termination() | ||
|
||
|
||
# ----------------------------------------------------------------------------- | ||
@click.command() | ||
@click.option('--min-rssi', type=int, help='Minimum RSSI value') | ||
@click.option('--passive', is_flag=True, default=False, help='Perform passive scanning') | ||
@click.option('--scan-interval', type=int, default=60, help='Scan interval') | ||
@click.option('--scan-window', type=int, default=60, help='Scan window') | ||
@click.option( | ||
'--phy', type=click.Choice(['1m', 'coded']), help='Only scan on the specified PHY' | ||
) | ||
@click.option( | ||
'--filter-duplicates', | ||
type=bool, | ||
default=True, | ||
help='Filter duplicates at the controller level', | ||
) | ||
|
||
def main( | ||
min_rssi, | ||
passive, | ||
scan_interval, | ||
scan_window, | ||
phy, | ||
filter_duplicates | ||
): | ||
logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'WARNING').upper()) | ||
asyncio.run( | ||
scan( | ||
passive, | ||
scan_interval, | ||
scan_window, | ||
phy, | ||
filter_duplicates | ||
) | ||
) | ||
|
||
|
||
# ----------------------------------------------------------------------------- | ||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- uptime_test.robot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright (c) 2024 Victor Chavez | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
set(ZEPHYR_EXTRA_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/ble_utils) | ||
|
||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(uptime_central) | ||
set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) | ||
target_sources(app PRIVATE src/main.cpp | ||
src/discovery.cpp) | ||
|
||
target_include_directories(app PRIVATE ${ROOT_DIR}/samples/uptime/src | ||
${ROOT_DIR}/include) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright (c) 2024 Victor Chavez | ||
# SPDX-License-Identifier: Apache-2.0 | ||
#--------- | ||
#C++ | ||
#---------- | ||
CONFIG_CPLUSPLUS=y | ||
CONFIG_LIB_CPLUSPLUS=y | ||
CONFIG_STD_CPP17=y | ||
CONFIG_NEWLIB_LIBC=y | ||
CONFIG_UART_CONSOLE=y | ||
CONFIG_BLE_UTILS=y | ||
CONFIG_CBPRINTF_FP_SUPPORT=y | ||
CONFIG_BT_ASSERT=n | ||
|
||
CONFIG_BT=y | ||
CONFIG_LOG=y | ||
CONFIG_BT_CENTRAL=y | ||
CONFIG_BT_SMP=y | ||
CONFIG_BT_GATT_CLIENT=y | ||
#increase mtu for sensor data notification | ||
CONFIG_BT_L2CAP_TX_MTU=600 | ||
CONFIG_BT_BUF_ACL_RX_SIZE=600 |
Oops, something went wrong.