Bluefruit nRF52 dual_bleuart - Identifying data source

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
twonius
 
Posts: 10
Joined: Wed May 29, 2013 3:36 pm

Bluefruit nRF52 dual_bleuart - Identifying data source

Post by twonius »

I've got the dual_bleuart example working but i'm not able to differentiate which bytes are coming from which device.

Looking at the rx callback and the BLEClientUART wrapper I don't see how this information is available.

Code: Select all

void cent_bleuart_rx_callback(BLEClientUart& cent_uart)
{
  char str[20+1] = { 0 };
  cent_uart.read(str, 20);
   
  Serial.print("[Cent] RX: ");
  Serial.println(str);

  if ( bleuart.notifyEnabled() )
  {
    // Forward data from our peripheral to Mobile
    bleuart.print( str );
  }else
  {
    // response with no prph message
    clientUart.println("[Cent] Peripheral role not connected");
  }  
}
I'm also only seeing output from one of the devices however if I only connect to one at a time I will see data for either (they're both flashed with the same code)
22:46:58.968 -> [Cent] RX: 246622
22:46:58.968 -> [Cent] RX:

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Bluefruit nRF52 dual_bleuart - Identifying data source

Post by mikeysklar »

@twonius,

Would it make sense to modify the code between the two nodes to be slightly different as to identify them self with each RX string?

eg.

Code: Select all

Serial.print("[Cent] RX NODE1: ");

Code: Select all

Serial.print("[Cent] RX NODE2: ");

User avatar
twonius
 
Posts: 10
Joined: Wed May 29, 2013 3:36 pm

Re: Bluefruit nRF52 dual_bleuart - Identifying data source

Post by twonius »

wouldn't i need a different rx callback for each node?

Also it'd be unlikely that the peripherals would connect in the same order, so each time you'd have a different device using a different callback.

I really need to be able to do something like pull the UUID for the device so i can append it to the readings

I wonder if this just wouldn't be an issue if i would use one of the normal profiles instead of UART e.g. weight scale

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Bluefruit nRF52 dual_bleuart - Identifying data source

Post by mikeysklar »

@twonius,

Maybe something like this scanner chunk of code would help to determine the UUID of each of your peripherals.

Code: Select all

if ( Bluefruit.Scanner.checkReportForUuid(report, CUSTOM_SERVICE) )
  {
    Serial.printf("%14s %s\n", "CUSTOM_SERVICE", "UUID Found!");
  }
viewtopic.php?f=57&t=144086&p=711347&hi ... id#p711347

User avatar
twonius
 
Posts: 10
Joined: Wed May 29, 2013 3:36 pm

Re: Bluefruit nRF52 dual_bleuart - Identifying data source

Post by twonius »

Thanks

Looking at other examples the central_bleuart_multi example gets pretty close to what I want.
Honestly i could probably make this work and just flash my devices with individual names but it'd be nice to be able to use their UUIDs instead.

I just need to find out where this struct is defined so i can see which field is the UUID.

Code: Select all

void bleuart_rx_callback(BLEClientUart& uart_svc)
{
  // uart_svc is prphs[conn_handle].bleuart
  uint16_t conn_handle = uart_svc.connHandle();

  int id = findConnHandle(conn_handle);
  prph_info_t* peer = &prphs[id];
  
  // Print sender's name
  Serial.printf("[From %s]: ", peer->name);

  // Read then forward to all peripherals
  while ( uart_svc.available() )
  {
    // default MTU with an extra byte for string terminator
    char buf[20+1] = { 0 };
    
    if ( uart_svc.read(buf,sizeof(buf)-1) )
    {
      Serial.println(buf);
      sendAll(buf);
    }
  }
}

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Bluefruit nRF52 dual_bleuart - Identifying data source

Post by mikeysklar »

You must have found this by now, but just to confirm.

Code: Select all

// Struct containing peripheral info
typedef struct
{
  char name[16+1];

  uint16_t conn_handle;

  // Each prph need its own bleuart client service
  BLEClientUart bleuart;
} prph_info_t;
prph_info_t is defined at the top of central_bleuart_multi.ino that you had been using.

User avatar
twonius
 
Posts: 10
Joined: Wed May 29, 2013 3:36 pm

Re: Bluefruit nRF52 dual_bleuart - Identifying data source

Post by twonius »

that groaning sound was not a disturbance in the force.

Thanks

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”