Nano 33 BLE central logger for multiple beacons

Hello everyone,
I managed in the past to use Nano 33 as logger for analog signal and it works very well for managin buffer of different sensors and create my own structure.
Now i want to switch wireless and use BLE capacity. I bought two sensor with BLE transmission capability. Sensor read accelerometer and a Time of Flight sensor and are programmed as beacons sending the data in the Advertisement data structure.
I am able witha modified ArudinoBLE.h library to read the advertisment data of a single sensor, but i struggle (since i am a beginner with BLE ) in the logging of those data, and managing the incoming data of both sensor.
I would like to ask if someone as experience on doing something similar. How i can manage to synchronize both sensor at the same time? Is possible to read continously the data from the beacons?

I report my code here. With this code i am able to get advertisement data in HEX format from my sensor . Anyway since the ScanForAddress is done in the setup i have no chance to get multiple beacons.
I tried to do the scanForAddress recursively in the loop, but this slow down a lot the acquisition.
Anyone oen has experienced how to " catch" beacon address and recursively get the advertisement data at high frequency?


#include <ArduinoBLE.h>

void setup() {
  
  Serial.begin(9600);
  while (!Serial);

  // begin initialization
  if (!BLE.begin()) {
    Serial.println("starting BLE failed!");

    while (1);
  }

  Serial.println("BLE Central scan");

  // start scanning for peripheral
  BLE.scanForAddress("ca:df:d7:hg:fq");
  
}

void loop() {
  // check if a peripheral has been discovered
  BLEDevice peripheral = BLE.available();

  // Scan only for ATC_ devices
  if (peripheral) {

    uint8_t advertisement[28] = {0};
    int adLength = peripheral.advertisingData(advertisement,28);
    Serial.print("Advertisement 0x16: 0x");
    uint8_t sensorAdvertisementData[28];  // TODO - allocate according to length or spec
    
 // Zeroing output
   for (int x = 0; x < sizeof(sensorAdvertisementData); x++)
   {
     sensorAdvertisementData[x] = 0;
   }



  int sensorAdvertisementLength = 0;
   for (int i = 0; i < 28;) {
     int eirLength = advertisement[i++];
     int eirType = advertisement[i++];

     if (eirType == 0x16) {  // ATC custom advertisement type

       // copy each byte and print.  could have used memcpy and sprintf
       sensorAdvertisementLength = eirLength;
       for (int j = 0; j < (eirLength - 1); j++) {
         uint8_t thisByte = advertisement[i + j];
         sensorAdvertisementData[j] = thisByte;
         if (thisByte <= 0xF) Serial.print("0");
         Serial.print(thisByte,HEX);
       }
       Serial.println();
       // restart scan 
       break;
      
     }
     i += (eirLength - 1);
   }


  }
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.