BLE rewrite + logging#77
Closed
zjwhitehead wants to merge 28 commits intomasterfrom
Closed
Conversation
Included motor_temp in the temps struct and updated its initialization to use telemetry.motor_temp, allowing motor temperature data to be sent via BLE telemetry.
Introduces BLE characteristics for charge and discharge MOS states in the BMS. Updates telemetry and notification logic to support these new characteristics, allowing external devices to read MOS status via BLE.
Moved BLE service and characteristic definitions from extra-data.ino into separate header and source files under inc/sp140/ble and src/sp140/ble. This modularizes BLE functionality for BMS, ESC, and configuration services, improving code organization and maintainability. Updated sp140.ino to include new BLE headers and removed legacy BLE code from extra-data.ino.
Swapped doc.containsKey(...) and settings.containsKey(...) in src/sp140/extra-data.ino:209-249 for the modern isNull() checks via doc["..."]/settings["..."], all guarded with null tests before use.
Introduces a new DEVICE_UNIQUE_ID_UUID constant and updates the BLE config service to expose the device's unique BLE address (in uppercase) as a characteristic in the device info service. The initConfigBleService function now requires the unique ID as a parameter.
Introduces a new BLE characteristic for BMS temperatures, including its UUID definition and initialization in the BMS BLE service. The characteristic supports read and notify properties and is initialized with default values.
Implements updating and notifying the BMS temperatures BLE characteristic with a bitmap and 8 temperature values in deci-degrees Celsius. This provides more detailed telemetry data for connected BLE clients.
Introduced ble_utils.h/cpp with setAndNotifyOnChange to update BLE characteristics and notify only on value changes. Updated bms_service.cpp to use this utility for failure level and MOS state characteristics, reducing unnecessary BLE notifications. Also added notification properties and descriptors to relevant characteristics.
Increased the BLE MTU to 185 in setupBLE() to improve compatibility with iOS devices, which support this size. This change helps ensure reliable BLE communication with mobile devices.
Introduces ThemeCallbacks, SeaPressureCallbacks, and MetricTempCallbacks classes to handle new BLE characteristics for theme selection, sea-level pressure, and metric temperature settings. Updates initConfigBleService to register these characteristics, enabling read/write access and validation for each setting.
Changed deviceConnected and oldDeviceConnected to volatile for thread safety. Updated BLE characteristic callbacks to use static instances instead of dynamic allocation, improving memory usage. Simplified connection checks in BLE update functions for reliability.
Co-authored-by: zjwhitehead <4623792+zjwhitehead@users.noreply.github.com>
Co-authored-by: zjwhitehead <4623792+zjwhitehead@users.noreply.github.com>
Remove manual 2902 descriptor creation as NimBLE automatically creates them for characteristics with NOTIFY or INDICATE properties. Co-authored-by: zjwhitehead <4623792+zjwhitehead@users.noreply.github.com>
Upgraded NimBLE-Arduino to v2.3.5 in platformio.ini. Refactored BLE callback methods to use new signatures with NimBLEConnInfo and removed unused NimBLE2902 include. Removed service handle count arguments from createService calls for compatibility with updated NimBLE API.
Replace ESP32 BLE library with NimBLE
Introduces functions to calculate cruise control PWM, check cruise activation range, and determine cruise disengagement in throttle.h and throttle.cpp. Refactors cruise activation logic in sp140.ino to use the new calculation function for consistent throttle behavior across modes.
Member
Author
|
@copilot how is this looking, coming back to this with fresh eyes have we missed anything? |
|
@zjwhitehead I've opened a new pull request, #84, to work on those changes. Once the pull request is ready, I'll request review from you. |
Member
Author
|
Superseded by #85 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a modular and maintainable BLE (Bluetooth Low Energy) architecture for the SP140 project, adding dedicated header and implementation files for BLE core logic, services, and utilities. It also upgrades the ESP32 platform version for improved compatibility. The changes focus on clean separation of BLE responsibilities and efficient notification handling for telemetry updates.
BLE Architecture & Core Setup:
ble_core.h) and implementation (ble_core.cpp) to encapsulate BLE initialization, server setup, connection/disconnection handling, and advertising restart logic. This centralizes BLE management and makes the codebase more maintainable. [1] [2]Service Modularization:
config_service.h), BMS telemetry (bms_service.h), and ESC telemetry (esc_service.h). Each header declares initialization and update functions for its respective BLE service. [1] [2] [3]bms_service.cpp, handling characteristic creation, deterministic startup values, and efficient notification of state changes only when necessary.BLE Utilities & Notification Efficiency:
ble_utils.h) and implementation (ble_utils.cpp) providing a templated helper for setting BLE characteristic values and notifying only when the value changes, reducing unnecessary BLE traffic. Includes specialization foruint8_ttype for binary data. [1] [2]Shared BLE Identifiers:
ble_ids.h) for all BLE UUID definitions, improving consistency and ease of reference for all BLE services and characteristics.Platform Update:
platformio.inifrom6.11.0to6.12.0for better support and stability.