Fix for the name change bug by NoahRosa · Pull Request #7 · stm32duino/SPBTLE-RF · GitHub
Skip to content
Merged
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
3 changes: 3 additions & 0 deletions README.md
7 changes: 6 additions & 1 deletion examples/SPBTLE_SensorDemo/SPBTLE_SensorDemo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
Environnemental values (Temperature, humidity and pressure) are updated each seconds.
Each minute a notification is sent to the user and seconds can be read.

Pay attention that the device name can't be more than 7 characters long. If the string
passed to the begin function is longer, it is automatically trimmed to the first 7 characters.
The BlueNRG app expects "BlueNRG" as device name, using anything else will make the device
not connectable.

*/

#include <SPI.h>
Expand All @@ -39,7 +44,7 @@ SPIClass BTLE_SPI(PIN_BLE_SPI_MOSI, PIN_BLE_SPI_MISO, PIN_BLE_SPI_SCK);
// Configure BTLE pins
SPBTLERFClass BTLE(&BTLE_SPI, PIN_BLE_SPI_nCS, PIN_BLE_SPI_IRQ, PIN_BLE_SPI_RESET, PIN_BLE_LED);

const char *name = "BlueNRG";
const char *name = "BlueNRG"; //Should be at most 7 characters
uint8_t SERVER_BDADDR[] = {0x12, 0x34, 0x00, 0xE1, 0x80, 0x03};

AxesRaw_t axes_data;
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=STM32duino SPBTLE-RF
version=1.0.2
version=1.0.3
author=STMicroelectronics, AMS, Wi6Labs
maintainer=stm32duino
sentence=This library includes drivers for ST's BlueNRG/BlueNRG-MS Bluetooth Low Energy device.
Expand Down
18 changes: 12 additions & 6 deletions src/sensor_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,18 @@ tBleStatus SensorServiceClass::begin(const char *name, uint8_t addr[BDADDR_SIZE]

int ret;

if((name == NULL) || (addr == NULL)) {
dev_nameLen = 7; // default
if(addr == NULL) {
return BLE_STATUS_NULL_PARAM;
}

if(name != NULL) {
memset(dev_name, 0, sizeof(dev_name));
dev_nameLen = (strlen(name)<7) ? strlen(name) : 7;
dev_name[0] =AD_TYPE_COMPLETE_LOCAL_NAME;
strncpy(&dev_name[1], name, dev_nameLen );
}


attach_HCI_CB(Sensor_HCI_Event_CB);

/* get the BlueNRG HW and FW versions */
Expand Down Expand Up @@ -190,7 +198,7 @@ tBleStatus SensorServiceClass::begin(const char *name, uint8_t addr[BDADDR_SIZE]
}

ret = aci_gatt_update_char_value(service_handle, dev_name_char_handle, 0,
strlen(name), (uint8_t *)name);
dev_nameLen, (uint8_t *)&dev_name[1]);

if(ret){
PRINTF("aci_gatt_update_char_value failed.\n");
Expand Down Expand Up @@ -523,15 +531,13 @@ void SensorServiceClass::setConnectable(void)
{
tBleStatus ret;

const char local_name[] = {AD_TYPE_COMPLETE_LOCAL_NAME,'B','l','u','e','N','R','G'};

if(set_connectable){
/* disable scan response */
hci_le_set_scan_resp_data(0,NULL);
PRINTF("General Discoverable Mode.\n");

ret = aci_gap_set_discoverable(ADV_IND, 0, 0, PUBLIC_ADDR, NO_WHITE_LIST_USE,
sizeof(local_name), local_name, 0, NULL, 0, 0);
1 + dev_nameLen, dev_name, 0, NULL, 0, 0);
if (ret != BLE_STATUS_SUCCESS) {
PRINTF("Error while setting discoverable mode (%d)\n", ret);
}
Expand Down
7 changes: 5 additions & 2 deletions src/sensor_service.h