Skip to content

Louisza patch phy #405

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ArduinoBLE
version=1.4.1
name=ArduinoBLE-CodedPHY
version=1.4.2-custom
author=Arduino
maintainer=Arduino <[email protected]>
sentence=Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev2, Arduino Nano 33 IoT, Arduino Nano 33 BLE, Nicla Sense ME and UNO R4 WiFi.
Expand Down
26 changes: 26 additions & 0 deletions src/BLEDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@

#include "BLEDevice.h"

#include "ble/AdvertisingParameters.h"
#include "ble/Gap.h"


extern "C" int strcasecmp(char const *a, char const *b);

BLEDevice::BLEDevice() :
Expand Down Expand Up @@ -576,3 +580,25 @@ bool BLEDevice::discovered()
return (_advertisementTypeMask & 0x18) != 0;
}

void BLEDevice::setTxPower(int8_t dbm) {
if (!_ble_interface.hasInitialized()) return;
_ble_interface.gap().setTxPower(dbm);
}

void BLEDevice::enableCodedPHYAdvertising(bool enabled) {
if (!_ble_interface.hasInitialized()) return;

ble::AdvertisingParameters advParams(
ble::advertising_type_t::NON_CONNECTABLE_UNDIRECTED,
Comment on lines +588 to +592
Copy link
Preview

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

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

The advertising type is hardcoded to NON_CONNECTABLE_UNDIRECTED, which may not be appropriate for all use cases. Consider making this configurable or using the existing advertising configuration.

Suggested change
void BLEDevice::enableCodedPHYAdvertising(bool enabled) {
if (!_ble_interface.hasInitialized()) return;
ble::AdvertisingParameters advParams(
ble::advertising_type_t::NON_CONNECTABLE_UNDIRECTED,
void BLEDevice::enableCodedPHYAdvertising(bool enabled, ble::advertising_type_t advType /* = ble::advertising_type_t::NON_CONNECTABLE_UNDIRECTED */) {
if (!_ble_interface.hasInitialized()) return;
ble::AdvertisingParameters advParams(
advType,

Copilot uses AI. Check for mistakes.

ble::adv_interval_t(ble::millisecond_t(200))
Copy link
Preview

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

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

The advertising interval is hardcoded to 200ms. This magic number should be made configurable or defined as a named constant to improve maintainability.

Suggested change
ble::adv_interval_t(ble::millisecond_t(200))
ble::adv_interval_t(ble::millisecond_t(DEFAULT_ADVERTISING_INTERVAL_MS))

Copilot uses AI. Check for mistakes.

);
if (enabled) {
advParams.setPhy(ble::phy_t::LE_1M, ble::phy_t::LE_CODED);
}
auto& gap = _ble_interface.gap();
gap.setAdvertisingParameters(_adv_handle, advParams);

// Set TX power here if not using setTxPower separately
Copy link
Preview

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

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

The comment is unclear about when this automatic TX power setting occurs versus when setTxPower() should be used. This could confuse users about the intended API usage pattern.

Copilot uses AI. Check for mistakes.

gap.setTxPower(4);
Comment on lines +601 to +602
Copy link
Preview

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

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

Hardcoded TX power value (4) should be made configurable or removed. This conflicts with the separate setTxPower() method and creates unexpected behavior where enabling Coded PHY always sets power to 4 dBm.

Suggested change
// Set TX power here if not using setTxPower separately
gap.setTxPower(4);
// TX power should be set via setTxPower() if needed

Copilot uses AI. Check for mistakes.

}

11 changes: 11 additions & 0 deletions src/BLEDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ class BLEDevice {
BLECharacteristic characteristic(const char * uuid) const;
BLECharacteristic characteristic(const char * uuid, int index) const;

/**
* Enable advertising on Coded PHY (long range).
* Must be called after BLE.begin() and before BLE.advertise().
*/
void enableCodedPHYAdvertising(bool enabled = true);

/**
* Set advertise and connection transmit power (in dBm, max +4 for Nano 33 BLE Rev2).
*/
void setTxPower(int8_t dbm);

protected:
friend class ATTClass;
friend class GAPClass;
Expand Down
Loading