This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF52 PCA10040 DK printf output via putty

I have the nRF52 PCA10040 DK device, and I'm downloading the code from the online mbed tutorial. I'm using Putty serial port to communicate with the device at 9600 baud rate. I'm trying to print out the elements of the Bluetooth beacon signals I receive from my device using the printf() function. The specific elements I'd like to print out are the manufacturer ID, time in milliseconds I received the signal, and the received signal strength in each advertising channels 37, 38, and, 39. I hope to print them out to the console, so I can have a record of the signal strengths over time. 

I'm using the example on https://ide.mbed.com/compiler/#nav:/mbed-os-example-ble-EddystoneObserver/source/main.cpp. I took out some elements that I thought were not useful to me in my goal. I'm receiving the Bluetooth beacon signals in the function "advertisementCallback", and that's the place I'm printing the applicationSpecificId, which I thought was the manufacturer ID.

I also used the nRF Connect application the RSSI Viewer plugin, but that does not keep a record of all the RSSI values I get over time.

Does anyone know how to print the elements I mentioned?

I also included the full code in this post.

#include <stdio.h>
#include <events/mbed_events.h>
#include "mbed.h"
#include "ble/BLE.h"

static const int URI_MAX_LENGTH = 18; // Maximum size of service data in ADV packets

static EventQueue eventQueue(/* event count */ 16 * EVENTS_EVENT_SIZE);

DigitalOut led1(LED1, 1);

void periodicCallback(void){
  led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */
}

/*
* This function is called every time we scan an advertisement.
*/
void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params){
  struct AdvertisingData_t {
    uint8_t length; /* doesn't include itself */
    GapAdvertisingData::DataType_t dataType;
    uint8_t data[1];
  };

  struct ApplicationData_t {
    uint8_t applicationSpecificId[2];
    uint8_t frameType;
    uint8_t advPowerLevels;
    uint8_t uriData[URI_MAX_LENGTH];
  };

  AdvertisingData_t *pAdvData;
  size_t index = 0;
  while(index < params->advertisingDataLen) {
    pAdvData = (AdvertisingData_t *)&params->advertisingData[index];
    ApplicationData_t *pAppData = (ApplicationData_t *) pAdvData->data;
    printf("%x\n", pAppData->applicationSpecificId);
    index += (pAdvData->length + 1);
  }
}

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

  if (error != BLE_ERROR_NONE) {
    return;
  }

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

  ble.gap().setScanParams(1800 /* scan interval */, 1500 /* scan window */);
  ble.gap().startScan(advertisementCallback);
}

void scheduleBleEventsProcessing(BLE::OnEventsToProcessCallbackContext* context) {
  BLE &ble = BLE::Instance();
  eventQueue.call(Callback<void()>(&ble, &BLE::processEvents));
}

int main(){
  eventQueue.call_every(500, periodicCallback);

  BLE &ble = BLE::Instance();
  ble.onEventsToProcess(scheduleBleEventsProcessing);
  ble.init(bleInitComplete);

  eventQueue.dispatch_forever();

  return 0;
}

Parents
  • Hello,

    I am not familiar with the mBed SDK. If you have questions regarding that stack, I suggest you open a ticket on the mBed forum.

    If you want to use the SDK from Nordic Semiconductor, I believe it is the retarget.c that translates from printf() to actually outputting it through the UART. It is used in the example:

    SDK\examples\ble_peripheral\ble_app_uart.

    There you can see that printf() is used in the main.c file, and it comes from including the retarget.c/h file.

    Whether this is implemented/enabled in the mBed SDK, I do not know.

    Best regards,

    Edvin

Reply
  • Hello,

    I am not familiar with the mBed SDK. If you have questions regarding that stack, I suggest you open a ticket on the mBed forum.

    If you want to use the SDK from Nordic Semiconductor, I believe it is the retarget.c that translates from printf() to actually outputting it through the UART. It is used in the example:

    SDK\examples\ble_peripheral\ble_app_uart.

    There you can see that printf() is used in the main.c file, and it comes from including the retarget.c/h file.

    Whether this is implemented/enabled in the mBed SDK, I do not know.

    Best regards,

    Edvin

Children
No Data
Related