Hi,
I am using the BLECentralRole library and the "scanner" example by Chiara Ruggeri.
This works great and this call "peer.printAdvertisement();"
prints the entire advertising packet received:
------------------------------------------------------------
Received adverstisement packet from node da:b7:3f:65:6d:78
RSSI -50 (dBm). Non connectable undirected node
Flags : BrEdrNotSupported
Manufacturer data: 0x590002150112233445566778899AABBCCDDEEFF001020304C3
Scan response received from node da:b7:3f:65:6d:78
Complete Local Name: ECO
------------------------------------------------------------
How can I extract/parse just the:
MAC address
Complete Local Name
RSSI
from the advertising packet?
Please show your code. Most of us will not dig the web to find the example. And add a link to the library.
If it's in a c-style string, you can use strstr() to find keywords like node, go a number of positions forward and read N characters and store that in a char array; don't forget to add a terminating nul character.
/*
scanner.ino
Written by Chiara Ruggeri (chiara@arduino.org)
This example for the Arduino Primo board implements the
Observer role of the BLE protocol.
Once scan parameters are set, the sketch continuously
listen for advertising packets.
This example code is in the public domain.
*/
#include "BLECentralRole.h"
// download ArduinoLowPower library from library manager to enter in low power mode
#include "ArduinoLowPower.h"
// create central instance
BLECentralRole bleCentral = BLECentralRole();
void setup() {
Serial.begin(9600);
// assign event handler for scanReceived event
bleCentral.setEventHandler(BLEScanReceived, receiveAdvPck);
// set scan parameters
// interval and window in 0.625 ms increments
bleCentral.setScanInterval(3200); // 2 sec
//bleCentral.setScanWindow(800); // 0.5 sec
bleCentral.setScanWindow(1600); // 1 sec
// timeout in seconds. 0 disables timeout
bleCentral.setScanTimeout(0);
// active scan true to ask for scan response packet
bleCentral.setActiveScan(true);
// begin initialization and start scanning
bleCentral.begin();
}
void loop() {
// since we want to realize a low power application we don't handle the
// BLE_LED in order to save power but put the board in low power mode instead.
LowPower.sleep();
}
void receiveAdvPck(BLEPeripheralPeer& peer){
char advertisedName[31];
byte len;
// search for a device that advertises "ECO" name
peer.getFieldInAdvPck(BLE_GAP_AD_TYPE_SHORT_LOCAL_NAME, advertisedName, len);
if(len == 0) // field not found
peer.getFieldInAdvPck(BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME, advertisedName, len);
if(len != 0){ // the field was found
if(!strcmp(advertisedName, "ECO")) // Name found.
{
Serial.print("Name ECO found: ");
Serial.println(advertisedName);
// Correct name found - Now get RSSI
Serial.print("RSSI: ");
}
else // Name NOT found.
{
Serial.println("Name ECO not found");
}
}
}