### Initialize Zephyr Workspace with Hubble Network SDK as Manifest Repository Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/docs/quickstart/zephyr/index.md These bash commands outline the process of setting up a Zephyr workspace where the Hubble Network SDK serves as the manifest repository. It includes creating a Python virtual environment, installing West, initializing the workspace with the Hubble SDK, and updating the project. ```bash python3 -m venv ~/hubblenetwork-workspace/.venv source ~/hubblenetwork-workspace/.venv/bin/activate pip install west west init -m git@github.com:HubbleNetwork/hubble-device-sdk.git ~/hubblenetwork-workspace cd ~/hubblenetwork-workspace/modules/lib/hubblenetwork-sdk west update ``` -------------------------------- ### Set Environment Variables for TI SDK Build (Bash) Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/samples/freertos/ti/ble-beacon/README.md Sets essential environment variables required for building the project with the TI SDK. These include paths to the ARM compiler, the SimpleLink SDK installation directory, and the SysConfig tool. ```bash export TICLANG_ARMCOMPILER=/Applications/ti/ccs2040/ccs/tools/compiler/ti-cgt-armllvm_4.0.4.LTS/ export SIMPLELINK_LOWPOWER_F3_SDK_INSTALL_DIR=/Applications/ti/simplelink_lowpower_f3_sdk_9_14_00_41 export SYSCONFIG_TOOL=/Applications/ti/sysconfig_1.23.2/sysconfig_cli.sh ``` -------------------------------- ### Build Project using Makefile (Bash) Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/samples/freertos/ti/ble-beacon/README.md Compiles the project using the provided makefile. This command assumes all dependencies and environment variables are correctly set up. ```bash make ``` -------------------------------- ### Build FreeRTOS Application with Hubble Network SDK Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/docs/quickstart/freertos/index.md This command initiates the build process for your FreeRTOS application, incorporating the Hubble Network SDK. Navigate to your application's Makefile directory before executing. ```bash make -C /path/to/your/application/Makefile ``` -------------------------------- ### Flash Application on Zephyr Target Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/docs/quickstart/zephyr/index.md This bash command flashes the built Zephyr application onto the target hardware. It assumes the build process has been completed successfully and the necessary tools are configured. ```bash west flash ``` -------------------------------- ### Build and Flash Zephyr Project with Hubble SDK (Bash) Source: https://context7.com/hubblenetwork/hubble-device-sdk/llms.txt Commands to initialize a Zephyr workspace with the Hubble SDK, update modules, export the Zephyr CMake package, install dependencies, build a sample application (BLE beacon for nRF52840 DK), and flash it to the device. ```bash # Initialize workspace with Hubble SDK as manifest west init -m git@github.com:HubbleNetwork/hubble-device-sdk.git ~/hubblenetwork-workspace cd ~/hubblenetwork-workspace/modules/lib/hubblenetwork-sdk west update # Export Zephyr CMake package west zephyr-export # Install dependencies pip install -r ~/hubblenetwork-workspace/zephyr/scripts/requirements.txt # Build BLE beacon sample for nRF52840 DK west build -p -b nrf52840dk/nrf52840 modules/lib/hubblenetwork-sdk/samples/zephyr/ble-beacon # Flash to device west flash ``` -------------------------------- ### ESP-IDF BLE Beacon Example using Hubble SDK Source: https://context7.com/hubblenetwork/hubble-device-sdk/llms.txt This example demonstrates how to create a BLE beacon application using the ESP-IDF framework. It leverages the Hubble SDK to broadcast Hubble advertisements, including device ID and sensor data. The beacon updates its advertisement data hourly. Dependencies include ESP-IDF, FreeRTOS, and the Hubble SDK. ```c #include #include "esp_bt.h" #include "esp_gap_ble_api.h" #include "esp_bt_main.h" #include "esp_log.h" #include "esp_timer.h" #include "nvs_flash.h" #define BLE_ADV_LEN 31 #define HUBBLE_BLE_UUID 0xFCA6 #define HOUR_TO_US(x) ((x) * 3600ULL * 1000000ULL) static const char *TAG = "HUBBLE_BLE"; static uint64_t utc_time = 1735689600000ULL; static uint8_t master_key[32] = { /* Your 256-bit key */ }; // Raw advertisement data template static uint8_t adv_data[BLE_ADV_LEN] = { 0x03, ESP_BLE_AD_TYPE_16SRV_CMPL, 0xA6, 0xFC, // Service UUID 0x01, ESP_BLE_AD_TYPE_SERVICE_DATA, // Service data header }; static esp_ble_adv_params_t adv_params = { .adv_int_min = 0x20, .adv_int_max = 0x20, .adv_type = ADV_TYPE_SCAN_IND, .own_addr_type = BLE_ADDR_TYPE_RANDOM, .channel_map = ADV_CHNL_ALL, .adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY, }; static esp_err_t update_hubble_advertisement(void) { size_t out_len = BLE_ADV_LEN - 6; // Space after header int ret = hubble_ble_advertise_get(NULL, 0, &adv_data[6], &out_len); if (ret != 0) { ESP_LOGE(TAG, "Failed to get adv data: %d", ret); return ESP_FAIL; } adv_data[4] = out_len + 1; // Update service data length return esp_ble_gap_config_adv_data_raw(adv_data, 6 + out_len); } static void timer_callback(void *arg) { update_hubble_advertisement(); } static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) { switch (event) { case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT: esp_ble_gap_start_advertising(&adv_params); break; case ESP_GAP_BLE_ADV_START_COMPLETE_EVT: ESP_LOGI(TAG, "Advertising started"); break; default: break; } } void app_main(void) { // Initialize Hubble SDK if (hubble_init(utc_time, master_key) != 0) { ESP_LOGE(TAG, "Hubble init failed"); return; } // Initialize NVS and Bluetooth nvs_flash_init(); esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); esp_bt_controller_init(&bt_cfg); esp_bt_controller_enable(ESP_BT_MODE_BLE); esp_bluedroid_config_t cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); esp_bluedroid_init_with_cfg(&cfg); esp_bluedroid_enable(); esp_ble_gap_register_callback(gap_event_handler); // Initial advertisement update_hubble_advertisement(); // Update advertisement hourly esp_timer_handle_t timer; esp_timer_create(&(esp_timer_create_args_t){ .callback = timer_callback }, &timer); esp_timer_start_periodic(timer, HOUR_TO_US(1)); } ``` -------------------------------- ### Zephyr RTOS BLE Beacon Example with Hubble Source: https://context7.com/hubblenetwork/hubble-device-sdk/llms.txt A complete BLE beacon application for Zephyr RTOS that periodically broadcasts Hubble advertisements. It initializes the Hubble SDK and Bluetooth, then uses a timer to update and start BLE advertising with the generated Hubble advertisement data. ```c #include #include #include #define HUBBLE_BLE_UUID 0xFCA6 #define ADV_BUFFER_LEN 31 #define ADV_UPDATE_PERIOD_SEC 60 static uint8_t hubble_buffer[ADV_BUFFER_LEN]; static uint16_t hubble_uuid = HUBBLE_BLE_UUID; static uint64_t utc_time = 1735689600000ULL; // Set your UTC time static uint8_t master_key[32] = { /* Your 256-bit key */ }; static struct bt_data ad[] = { BT_DATA(BT_DATA_UUID16_ALL, &hubble_uuid, sizeof(hubble_uuid)), {0}, // Placeholder for Hubble service data }; K_SEM_DEFINE(timer_sem, 0, 1); static void timer_cb(struct k_timer *timer) { k_sem_give(&timer_sem); } K_TIMER_DEFINE(adv_timer, timer_cb, NULL); int main(void) { int err; size_t out_len; // Initialize Bluetooth err = bt_enable(NULL); if (err) { printk("Bluetooth init failed: %d\n", err); return err; } // Initialize Hubble SDK err = hubble_init(utc_time, master_key); if (err) { printk("Hubble init failed: %d\n", err); return err; } // Start periodic advertisement updates k_timer_start(&adv_timer, K_SECONDS(ADV_UPDATE_PERIOD_SEC), K_SECONDS(ADV_UPDATE_PERIOD_SEC)); while (1) { // Generate new advertisement data out_len = ADV_BUFFER_LEN; err = hubble_ble_advertise_get(NULL, 0, hubble_buffer, &out_len); if (err) { printk("Failed to get adv data: %d\n", err); continue; } // Update advertisement payload ad[1].data_len = out_len; ad[1].type = BT_DATA_SVC_DATA16; ad[1].data = hubble_buffer; // Start advertising err = bt_le_adv_start(BT_LE_ADV_NCONN, ad, ARRAY_SIZE(ad), NULL, 0); if (err) { printk("Advertising failed: %d\n", err); } // Wait for next update period k_sem_take(&timer_sem, K_FOREVER); bt_le_adv_stop(); } return 0; } ``` -------------------------------- ### Add Hubble Network SDK as Git Submodule Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/docs/quickstart/freertos/index.md This command adds the Hubble Network SDK repository as a git submodule to your project. Ensure you have git installed and are in the root directory of your application. ```bash git submodule add https://github.com/HubbleNetwork/hubble-device-sdk . ``` -------------------------------- ### Embed Key and UTC Timestamp using Python Script Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/samples/freertos/ti/ble-beacon/README.md Provisions a BLE key and UTC timestamp using the embed_key_utc.py script. This script is typically located in the SDK's tools directory and requires the path to the key file and an output directory. ```bash # Script is located in SDK_BASE/tools python ../../../../tools/embed_key_utc.py --base64 -o src/ ``` -------------------------------- ### Build Hubble Network BLE Application in Zephyr Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/docs/quickstart/zephyr/index.md This bash command builds a sample BLE Network application using the Hubble Network SDK within a Zephyr project. It navigates to the workspace directory and uses `west build` with specified board and application path. ```bash cd ~/hubblenetwork-workspace/ west build -p -b nrf52840dk/nrf52840 modules/lib/hubblenetwork-sdk/samples/zephyr/ble-network ``` -------------------------------- ### Integrate Hubble Network SDK Makefile Fragment for FreeRTOS Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/docs/quickstart/freertos/index.md This Makefile snippet shows how to include the Hubble Network SDK's build rules into your FreeRTOS application's build system. It defines rules for compiling the SDK's source files using specific flags. ```makefile # Hubble Network SDK include path/to/hubblenetwork-sdk/port/freertos/hubblenetwork-sdk.mk define HUBBLE_RULE $(basename $(notdir $(1))).obj: $(1) $(CC) $(CFLAGS) $(HUBBLENETWORK_SDK_BLE_FLAGS) -c $$< -o $$@ endef $(foreach source_file,$(HUBBLENETWORK_SDK_BLE_SOURCES),$(eval $(call HUBBLE_RULE,$(source_file)))) # Hubble Network SDK END ``` -------------------------------- ### Configure CMake Build for Zephyr RTOS Application Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/tests/zephyr/ble-network/CMakeLists.txt This CMake script configures a Zephyr RTOS application for BLE network testing. It specifies the minimum CMake version, finds the Zephyr package, sets the project name, and includes all C source files from the src directory into the target. Dependencies include the Zephyr SDK. ```cmake cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(ble_network_test) FILE(GLOB app_sources src/*.c) target_sources(app PRIVATE ${app_sources}) ``` -------------------------------- ### Implement Cryptographic Provider for Porting Layer (C) Source: https://context7.com/hubblenetwork/hubble-device-sdk/llms.txt Provides example implementations for essential cryptographic functions required by the Hubble SDK's porting layer, targeting platforms like FreeRTOS. This includes initialization, secure memory zeroization, AES-CTR encryption, and CMAC generation. Dependencies include `hubble/port/crypto.h` and `string.h`. ```c #include #include // Platform-specific crypto implementation example int hubble_crypto_init(void) { // Initialize your crypto hardware/library // E.g., mbedtls_aes_init(), hardware crypto module, etc. return 0; } void hubble_crypto_zeroize(void *buf, size_t len) { // Secure memory clearing (prevent compiler optimization) volatile uint8_t *p = (volatile uint8_t *)buf; while (len--) { *p++ = 0; } } int hubble_crypto_aes_ctr(const uint8_t key[CONFIG_HUBBLE_KEY_SIZE], uint8_t nonce_counter[HUBBLE_BLE_NONCE_BUFFER_LEN], const uint8_t *data, size_t len, uint8_t *output) { // Implement AES-CTR encryption using your crypto library // Example with mbedtls: // mbedtls_aes_context ctx; // mbedtls_aes_setkey_enc(&ctx, key, CONFIG_HUBBLE_KEY_SIZE * 8); // size_t nc_off = 0; // uint8_t stream_block[16]; // mbedtls_aes_crypt_ctr(&ctx, len, &nc_off, nonce_counter, // stream_block, data, output); return 0; } int hubble_crypto_cmac(const uint8_t key[CONFIG_HUBBLE_KEY_SIZE], const uint8_t *data, size_t len, uint8_t output[HUBBLE_AES_BLOCK_SIZE]) { // Implement AES-CMAC using your crypto library // Example with mbedtls: // mbedtls_cipher_context_t ctx; // mbedtls_cipher_cmac_starts(&ctx, key, CONFIG_HUBBLE_KEY_SIZE * 8); // mbedtls_cipher_cmac_update(&ctx, data, len); // mbedtls_cipher_cmac_finish(&ctx, output); return 0; } ``` -------------------------------- ### Enable Hubble Network Modules in Zephyr Project Configuration Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/docs/quickstart/zephyr/index.md These configuration options are added to the Zephyr project's `prj.conf` file to enable specific Hubble Network modules. `CONFIG_HUBBLE_BLE_NETWORK=y` enables the BLE Network module, and `CONFIG_HUBBLE_SAT_NETWORK=y` enables the Satellite Network module. ```none CONFIG_HUBBLE_BLE_NETWORK=y CONFIG_HUBBLE_SAT_NETWORK=y ``` -------------------------------- ### Enable Hubble Network Modules in Kconfig (Kconfig) Source: https://context7.com/hubblenetwork/hubble-device-sdk/llms.txt Enables Hubble Network modules within your Zephyr project's Kconfig configuration file (prj.conf). This example shows how to enable both BLE and optional Satellite Network modules, along with necessary Bluetooth settings and optional logging. ```kconfig # prj.conf # Enable BLE Network module CONFIG_HUBBLE_BLE_NETWORK=y # Enable Satellite Network module (optional) CONFIG_HUBBLE_SAT_NETWORK=y # Required Bluetooth settings for BLE Network CONFIG_BT=y CONFIG_BT_PERIPHERAL=y CONFIG_BT_DEVICE_NAME="Hubble Device" # Logging (optional) CONFIG_LOG=y CONFIG_LOG_DEFAULT_LEVEL=3 ``` -------------------------------- ### Add Hubble Network SDK to Zephyr Project Manifest Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/docs/quickstart/zephyr/index.md This YAML snippet configures the West sub-manifest to include the Hubble Network SDK. It specifies the remote repository and the project path within the Zephyr workspace. This is used when integrating the SDK into an existing Zephyr project. ```yaml manifest: remotes: - name: hubble url-base: https://github.com/HubbleNetwork projects: - name: hubblenetwork-sdk repo-path: hubble-device-sdk revision: main path: modules/lib/hubblenetwork-sdk remote: hubble groups: - optional ``` -------------------------------- ### CMake Project Setup for BLE Beacon Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/samples/esp-idf/ble-beacon/CMakeLists.txt Configures the CMake build system for the 'ble-beacon' project. It sets the minimum required CMake version to 3.13.1, defines additional component directories, lists the necessary components for the build, and includes the IDF project CMake script. The project is set to use the C programming language. ```cmake cmake_minimum_required(VERSION 3.13.1) set(EXTRA_COMPONENT_DIRS ../../../port/esp-idf/) set( COMPONENTS "main" "bt" "esp_timer" "hubblenetwork-sdk" ) include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(ble-beacon LANGUAGES C) ``` -------------------------------- ### Get Current Unix Timestamp in Milliseconds Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/samples/zephyr/ble-network/README.md Retrieves the current Unix timestamp in milliseconds, which is required for setting the UTC time in the Hubble Network BLE sample application. This can be achieved using Python's time module or the 'date' command with specific formatting. ```sh python -c "import time;print(int(time.time() * 1000))" date +"%s%3N" ``` -------------------------------- ### Transmit Satellite Packet with Configurable Reliability (C) Source: https://context7.com/hubblenetwork/hubble-device-sdk/llms.txt Demonstrates how to send data packets over a satellite communication channel using the `hubble_sat_packet_send` function. It shows examples for normal and high reliability modes, including packet building and error handling. Dependencies include `hubble/sat.h` and `hubble/sat/packet.h`. ```c #include #include int send_sensor_data_via_satellite(void) { struct hubble_sat_packet packet; uint64_t device_id = 0x123456789ABCDEF0; // Prepare payload uint8_t payload[] = {0x1A, 0x2B, 0x32, 0x64}; // Build the packet int ret = hubble_sat_packet_get(&packet, device_id, payload, sizeof(payload)); if (ret != 0) { printf("Failed to build packet: %d\n", ret); return ret; } // Transmit with normal reliability (balanced power/reliability) ret = hubble_sat_packet_send(&packet, HUBBLE_SAT_RELIABILITY_NORMAL); if (ret != 0) { printf("Failed to send packet: %d\n", ret); return ret; } printf("Packet transmitted successfully\n"); return 0; } // High reliability transmission (more retries, higher power consumption) int send_critical_data_via_satellite(const uint8_t *data, size_t len) { struct hubble_sat_packet packet; uint64_t device_id = 0x123456789ABCDEF0; int ret = hubble_sat_packet_get(&packet, device_id, data, len); if (ret != 0) return ret; // Use high reliability for critical data return hubble_sat_packet_send(&packet, HUBBLE_SAT_RELIABILITY_HIGH); } ``` -------------------------------- ### Initialize Hubble SDK (C) Source: https://context7.com/hubblenetwork/hubble-device-sdk/llms.txt Initializes the Hubble SDK with UTC time and an encryption key. This function must be called before any other SDK APIs. It requires the current UTC time in milliseconds and a 32-byte master encryption key. ```c #include int main(void) { // UTC time in milliseconds since Unix epoch (January 1, 1970) uint64_t current_utc_time = 1633072800000; // 256-bit encryption key (32 bytes) static uint8_t master_key[32] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20 }; int ret = hubble_init(current_utc_time, master_key); if (ret != 0) { printf("Failed to initialize Hubble SDK: %d\n", ret); return ret; } printf("Hubble SDK initialized successfully\n"); return 0; } ``` -------------------------------- ### Build and Flash Hubble BLE Beacon Application Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/samples/zephyr/ble-beacon/README.md Commands to build the Hubble BLE beacon application for the nrf52840dk board and flash it. Assumes the 'west' build system is configured. ```sh west build -b nrf52840dk/nrf52840 . west flash ``` -------------------------------- ### Build Zephyr Application with West Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/samples/zephyr/ble-network/README.md Builds the Zephyr-based Hubble Network BLE sample application using the 'west' build tool. This command compiles the application for a specified target board. Ensure you replace '' with your actual board identifier. ```sh west build -b ``` -------------------------------- ### Configure Project Build with CMake and Zephyr Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/samples/zephyr/ble-beacon/CMakeLists.txt This snippet configures the project build using CMake, specifying the minimum required CMake version and finding the Zephyr RTOS. It sets the project name to 'app' and declares C as the primary language. It also includes conditional source files based on Zephyr configuration options. ```cmake cmake_minimum_required(VERSION 3.13.1) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(app LANGUAGES C) target_sources(app PRIVATE src/main.c) target_sources_ifdef(CONFIG_HUBBLE_BEACON_SAMPLE_STORE_NONCE_SEQUENCE app PRIVATE src/store.c) ``` -------------------------------- ### Integrate Hubble SDK into FreeRTOS Makefile (Makefile) Source: https://context7.com/hubblenetwork/hubble-device-sdk/llms.txt Includes the Hubble Network SDK in a FreeRTOS Makefile-based build system. This demonstrates how to set the SDK path, include the SDK's makefile fragment, define application sources, and create build rules for SDK sources and the final application link. ```makefile # Makefile # Path to Hubble Network SDK HUBBLE_SDK_PATH = ./hubble-device-sdk # Include SDK makefile fragment include $(HUBBLE_SDK_PATH)/port/freertos/hubblenetwork-sdk.mk # Your application sources APP_SOURCES = main.c app.c # Build rule for Hubble SDK sources define HUBBLE_RULE $(basename $(notdir $(1))).obj: $(1) $(CC) $(CFLAGS) $(HUBBLENETWORK_SDK_BLE_FLAGS) -c $$< -o $$@ endef $(foreach src,$(HUBBLENETWORK_SDK_BLE_SOURCES),$(eval $(call HUBBLE_RULE,$(src)))) # Link everything together app.elf: $(APP_SOURCES:.c=.obj) $(HUBBLENETWORK_SDK_BLE_SOURCES:.c=.obj) $(CC) $(LDFLAGS) $^ -o $@ ``` -------------------------------- ### Provision BLE Beacon with Master Key and UTC Time Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/samples/zephyr/ble-beacon/README.md This script embeds a master key and the current UTC time into the device firmware. It supports both raw and base64-encoded key files. The output is written to src/key.c and src/utc.c. ```python # Script is located in SDK_BASE/tools python ../../../tools/embed_key_utc.py master.key -o ./src ``` ```python # Script is located in SDK_BASE/tools python ../../../tools/embed_key_utc.py -b master.key -o ./src ``` -------------------------------- ### Sync Time for BLE Beacon with CTS Enabled Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/samples/zephyr/ble-beacon/README.md Executes the script to synchronize the UTC time for the BLE beacon, particularly when the CONFIG_HUBBLE_BEACON_SAMPLE_USE_CTS option is enabled in the project configuration. ```sh ./sync_time.py ``` -------------------------------- ### Configure Zephyr Build with CMake Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/tests/zephyr/unit/bitarray/CMakeLists.txt This snippet configures the CMake build for a project using the Zephyr RTOS. It finds the 'unittest' component and sets up include and source directories for a target named 'testbinary'. Ensure the ZEPHYR_BASE environment variable is set correctly. ```cmake cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) target_include_directories(testbinary PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../../../include ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src ) target_sources(testbinary PRIVATE main.c ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/bitarray.c ) ``` -------------------------------- ### Apache 2.0 License Header for Source Files Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/CONTRIBUTING.md All source files in the Hubble Network SDK must include the SPDX license identifier for Apache 2.0. This ensures compliance with the project's licensing terms. The header includes copyright information and the specific license identifier. ```c /* * Copyright (c) 2025 Hubble Network, Inc. * * SPDX-License-Identifier: Apache-2.0 */ ``` -------------------------------- ### Configure Zephyr Project and Source Files with CMake Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/samples/zephyr/ble-network/CMakeLists.txt This snippet configures the CMake build for a Zephyr-based project. It sets the minimum CMake version, finds the Zephyr package, defines the project language as C, and specifies the main source file for the application target. ```cmake cmake_minimum_required(VERSION 3.13.1) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(app LANGUAGES C) target_sources(app PRIVATE src/main.c) ``` -------------------------------- ### Configure West Manifest for Hubble SDK (YAML) Source: https://context7.com/hubblenetwork/hubble-device-sdk/llms.txt Adds the Hubble Network SDK to your Zephyr project's West manifest file (west.yml). This configuration specifies the remote repository, project path, and revision for the SDK. It assumes a remote named 'hubble' is defined. ```yaml # west.yml manifest: remotes: - name: hubble url-base: https://github.com/HubbleNetwork projects: - name: hubblenetwork-sdk repo-path: hubble-device-sdk revision: main path: modules/lib/hubblenetwork-sdk remote: hubble groups: - optional ``` -------------------------------- ### Configure SDK Base Directory and Source Files (CMake) Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/port/esp-idf/hubblenetwork-sdk/CMakeLists.txt Sets the base directory for the SDK and defines the list of source files to be compiled. This includes core SDK files and platform-specific implementations. ```cmake set(SDK_BASE_DIR ../../../) set(SRCS "${SDK_BASE_DIR}/port/esp-idf/hubble_esp_idf.c" "${SDK_BASE_DIR}/port/freertos/hubble_freertos.c" "${SDK_BASE_DIR}/src/hubble.c" ) ``` -------------------------------- ### Scan and Decode Hubble BLE Beacon Advertisements Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/samples/zephyr/ble-beacon/README.md This script scans for BLE devices, identifies Hubble Network beacons, and decodes their advertisement data using a provided master key. It supports both raw and base64-encoded keys. ```python ./scan.py master.key ``` ```python ./scan.py -b master.key ``` -------------------------------- ### Configure Zephyr Build System and Application Sources (CMake) Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/tests/zephyr/ephemeris/CMakeLists.txt This snippet configures the CMake build system for a Zephyr-based project. It specifies the minimum required CMake version, finds the Zephyr package, sets the project name, and includes all C source files from the 'src/' directory into the application target. This is essential for building the embedded application within the Zephyr RTOS. ```cmake # SPDX-License-Identifier: Apache-2.0 cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(ephemeris) FILE(GLOB app_sources src/*.c) target_sources(app PRIVATE ${app_sources}) ``` -------------------------------- ### Initialize Hubble BLE Network Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/docs/ble/index.md Initializes the Hubble BLE Network with the current UTC time and an encryption key. This function must be called before other API functions. It takes the UTC time in seconds since the Unix epoch and a pointer to the encryption key as input. ```c int hubble_init(uint64_t utc_time, const void *key); ``` -------------------------------- ### Apply Component Compile Options and Definitions (CMake) Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/port/esp-idf/hubblenetwork-sdk/CMakeLists.txt Applies additional compile options and definitions to the component. This includes setting EXTRA_C_FLAGS_LIST and defining CONFIG_ESP_IDF_BUILD and WITH_POSIX for the component library. ```cmake component_compile_options(${EXTRA_C_FLAGS_LIST}) target_compile_definitions(${COMPONENT_LIB} PRIVATE CONFIG_ESP_IDF_BUILD) target_compile_definitions(${COMPONENT_LIB} PUBLIC WITH_POSIX) ``` -------------------------------- ### Ingest Scanned BLE Beacon Data into Hubble Network Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/samples/zephyr/ble-beacon/README.md Extends the scanning functionality to ingest decoded BLE beacon data into the Hubble Network. Requires setting API token and organization ID environment variables. ```sh export HUBBLE_API_TOKEN= export HUBBLE_ORG_ID= ./scan.py -i master.key ``` -------------------------------- ### Send Raw Key Data to Serial Port Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/samples/zephyr/ble-network/README.md Sends raw binary key data to the connected device's serial port. It first converts a hexadecimal key string to binary using 'xxd -r -p' and then pipes it to 'dd' for byte-by-byte transmission to the serial port (e.g., /dev/ttyACM0). ```sh xxd -r -p key.hex | dd of=/dev/ttyACM0 bs=1 ``` -------------------------------- ### Zephyr Library Configuration for Hubble SDK Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/port/zephyr/CMakeLists.txt Configures a Zephyr library for the Hubble SDK. It includes common header directories and conditionally adds source files based on network configurations (SAT_NETWORK, BLE_NETWORK). Dependencies on cryptographic libraries are also handled. ```cmake zephyr_include_directories(../../include) zephyr_library() if (CONFIG_HUBBLE_SAT_NETWORK OR CONFIG_HUBBLE_BLE_NETWORK) zephyr_library_sources(hubble_zephyr.c) zephyr_library_sources(../../src/hubble.c) zephyr_library_sources_ifdef(CONFIG_HUBBLE_BLE_NETWORK_MBEDTLS ../../src/crypto/mbedtls.c) zephyr_library_sources_ifdef(CONFIG_HUBBLE_BLE_NETWORK_PSA ../../src/crypto/psa.c) if (CONFIG_HUBBLE_BLE_NETWORK_PSA OR CONFIG_HUBBLE_BLE_NETWORK_MBEDTLS) zephyr_library_link_libraries(mbedTLS) endif() endif() if(CONFIG_HUBBLE_SAT_NETWORK) zephyr_library_sources(../../src/utils/bitarray.c) zephyr_library_sources(../../src/hubble_sat_ephemeris.c) zephyr_library_sources(../../src/hubble_sat.c) zephyr_library_sources(../../src/hubble_sat_packet.c) zephyr_library_sources(../../src/reed_solomon_encoder.c) zephyr_library_sources(hubble_sat_zephyr.c) zephyr_include_directories(.) endif() if(CONFIG_HUBBLE_BLE_NETWORK) zephyr_library_sources(../../src/hubble_ble.c) endif() ``` -------------------------------- ### Conditionally Include BLE and Crypto Sources (CMake) Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/port/esp-idf/hubblenetwork-sdk/CMakeLists.txt Appends source files for Hubble BLE network and mbedTLS crypto if the CONFIG_HUBBLE_BLE_NETWORK option is enabled. This allows for modular inclusion of features. ```cmake if(CONFIG_HUBBLE_BLE_NETWORK) list(APPEND SRCS "${SDK_BASE_DIR}/src/hubble_ble.c" "${SDK_BASE_DIR}/src/crypto/mbedtls.c" ) endif() ``` -------------------------------- ### Register ESP-IDF Component and Dependencies (CMake) Source: https://github.com/hubblenetwork/hubble-device-sdk/blob/main/port/esp-idf/hubblenetwork-sdk/CMakeLists.txt Registers the Hubble SDK as an ESP-IDF component. It specifies include directories, required dependencies like mbedTLS, FreeRTOS, and log, and lists the source files to be compiled. ```cmake idf_component_register( INCLUDE_DIRS "${SDK_BASE_DIR}/include" "${SDK_BASE_DIR}/port/esp-idf" "${SDK_BASE_DIR}/port/freertos" PRIV_INCLUDE_DIRS REQUIRES PRIV_REQUIRES "mbedtls" "freertos" "log" SRCS ${SRCS} ) ```