### Include All SimpleBLE Classes Source: https://docs.simpleble.org/docs/simpleble/tutorial This snippet shows how to include all classes provided by the SimpleBLE library using a single header file. This is the simplest way to get started. ```cpp #include ``` -------------------------------- ### Install Dependencies for SimpleBLE Docs Source: https://docs.simpleble.org/docs/extras Installs the necessary dependencies for building the SimpleBLE documentation. This command should be run from the 'docs-new' directory within the repository. ```shell cd /docs-new npm install ``` ```shell cd /docs-new bun install ``` -------------------------------- ### Install SimpleBluez to Specific Prefix with CMake Source: https://docs.simpleble.org/docs/simplebluez/usage Example of installing SimpleBluez to a custom location using the --prefix argument with the cmake --install command. This allows for flexible installation paths. ```bash cmake --install build_simplebluez --prefix /usr/local ``` -------------------------------- ### Install SimplePyBLE from PyPI Source: https://docs.simpleble.org/docs/simplepyble/usage Installs the SimplePyBLE library using pip. This is the quickest method for getting started. For Linux users, ensure libdbus-1-dev is installed beforehand. ```bash pip install simplepyble ``` -------------------------------- ### Preview Production Build of SimpleBLE Docs Source: https://docs.simpleble.org/docs/extras Starts a local server to preview the production build of the SimpleBLE documentation before deployment. This ensures the final output matches expectations. ```shell npm run start ``` ```shell bun start ``` -------------------------------- ### Install SimpleAIBLE MCP Server using uv Source: https://docs.simpleble.org/docs/simpleaible/mcp Installs the SimpleAIBLE MCP server using the uv package installer. This is the recommended method for installation. ```bash uv tool install simpleaible ``` -------------------------------- ### Scan for Peripherals with SimpleBLE Source: https://docs.simpleble.org/docs/simpleble/tutorial This snippet demonstrates how to scan for Bluetooth Low Energy peripherals using the SimpleBLE library. It retrieves available adapters, initiates a scan, and then lists the identifiers and addresses of discovered peripherals. Dependencies include the SimpleBLE library. ```cpp // Get a list of all available adapters std::vector adapters = SimpleBLE::Adapter::get_adapters(); // Get the first adapter SimpleBLE::Adapter adapter = adapters[0]; // Scan for peripherals for 5000 milliseconds adapter.scan_for(5000); // Get the list of peripherals found std::vector peripherals = adapter.scan_get_results(); // Print the identifier of each peripheral for (auto peripheral : peripherals) { std::cout << "Peripheral identifier: " << peripheral.identifier() << std::endl; std::cout << "Peripheral address: " << peripheral.address() << std::endl; } ``` -------------------------------- ### Install simpleaible Package Source: https://docs.simpleble.org/docs/simpleaible/http Installs the simpleaible Python package using pip. This is the first step to setting up the HTTP server. ```bash pip install simpleaible ``` -------------------------------- ### Run SimpleBLE Docs in Development Mode Source: https://docs.simpleble.org/docs/extras Starts the documentation site in development mode, enabling hot reloading for faster iteration. Access the site at http://localhost:3000. ```shell npm run dev ``` ```shell bun dev ``` -------------------------------- ### Install CMake Project Source: https://docs.simpleble.org/docs/cmake_primer Installs the built project artifacts (executables, libraries, headers) to a system-defined location or a custom prefix. This makes the software available for use outside the build directory. On Linux/MacOS, installation to system directories may require `sudo`. ```bash cmake --install ``` ```bash sudo cmake --install ``` -------------------------------- ### Configure and Install CMake Project with Custom Prefix Source: https://docs.simpleble.org/docs/cmake_primer Configures and installs a CMake project, allowing customization of the installation directory using `CMAKE_INSTALL_PREFIX`. This provides flexibility for installing to non-standard locations or for testing purposes. The prefix can be set during configuration or directly during the install command. ```bash cmake -S -B -DCMAKE_INSTALL_PREFIX= cmake --build -j4 cmake --install ``` ```bash cmake --install --prefix ``` -------------------------------- ### Asynchronous BLE Peripheral Scanning with Callbacks Source: https://docs.simpleble.org/docs/simpleble/tutorial This code illustrates asynchronous scanning for BLE peripherals using SimpleBLE, employing callback functions for scan events. It sets up handlers for scan start, stop, peripheral found, and peripheral updated events, then initiates and manages the scan lifecycle. This approach is useful for background scanning. ```cpp // Set the callback to be called when the scan starts adapter.set_callback_on_scan_start([]() { std::cout << "Scan started" << std::endl; }); // Set the callback to be called when the scan stops adapter.set_callback_on_scan_stop([]() { std::cout << "Scan stopped" << std::endl; }); // Set the callback to be called when the scan finds a new peripheral adapter.set_callback_on_scan_found([](SimpleBLE::Peripheral peripheral) { std::cout << "Peripheral found: " << peripheral.identifier() << std::endl; }); // Set the callback to be called when a peripheral property has changed adapter.set_callback_on_scan_updated([](SimpleBLE::Peripheral peripheral) { std::cout << "Peripheral updated: " << peripheral.identifier() << std::endl; }); // Start scanning for peripherals adapter.scan_start(); // Wait for 5 seconds std::this_thread::sleep_for(std::chrono::seconds(5)); // Stop scanning for peripherals adapter.scan_stop(); ``` -------------------------------- ### List Bluetooth Adapters Response Source: https://docs.simpleble.org/docs/simpleaible/http Example JSON response for the GET /adapters endpoint, listing available Bluetooth adapters with their identifiers and addresses. ```json [ { "identifier": "hci0", "address": "AA:BB:CC:DD:EE:FF" } ] ``` -------------------------------- ### Include Specific SimpleBLE Classes Source: https://docs.simpleble.org/docs/simpleble/tutorial This snippet demonstrates how to include specific header files for individual SimpleBLE components like Adapter, Peripheral, Service, Characteristic, and Descriptor. This allows for more granular control over dependencies. ```cpp #include #include #include #include #include ``` -------------------------------- ### Install SimplePyBLE Locally Source: https://docs.simpleble.org/docs/simplepyble/usage Installs SimplePyBLE directly from the source code after cloning the repository. This method is useful for development or accessing the latest features. ```bash cd /simplepyble pip install . ``` -------------------------------- ### Install SimpleDBus using CMake Source: https://docs.simpleble.org/docs/simpledbus/usage Commands to install the SimpleDBus library after it has been built. It supports specifying a custom installation prefix and requires sudo privileges on Linux and macOS for system-wide installation. ```bash cmake --install build_simpledbus ``` ```bash cmake --install build_simpledbus --prefix /usr/local ``` ```bash sudo cmake --install build_simpledbus ``` -------------------------------- ### Install SimpleBLE Source: https://docs.simpleble.org/docs/simpleble/usage Installs the SimpleBLE library after it has been built. This command copies the compiled library and headers to the appropriate system locations. ```bash cmake --install build_simpleble ``` -------------------------------- ### Build SimpleBLE Examples with CMake Source: https://docs.simpleble.org/docs/simpleble/usage Builds the provided SimpleBLE examples using CMake. It configures the build with `-DSIMPLEBLE_LOCAL=ON` and then builds the targets using `cmake --build`. This command assumes you are in the root directory of the SimpleBLE project or have adjusted the paths accordingly. ```bash cmake -S /examples/simpleble -B build_simpleble_examples -DSIMPLEBLE_LOCAL=ON cmake --build build_simpleble_examples -j7 ``` -------------------------------- ### Integrate SimpleDBus in CMake (Installed) Source: https://docs.simpleble.org/docs/simpledbus/usage Example of how to find and link the SimpleDBus library in a CMake project after it has been installed. Requires the `simpledbus` package to be available in the CMake module path. ```cmake find_package(simpledbus REQUIRED CONFIG) target_link_libraries( simpledbus::simpledbus) ``` -------------------------------- ### FastMCP Client Example Source: https://docs.simpleble.org/docs/simpleaible/mcp An example of how to use the FastMCP client to interact with a SimpleBLE server running over HTTP. It demonstrates connecting to the server and calling the 'get_adapters' tool. ```python import asyncio from fastmcp import Client async def main(): # Connect to the server running on the default port 8000 async with Client("http://127.0.0.1:8000/mcp") as client: adapters = await client.call_tool("get_adapters", {{}}) # ... asyncio.run(main()) ``` -------------------------------- ### Check Bluetooth Status and Get Adapters in C++ Source: https://docs.simpleble.org/docs/simpleble/tutorial This C++ code snippet demonstrates how to check if Bluetooth is enabled and retrieve a list of available Bluetooth adapters using SimpleBLE. It handles cases where Bluetooth is disabled or no adapters are found, and then prints the identifier and address of the first adapter. ```cpp #include #include int main(int argc, char** argv) { if (!SimpleBLE::Adapter::bluetooth_enabled()) { std::cout << "Bluetooth is not enabled" << std::endl; return 1; } auto adapters = SimpleBLE::Adapter::get_adapters(); if (adapters.empty()) { std::cout << "No Bluetooth adapters found" << std::endl; return 1; } // Use the first adapter auto adapter = adapters[0]; // Do something with the adapter std::cout << "Adapter identifier: " << adapter.identifier() << std::endl; std::cout << "Adapter address: " << adapter.address() << std::endl; return 0; } ``` -------------------------------- ### Install SimpleBLE with Sudo Privileges Source: https://docs.simpleble.org/docs/simpleble/usage Installs SimpleBLE using `sudo` to ensure that the necessary permissions are available for writing to system directories. This is typically required on Linux and macOS. ```bash sudo cmake --install build_simpleble ``` -------------------------------- ### Install SimpleBluez with Sudo Privileges Source: https://docs.simpleble.org/docs/simplebluez/usage Command to install SimpleBluez using sudo, which is often required on Linux and macOS systems to write to system directories. ```bash sudo cmake --install build_simplebluez ``` -------------------------------- ### Install Testing Dependencies for SimpleBLE Source: https://docs.simpleble.org/docs/simpleble/usage Installs the necessary system and Python packages required for building and running SimpleBLE's unit and integration tests. This includes Google Test and Google Mock development libraries, Python development headers, and Python dependencies listed in the requirements file. ```bash sudo apt install libgtest-dev libgmock-dev python3-dev pip3 install -r /test/requirements.txt ``` -------------------------------- ### Connect to a BLE Peripheral with SimpleBLE Source: https://docs.simpleble.org/docs/simpleble/tutorial This snippet shows how to connect to a Bluetooth Low Energy peripheral using the SimpleBLE library. It first scans for peripherals and then establishes a connection to the first peripheral found in the results. This is a prerequisite for interacting with a device's services and characteristics. ```cpp // Scan for peripherals for 5000 milliseconds std::vector peripherals = adapter.scan_for(5000); // Connect to the first peripheral SimpleBLE::Peripheral peripheral = peripherals[0]; peripheral.connect(); ``` -------------------------------- ### Install Dependencies on Debian/Ubuntu Source: https://docs.simpleble.org/docs/simpleble/usage Installs the necessary development files for D-Bus on Debian-based Linux distributions using the APT package manager. This is a prerequisite for building SimpleBLE on these systems. ```bash sudo apt install libdbus-1-dev ``` -------------------------------- ### Install SimpleBluez using CMake Source: https://docs.simpleble.org/docs/simplebluez/usage Command to install the SimpleBluez library after it has been built. This command may require sudo privileges on Linux and macOS. ```bash cmake --install build_simplebluez ``` -------------------------------- ### Install Dependencies on Fedora/CentOS Source: https://docs.simpleble.org/docs/simpleble/usage Installs the necessary development files for D-Bus on RPM-based Linux distributions. This command uses `dnf` for Fedora and `yum` for CentOS, ensuring compatibility with different package managers. ```bash # On Fedora sudo dnf install dbus-devel # On CentOS sudo yum install dbus-devel ``` -------------------------------- ### Build SimpleBLE Docs for Production Source: https://docs.simpleble.org/docs/extras Generates a production-ready build of the SimpleBLE documentation. This command optimizes assets for deployment. ```shell npm run build ``` ```shell bun run build ``` -------------------------------- ### Install SimpleBLE to a Specific Prefix Source: https://docs.simpleble.org/docs/simpleble/usage Installs SimpleBLE to a custom location specified by the `CMAKE_INSTALL_PREFIX` variable. This allows for flexible installation paths, useful for development or custom deployments. ```bash cmake --install build_simpleble --prefix /usr/local ``` -------------------------------- ### Install Linux Dependencies for SimplePyBLE Source: https://docs.simpleble.org/docs/simplepyble/usage Installs the required D-Bus development library for SimplePyBLE on Debian-based Linux distributions. This is a prerequisite for using SimplePyBLE on Linux. ```bash sudo apt-get install libdbus-1-dev ``` -------------------------------- ### Run SimpleAIBLE HTTP Server Source: https://docs.simpleble.org/docs/simpleaible/http Starts the SimpleAIBLE HTTP server on a specified host and port. The server defaults to http://127.0.0.1:8000. ```bash python3 -m simpleaible.http --host 127.0.0.1 --port 8000 ``` -------------------------------- ### Install SimpleAIBLE MCP Server using pip Source: https://docs.simpleble.org/docs/simpleaible/mcp Installs the SimpleAIBLE MCP server using pip. For Python 3.11+ systems encountering PEP 668 errors, the `--break-system-packages` flag is required. ```bash pip install simpleaible ``` ```bash pip install --break-system-packages simpleaible # or python3 -m pip install --break-system-packages simpleaible ``` -------------------------------- ### Create a slice from start index Source: https://docs.simpleble.org/docs/simpleble/api Returns a new bytearray containing elements from the specified start index to the end of the original bytearray. ```cpp bytearray slice_from(size_t start) const; ``` -------------------------------- ### Vendorize SimpleBluez using FetchContent in CMake Source: https://docs.simpleble.org/docs/simplebluez/usage Example of vendorizing SimpleBluez within a CMake project using the FetchContent module. This allows managing SimpleBluez as a dependency directly from a Git repository. ```cmake include(FetchContent) FetchContent_Declare( simplebluez GIT_REPOSITORY GIT_TAG GIT_SHALLOW YES ) FetchContent_GetProperties(simplebluez) if(NOT simplebluez_POPULATED) FetchContent_Populate(simplebluez) list(APPEND CMAKE_MODULE_PATH "${simplebluez_SOURCE_DIR}/cmake/find") add_subdirectory("${simplebluez_SOURCE_DIR}/simplebluez" "${simplebluez_BINARY_DIR}") endif() set(simplebluez_FOUND 1) ``` -------------------------------- ### Configure Shared Library Build with CMake Source: https://docs.simpleble.org/docs/simplebluez/usage Example of how to configure SimpleBluez to build as a shared library using CMake. This is done by setting the BUILD_SHARED_LIBS CMake variable to TRUE. ```bash cmake -S -B build_simplebluez -DBUILD_SHARED_LIBS=TRUE ``` -------------------------------- ### Scan for BLE Devices Response Source: https://docs.simpleble.org/docs/simpleaible/http Example JSON response for the POST /scan endpoint, detailing discovered BLE devices including their name, address, RSSI, connectability, and manufacturer data. ```json [ { "identifier": "Nordic_HRM", "address": "AA:BB:CC:DD:EE:FF", "rssi": -55, "connectable": true, "manufacturer_data": { "76": "0215..." } } ] ``` -------------------------------- ### Get Device Information Response Source: https://docs.simpleble.org/docs/simpleaible/http Example JSON response for the GET /device/{address} endpoint, providing details about a connected BLE device, including its services and characteristics. ```json { "identifier": "Nordic_HRM", "address": "AA:BB:CC:DD:EE:FF", "connected": true, "mtu": 23, "services": [ { "uuid": "0000180d-0000-1000-8000-00805f9b34fb", "characteristics": ["00002a37-0000-1000-8000-00805f9b34fb"] } ] } ``` -------------------------------- ### Get Device Notifications Response Source: https://docs.simpleble.org/docs/simpleaible/http Example JSON response for the GET /device/{address}/notifications endpoint, listing received notifications and indications for a device. This call also clears the internal notification buffer. ```json [ { "service": "0000180d-0000-1000-8000-00805f9b34fb", "characteristic": "00002a37-0000-1000-8000-00805f9b34fb", "data_hex": "163c00", "data_utf8": "...", "type": "notification" } ] ``` -------------------------------- ### Vendorize SimpleDBus in CMake using FetchContent Source: https://docs.simpleble.org/docs/simpledbus/usage Demonstrates using CMake's FetchContent module to download and integrate a specific version of SimpleDBus directly into your project. This approach is useful for managing dependencies and ensuring reproducible builds. ```cmake include(FetchContent) FetchContent_Declare( simpledbus GIT_REPOSITORY GIT_TAG GIT_SHALLOW YES ) FetchContent_GetProperties(simpledbus) if(NOT simpledbus_POPULATED) FetchContent_Populate(simpledbus) list(APPEND CMAKE_MODULE_PATH "${simpledbus_SOURCE_DIR}/cmake/find") add_subdirectory("${simpledbus_SOURCE_DIR}/simpledbus" "${simpledbus_BINARY_DIR}") endif() set(simpledbus_FOUND 1) ``` ```cmake find_package(simpledbus REQUIRED) target_link_libraries( simpledbus::simpledbus) ``` -------------------------------- ### General Tools API Source: https://docs.simpleble.org/docs/simpleaible/mcp Provides tools for checking Bluetooth status, listing adapters, and scanning for devices. ```APIDOC ## GET /bluetooth_enabled ### Description Checks if Bluetooth is enabled on the host system. Assumes Bluetooth is enabled by default. Use this tool only when troubleshooting failed operations. ### Method GET ### Endpoint /bluetooth_enabled ### Parameters #### Query Parameters None #### Request Body None ### Response #### Success Response (200) - **enabled** (boolean) - Indicates if Bluetooth is enabled. #### Response Example ```json { "enabled": true } ``` ## GET /get_adapters ### Description Lists all available Bluetooth adapters on the system. ### Method GET ### Endpoint /get_adapters ### Parameters #### Query Parameters None #### Request Body None ### Response #### Success Response (200) - A list of objects, where each object contains `identifier` and `address` of a Bluetooth adapter. #### Response Example ```json [ { "identifier": "hci0", "address": "AA:BB:CC:DD:EE:FF" } ] ``` ## POST /scan_for ### Description Scans for nearby BLE devices using the first available adapter. ### Method POST ### Endpoint /scan_for ### Parameters #### Query Parameters - **timeout_ms** (integer) - Optional - Duration of the scan in milliseconds. Defaults to 5000. #### Request Body None ### Response #### Success Response (200) - A list of found BLE devices, each with `identifier`, `address`, `rssi`, `connectable`, and `manufacturer_data`. #### Response Example ```json [ { "identifier": "Nordic_HRM", "address": "AA:BB:CC:DD:EE:FF", "rssi": -55, "connectable": true, "manufacturer_data": {"76": "0215..."} } ] ``` ``` -------------------------------- ### Link SimpleBLE in CMake (Installed) Source: https://docs.simpleble.org/docs/simpleble/usage Demonstrates how to link the installed SimpleBLE library into a CMake project. It uses `find_package` to locate SimpleBLE and `target_link_libraries` to include it in your target. ```cmake find_package(simpleble REQUIRED CONFIG) target_link_libraries( simpleble::simpleble) ``` -------------------------------- ### Enable Verbose Output in CMake Build Source: https://docs.simpleble.org/docs/cmake_primer Executes a CMake build with verbose output, showing detailed steps. This is useful for debugging build process issues. The build directory must already be configured. ```bash cmake --build --verbose ``` -------------------------------- ### Pass Custom Configuration Options with CMake Source: https://docs.simpleble.org/docs/cmake_primer Configures a CMake project with custom build options using the -D flag. This allows enabling features or setting parameters like log levels. Ensure the project supports these variables. ```bash cmake -S -B -DMY_PROJECT_FEATURE=ON -DMY_LOG_LEVEL=DEBUG ``` -------------------------------- ### Use Installed SimpleBluez in CMake Project Source: https://docs.simpleble.org/docs/simplebluez/usage Instructions for consuming an installed SimpleBluez library within a CMake project. It involves finding the package and linking the target library. ```cmake find_package(simplebluez REQUIRED CONFIG) target_link_libraries( simplebluez::simplebluez) ``` -------------------------------- ### Configure CMake Project Source: https://docs.simpleble.org/docs/cmake_primer Configures a CMake project by reading the `CMakeLists.txt` file and generating system-specific build files. It requires the path to the source directory and a build directory. The build directory is where CMake stores generated files, keeping the source directory clean. ```bash cmake -S -B ``` -------------------------------- ### Build CMake Project Source: https://docs.simpleble.org/docs/cmake_primer Builds the configured CMake project, compiling source code into executables or libraries. It uses the generated build files in the specified build directory. The `-j` flag allows for parallel compilation to speed up the process. ```bash cmake --build -j4 ``` -------------------------------- ### Build and Run SimpleBLE Unit Tests Source: https://docs.simpleble.org/docs/simpleble/usage Configures, builds, and runs the SimpleBLE unit tests using CMake. The build is configured with `-DSIMPLEBLE_TEST=ON`, and the tests are executed after building. This process generates an executable in the build directory. ```bash cmake -S -B build_simpleble_test -DSIMPLEBLE_TEST=ON cmake --build build_simpleble_test -j7 ./build_simpleble_test/bin/simpleble_test ``` -------------------------------- ### Device Connection API Source: https://docs.simpleble.org/docs/simpleaible/mcp Handles establishing and terminating connections to BLE devices. ```APIDOC ## POST /connect ### Description Establishes a connection to a specific BLE device. ### Method POST ### Endpoint /connect ### Parameters #### Query Parameters None #### Request Body - **address** (string) - Required - The address of the device to connect to (UUID on macOS, MAC address on Linux/Windows). ### Response #### Success Response (200) - **message** (string) - Confirmation message of the connection. - **address** (string) - The address of the connected device. #### Response Example ```json { "message": "Connected to Nordic_HRM", "address": "AA:BB:CC:DD:EE:FF" } ``` ## POST /disconnect ### Description Disconnects from a currently connected BLE device. ### Method POST ### Endpoint /disconnect ### Parameters #### Query Parameters None #### Request Body - **address** (string) - Required - The address of the device to disconnect from. ### Response #### Success Response (200) - **message** (string) - Confirmation message of the disconnection. #### Response Example ```json { "message": "Disconnected from AA:BB:CC:DD:EE:FF" } ``` ## GET /services ### Description Retrieves the services and characteristics for a connected BLE device. ### Method GET ### Endpoint /services ### Parameters #### Query Parameters - **address** (string) - Required - The address of the connected device. #### Request Body None ### Response #### Success Response (200) - **identifier** (string) - The identifier of the device. - **address** (string) - The address of the device. - **connected** (boolean) - Indicates if the device is connected. - **mtu** (integer) - The Maximum Transmission Unit (MTU) for the connection. - **services** (array) - A list of services, where each service contains a `uuid` and a list of `characteristics` (represented by their UUIDs). #### Response Example ```json { "identifier": "Nordic_HRM", "address": "AA:BB:CC:DD:EE:FF", "connected": true, "mtu": 23, "services": [ { "uuid": "0000180d-0000-1000-8000-00805f9b34fb", "characteristics": ["00002a37-0000-1000-8000-00805f9b34fb"] } ] } ``` ``` -------------------------------- ### Access Interactive API Documentation Source: https://docs.simpleble.org/docs/simpleaible/http URLs to access the interactive API documentation (Swagger UI and ReDoc) provided by FastAPI when the server is running. ```bash http://127.0.0.1:8000/docs ``` ```bash http://127.0.0.1:8000/redoc ``` -------------------------------- ### API Health Check Response Source: https://docs.simpleble.org/docs/simpleaible/http The expected JSON response when checking the health of the SimpleAIBLE API via the GET / endpoint. ```json {"message": "SimpleAIBLE API is running"} ``` -------------------------------- ### Link SimpleBLE in CMake (Local) Source: https://docs.simpleble.org/docs/simpleble/usage Shows how to include SimpleBLE directly from its source directory into your CMake project. This is useful for development or when SimpleBLE is not installed system-wide. ```cmake add_subdirectory( ${CMAKE_BINARY_DIR}/simpleble) target_link_libraries( simpleble::simpleble) ``` -------------------------------- ### Create a slice of bytearray Source: https://docs.simpleble.org/docs/simpleble/api Returns a new bytearray containing a portion of the original bytearray, specified by start and end indices. The end index is exclusive. ```cpp bytearray slice(size_t start, size_t end) const; ``` -------------------------------- ### Configure SimpleDBus Build Options with CMake Source: https://docs.simpleble.org/docs/simpledbus/usage Demonstrates how to customize the SimpleDBus build using CMake variables. This includes enabling shared library builds, setting log levels (VERBOSE, DEBUG, INFO, WARN, ERROR, FATAL), and forcing the use of the DBus session bus. ```bash cmake -S -B build_simpledbus -DBUILD_SHARED_LIBS=TRUE ``` ```bash cmake -S -B build_simpledbus -DSIMPLEDBUS_LOG_LEVEL=DEBUG ``` ```bash cmake -S -B build_simpledbus -DSIMPLEDBUS_USE_SESSION_DBUS=TRUE ``` -------------------------------- ### General Endpoints Source: https://docs.simpleble.org/docs/simpleaible/http Endpoints for checking server status and listing Bluetooth adapters. ```APIDOC ## GET / ### Description Check if the API is running and healthy. ### Method GET ### Endpoint / ### Response #### Success Response (200) - **message** (string) - Confirmation that the API is running. #### Response Example ```json { "message": "SimpleAIBLE API is running" } ``` ## GET /adapters ### Description List all available Bluetooth adapters on the system. ### Method GET ### Endpoint /adapters ### Response #### Success Response (200) - List of objects, each containing: - **identifier** (string) - The identifier of the Bluetooth adapter (e.g., "hci0"). - **address** (string) - The MAC address of the Bluetooth adapter. #### Response Example ```json [ { "identifier": "hci0", "address": "AA:BB:CC:DD:EE:FF" } ] ``` ``` -------------------------------- ### Integrate SimpleDBus in CMake (Local) Source: https://docs.simpleble.org/docs/simpledbus/usage Instructions for integrating SimpleDBus into a CMake project by adding its source directory. This allows linking against the library without a formal installation step. ```cmake add_subdirectory( ${CMAKE_BINARY_DIR}/simpledbus) target_link_libraries( simpledbus::simpledbus) ``` -------------------------------- ### Build Static Library with CMake Source: https://docs.simpleble.org/docs/cmake_primer Configures and builds a project using static libraries. This requires the CMake build tool and the project's source code. The output is a statically linked library embedded within the executable. ```bash cmake -S -B -DBUILD_SHARED_LIBS=FALSE cmake --build -j4 ``` -------------------------------- ### Device Scanning and Connection Source: https://docs.simpleble.org/docs/simpleaible/http Endpoints for scanning BLE devices and managing connections. ```APIDOC ## POST /scan ### Description Scan for nearby BLE devices. ### Method POST ### Endpoint /scan ### Query Parameters - **timeout_ms** (integer) - Optional - Duration of the scan in milliseconds. Defaults to 5000. ### Response #### Success Response (200) - List of found BLE devices, each containing: - **identifier** (string) - The name or identifier of the device. - **address** (string) - The MAC address of the device. - **rssi** (integer) - The Received Signal Strength Indicator. - **connectable** (boolean) - Indicates if the device is connectable. - **manufacturer_data** (object) - Optional - Manufacturer-specific data. #### Response Example ```json [ { "identifier": "Nordic_HRM", "address": "AA:BB:CC:DD:EE:FF", "rssi": -55, "connectable": true, "manufacturer_data": { "76": "0215..." } } ] ``` ## POST /connect/{address} ### Description Establish a connection to a specific BLE device. ### Method POST ### Endpoint /connect/{address} ### Path Parameters - **address** (string) - Required - The MAC address or UUID of the device to connect to. ### Response #### Success Response (200) - **message** (string) - Confirmation message of the connection. - **address** (string) - The address of the connected device. #### Response Example ```json {"message": "Connected to Nordic_HRM", "address": "AA:BB:CC:DD:EE:FF"} ``` ## POST /disconnect/{address} ### Description Disconnect from a connected BLE device. ### Method POST ### Endpoint /disconnect/{address} ### Path Parameters - **address** (string) - Required - The MAC address of the device to disconnect from. ### Response #### Success Response (200) - **message** (string) - Confirmation message of the disconnection. #### Response Example ```json {"message": "Disconnected from AA:BB:CC:DD:EE:FF"} ``` ``` -------------------------------- ### Build SimpleBluez using CMake Source: https://docs.simpleble.org/docs/simplebluez/usage Commands to configure and build the SimpleBluez library using CMake. It involves specifying the source directory and a build directory. The build process can be customized with additional arguments. ```bash cmake -S -B build_simplebluez cmake --build build_simplebluez -j7 ``` -------------------------------- ### Build SimpleBLE using CMake Source: https://docs.simpleble.org/docs/simpleble/usage Configures and builds the SimpleBLE library using CMake. The first command sets up the build directory, and the second command compiles the library, utilizing multiple cores for faster build times. ```bash cmake -S -B build_simpleble cmake --build build_simpleble -j7 ``` -------------------------------- ### Build Shared Library with CMake Source: https://docs.simpleble.org/docs/cmake_primer Configures and builds a project using shared libraries. This requires the CMake build tool and the project's source code. The output is a dynamically linked library. ```bash cmake -S -B -DBUILD_SHARED_LIBS=TRUE cmake --build -j4 ``` -------------------------------- ### Initialize bytearray with specified size Source: https://docs.simpleble.org/docs/simpleble/api Creates an empty bytearray with a pre-allocated size. This can be more efficient if the final size is known in advance. ```cpp bytearray(size_t size); ``` -------------------------------- ### Initialize bytearray from default Source: https://docs.simpleble.org/docs/simpleble/api Creates a default bytearray. This is the simplest constructor for the bytearray class. ```cpp bytearray()=default; ``` -------------------------------- ### Initialize bytearray from raw pointer and size Source: https://docs.simpleble.org/docs/simpleble/api Creates a bytearray from a raw pointer to uint8_t data and a specified size. Ensure the pointer is valid for the given size. ```cpp bytearray(const uint8_t *ptr, size_t size); ``` -------------------------------- ### Device Connection API Source: https://docs.simpleble.org/docs/simpleaible/http Endpoints for managing connections to Bluetooth devices. ```APIDOC ## POST /connect/{address} ### Description Connects to a Bluetooth device using its address. ### Method POST ### Endpoint /connect/{address} ### Parameters #### Path Parameters - **address** (string) - Required - The MAC address of the device to connect to. #### Query Parameters None ### Request Example None ### Response #### Success Response (200) - **status** (string) - Connection status message. #### Response Example ```json { "status": "Connected to AA:BB:CC:DD:EE:FF" } ``` ## POST /disconnect/{address} ### Description Disconnects from a Bluetooth device. ### Method POST ### Endpoint /disconnect/{address} ### Parameters #### Path Parameters - **address** (string) - Required - The MAC address of the device to disconnect from. #### Query Parameters None ### Request Example None ### Response #### Success Response (200) - **status** (string) - Disconnection status message. #### Response Example ```json { "status": "Disconnected from AA:BB:CC:DD:EE:FF" } ``` ## GET /device/{address} ### Description Retrieves information about a connected device, including its services and characteristics. ### Method GET ### Endpoint /device/{address} ### Parameters #### Path Parameters - **address** (string) - Required - The MAC address of the device. #### Query Parameters None ### Request Example None ### Response #### Success Response (200) - **services** (array) - A list of services offered by the device. - **characteristics** (array) - A list of characteristics for each service. #### Response Example ```json { "services": [ { "uuid": "1800", "characteristics": [ { "uuid": "2a00", "properties": ["read"] } ] } ] } ``` ``` -------------------------------- ### Vendorize SimpleBLE with CMake FetchContent Source: https://docs.simpleble.org/docs/simpleble/usage Integrates a vendorized copy of SimpleBLE into your CMake project using FetchContent. This method allows specifying the Git repository and tag for SimpleBLE, ensuring it's fetched from a controlled source. It manually handles the population and subdirectory addition to allow for custom dependency management. ```cmake include(FetchContent) FetchContent_Declare( simpleble GIT_REPOSITORY GIT_TAG GIT_SHALLOW YES ) FetchContent_GetProperties(simpleble) if(NOT simpleble_POPULATED) FetchContent_Populate(simpleble) list(APPEND CMAKE_MODULE_PATH "${simpleble_SOURCE_DIR}/cmake/find") add_subdirectory("${simpleble_SOURCE_DIR}/simpleble" "${simpleble_BINARY_DIR}") endif() set(simpleble_FOUND 1) ``` -------------------------------- ### Clean CMake Build Directory Source: https://docs.simpleble.org/docs/cmake_primer Removes the CMake build directory to perform a clean build. This is useful for resolving issues caused by stale build artifacts or configuration changes. A subsequent configuration step is required. ```bash rm -rf cmake -S -B ``` -------------------------------- ### Initialize bytearray from C-style string and size Source: https://docs.simpleble.org/docs/simpleble/api Initializes a bytearray from a C-style string (char pointer) and its size. This is useful when working with C-style string data. ```cpp bytearray(const char *byteArr, size_t size); ``` -------------------------------- ### Configure SimpleAIBLE MCP Server in Cursor Source: https://docs.simpleble.org/docs/simpleaible/mcp Configuration for adding the SimpleAIBLE MCP server globally or per-project in Cursor IDE. This involves adding a JSON configuration to `~/.cursor/mcp.json` or `.cursor/mcp.json`. ```json { "mcpServers": { "simpleaible": { "command": "simpleaible" } } } ```