cancel
Showing results for 
Search instead for 
Did you mean: 

Problem application bluetooth don't send character and display Error 507 on app with mbed program

Alexandre Patras
Associate II
Posted on February 27, 2017 at 15:26

Hello,

I've got a problem with this program I can't send a character with an application btle 'Error 507' Displayed on the app.What's the problem?

/* mbed Microcontroller Library

  • Copyright (c) 2006-2015 ARM Limited
  • Licensed under the Apache License, Version 2.0 (the 'License');
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at
  • http://www.apache.org/licenses/LICENSE-2.0

  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an 'AS IS' BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.
  • /
  1. include 'mbed.h'
  2. include 'ble/BLE.h'
  3. include 'ble/services/HeartRateService.h'

DigitalOut led1(LED1, 1);

const static char DEVICE_NAME[] = 'HRM1'; static const uint16_t uuid16_list[] = {GattService::UUID_HEART_RATE_SERVICE};

static volatile bool triggerSensorPolling = false;

void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) { (void)params; BLE::Instance().gap().startAdvertising(); restart advertising }

void periodicCallback(void) { led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */ /* Note that the periodicCallback() executes in interrupt context, so it is safer to do

  • heavy-weight sensor polling from the main thread. */ triggerSensorPolling = true; }

void onBleInitError(BLE &ble, ble_error_t error) { (void)ble; (void)error; /* Initialization error handling should go here */ }

void bleInitComplete(BLE::InitializationCompleteCallbackContext *params) { BLE& ble = params->ble; ble_error_t error = params->error;

if (error != BLE_ERROR_NONE) { onBleInitError(ble, error); return; }

if (ble.getInstanceID() != BLE::DEFAULT_INSTANCE) { return; }

ble.gap().onDisconnection(disconnectionCallback);

/* Setup primary service. */ uint8_t hrmCounter = 60; init HRM to 60bps HeartRateService hrService(ble, hrmCounter, HeartRateService::LOCATION_HAND);

/* Setup advertising. */ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list)); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_HEART_RATE_SENSOR); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.gap().setAdvertisingInterval(1000); /* 1000ms */ ble.gap().startAdvertising();

infinite loop while (true) { check for trigger from periodicCallback() if (triggerSensorPolling && ble.getGapState().connected) { triggerSensorPolling = false;

Do blocking calls or whatever is necessary for sensor polling. In our case, we simply update the HRM measurement. hrmCounter++;

60 <= HRM bps <= 100 if (hrmCounter == 100) { hrmCounter = 60; }

update bps hrService.updateHeartRate(hrmCounter); } else { ble.waitForEvent(); low power wait for event

} } } Serial BT(PA_2,PA_3); tx, rxb Serial pc(USBTX, USBRX); int main(void) { pc.baud(115200); BT.baud(115200); Ticker ticker; ticker.attach(periodicCallback, 1); blink LED every second

BLE::Instance().init(bleInitComplete); { while (BT.available() > 0) { read the incoming byte: char incomingByte = BT.readable(); printf('I received:'); BT.putc(incomingByte);

} } }

Thank you for your answers.

Alexandre Patras

#bluetooh #x-nucleo-idb05a1 #nucleo-stm32l476rg #mbed
4 REPLIES 4
Antonio Vilei
Senior III
Posted on February 28, 2017 at 11:30

Hi Alexandre,

which STM32 Nucleo board are you using in your setup?

And what about the BLE board? Is it the X-NUCLEO-IDB05A1? Please notice that the old X-NUCLEO-IDB04A1 is not recommended any more.

Also, what application are you using on your phone? Is it the STM32 BLE Profiles? For which phone OS?

You may find additional information on the dedicated mbed pages for X-NUCLEO-IDB05A1:

https://developer.mbed.org/components/X-NUCLEO-IDB05A1-Bluetooth-Low-Energy/

Depending on the STM32 Nucleo board you are using, please make sure you check the note about Arduino Connector Compatibility.

Best regards,

Antonio

Alexandre Patras
Associate II
Posted on February 28, 2017 at 11:55

Hi Vilei.Antonio,

I use a Nucleo STM32-L476RG with the bluetooth expansion 

the X-NUCLEO-IDB05A1 and i use a Samsung galaxy S4 with this application.0690X00000606LeQAI.png

0690X00000606OnQAI.png

Best regards,

Alexandre

Posted on March 02, 2017 at 18:32

Dear Alexandre,

the error code that you get is related to your smartphone app, which is not developed by ST, so I don't know what that error code means.

Anyway, your STM32 code implements the Heart Rate Monitor (HRM) profile, i.e. it simulates sending heart rate information from your device to your phone.

In your app, you're trying to send some arbitrary text to the BLE device (which is not expecting it) and this is probably why you're getting an error.

If you want to test the correct behavior of your board, you can use the STM32 BLE Profiles app:

https://play.google.com/store/apps/details?id=com.stm.bluetoothlevalidation

Hope that helps,

Antonio

Posted on March 02, 2017 at 18:58

My objective is  to display on a display the temperature and the pressure of a room with the 

Nucleo STM32-L476RG in bluetooth communication with 

the X-NUCLEO-IDB05A1 using the mbed online software and I don't know how to do it ?

If you can help me,

Alexandre