Skip to content

Commit

Permalink
Merge pull request #7 from NoahRosa/master
Browse files Browse the repository at this point in the history
Fix for the name change bug
  • Loading branch information
cparata authored Apr 5, 2019
2 parents 06e1fb8 + a6f0ff6 commit 1ebc418
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
* @{
*/
/* Exported defines ----------------------------------------------------------*/

// Default Name
#define DEFAULT_DEVICE_NAME 'B','l','u','e','N','R','G'
/**
* @}
*/
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
};
Expand Down

0 comments on commit 1ebc418

Please sign in to comment.