diff --git a/README.md b/README.md index 4ab6710..4deff05 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,9 @@ Three services are started : Acc, Environnemental and Time. For testing the sketch, you can download on the playstore the "BLueNRG" application provided by STMicroelectronics. Launch the application and enable Bluetooth on your smartphone. Connect it to the BLueNRG device. You will see all the services, you can click on each one and read the data. +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. The SPBTLE-RF uses SPI. You need to configure the pin used for spi link. diff --git a/examples/SPBTLE_SensorDemo/SPBTLE_SensorDemo.ino b/examples/SPBTLE_SensorDemo/SPBTLE_SensorDemo.ino index 33e7ef4..fed8af5 100644 --- a/examples/SPBTLE_SensorDemo/SPBTLE_SensorDemo.ino +++ b/examples/SPBTLE_SensorDemo/SPBTLE_SensorDemo.ino @@ -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 @@ -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; diff --git a/library.properties b/library.properties index bb4b03a..f39a8bb 100644 --- a/library.properties +++ b/library.properties @@ -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. diff --git a/src/sensor_service.cpp b/src/sensor_service.cpp index 51a5d87..f0f0c0d 100644 --- a/src/sensor_service.cpp +++ b/src/sensor_service.cpp @@ -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 */ @@ -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"); @@ -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); } diff --git a/src/sensor_service.h b/src/sensor_service.h index bb4dc22..a903e12 100644 --- a/src/sensor_service.h +++ b/src/sensor_service.h @@ -74,7 +74,8 @@ * @{ */ /* Exported defines ----------------------------------------------------------*/ - +// Default Name +#define DEFAULT_DEVICE_NAME 'B','l','u','e','N','R','G' /** * @} */ @@ -108,7 +109,7 @@ class SensorServiceClass int isConnected(void); tBleStatus Add_Acc_Service(void); - tBleStatus Free_Fall_Notify(void); + tBleStatus Free_Fall_Notify(void); tBleStatus Acc_Update(AxesRaw_t *data); tBleStatus Add_Environmental_Sensor_Service(void); @@ -149,6 +150,8 @@ class SensorServiceClass volatile uint32_t press_data; volatile uint16_t hum_data; + char dev_name[8] = {AD_TYPE_COMPLETE_LOCAL_NAME, DEFAULT_DEVICE_NAME}; + uint8_t dev_nameLen; bool ledState = false; uint32_t previousMinuteValue = 0; };