Skip to content

WIP:T1000E some ideas for power usage improvements #596

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

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

prusnak
Copy link

@prusnak prusnak commented Aug 9, 2025

Various T1000-E power usage improvements

This hasn't been tested on real hardware yet and is posted as a draft to discuss things

@446564
Copy link
Contributor

446564 commented Aug 9, 2025

Have you seen the testing being done on discord?

@prusnak
Copy link
Author

prusnak commented Aug 9, 2025

Have you seen the testing being done on discord?

Yes, but I do not have time to participate unfortunately.

Posted my ideas here - might be worth integrating ... or not.

Feel free to cheery-pick the changes if it makes sense.

@trakais
Copy link

trakais commented Aug 10, 2025 via email

@ripplebiz ripplebiz requested a review from fdlamotte August 14, 2025 05:44
@fdlamotte
Copy link
Collaborator

fdlamotte commented Aug 14, 2025

seems ok to me,

I'm giving it a try on a device and will merge if ok

edit: Some good ideas, but doesn't compile straight away, device is acting really weird ... I'll need some time to work on this (power optim for t1000 are on my todo ...)
edit2: changed title to reflect state of the patch

@@ -87,6 +88,9 @@ class T1000eBoard : public mesh::MainBoard {
#ifdef LED_PIN
digitalWrite(LED_PIN, LOW);
#endif

radio.sleep();
Copy link
Collaborator

Choose a reason for hiding this comment

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

On my platformio setup, it won't compile if I let this ... don't know about radio on board

@fdlamotte fdlamotte changed the title T1000E power usage improvements WIP:T1000E some ideas for power usage improvements Aug 14, 2025
@ventz
Copy link

ventz commented Aug 16, 2025

There are a few things that can be optimized from a security, performance, memory perspective.

Adding some improvements here -- @prusnak feel free to pick/choose whatever makes sense - providing as a zip (I don't want to push anything since you are making a lot of great changes!)

modified: src/helpers/nrf52/SerialBLEInterface.cpp
modified: src/helpers/nrf52/SerialBLEInterface.h
modified: variants/t1000-e/T1000eBoard.cpp

updates.zip

Key Issues Identified

1. Security Issues

  • Insufficient Authentication: While the code used MITM (Man-in-the-Middle) protection, it lacked stronger authentication mechanisms.
  • No Connection Timeout: Connected devices remained connected indefinitely, creating potential security vulnerabilities.
  • No Adaptive Security: Security levels didn't adjust based on connection failures or suspicious activities.

2. Performance Bottlenecks

  • Inefficient Reconnection Strategy: The advertising strategy used fixed intervals and timeouts, consuming unnecessary power.
  • No Rate Limiting for Reconnections: Failed connections could continuously retry without backoff periods.
  • Fixed MTU Size: The MTU size wasn't optimized for data throughput.

3. Memory/CPU Usage Issues

  • Inefficient Buffer Management: No handling for partial writes or buffer overflows.
  • Memory Leaks: Memory allocated for disconnected sessions wasn't properly released.
  • Inefficient Queue Management: The send queue used shifting operations for each deletion.

Implemented Optimizations

1. Security Enhancements

  • Improved Device Identification: Added unique device ID to BLE name for better identification.
  • Connection Timeout: Implemented a connection timeout mechanism to disconnect inactive sessions.
  • Activity Monitoring: Added tracking of communication activity to detect stale connections.

2. Power & Performance Optimizations

  • Maximum TX Power: Set TX power to maximum (4) for optimal transmission range and reliability.

  • Smart Advertising Strategy:

    • Created adaptive advertising intervals based on connection retry count
    • Adjusted timeouts based on connection history
    • Added backoff periods after multiple failed connection attempts
  • Optimized MTU Configuration: Adjusted the MTU size for better data throughput.

  • Improved Reconnection Logic: Implemented exponential backoff for reconnection attempts to reduce power consumption.

3. Memory & CPU Optimizations

  • Enhanced Buffer Management:

    • Added proper handling for partial writes
    • Implemented flow control checking with bleuart.notifyEnabled()
  • Optimized Queue Management: More efficient handling of the send queue with proper error checking.

4. Code Quality Improvements

  • Better Error Handling: Added checks for error conditions during BLE operations.
  • Improved Logging: Enhanced debug logging for better troubleshooting.
  • Code Documentation: Added comments explaining the purpose and functionality of complex sections.

Implementation Details

The optimizations were implemented in two main files:

  1. variants/t1000-e/T1000eBoard.cpp:

    • Enhanced the OTA update implementation (currently disabled)
    • Improved the BLE initialization process
    • Added more descriptive comments
  2. src/helpers/nrf52/SerialBLEInterface.cpp and SerialBLEInterface.h:

    • Implemented adaptive power management
    • Added connection retry limiting and backoff
    • Improved buffer handling and flow control
    • Added activity monitoring and timeout handling
    • Implemented more efficient queue management

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