Conenct NANO 33 BLE & NANO 33 SENSE via BLE library

Hi to all,

I want to create a little meteorologicel station with Arduino. The first idea was used NANO 33 SENSE to provide information about temperature, humidity and barometric pressure (peripheric) to NANO 33 BLE (central). I tried several times but the program did not work (it did not connect between devices). So I have changed my idea and have simplify it.
Now both devices get conection with BLE, but it do not go ahead (not send/receive infromation).

I show you both codes that I programmed on them. Please, can you check my codes and give me any information that you find on it or code that I did not develop yet?

If you know another tutorial of BLE library that appears in Arduino’s web page, please, can you share? Thanks in advance.

Here appears both codes and the serial monitor show when them are working. Sorry, you will find all comments and serial messages in Spanish, I hope it will not be a problem for you.

Code of Arduino NANO 33 BLE, central device:

#include <ArduinoBLE.h> //libreria Bluetooth
BLEIntCharacteristic Caracteristica1("0002", BLERead | BLENotify);  //declaramos caracteristica numero al servicio Servicio
unsigned int mseg = 4000;
bool ScanActive = 0;
int cuenta;

void setup() {
  // put your setup code here, to run once:
  delay(mseg);
  Serial.begin(9600); //inicializamos la comunicacion monitor serie

  if (!BLE.begin()) { //inicializamos Bluetooth
    Serial.println("Fallo al inicializar BLE");
    while (1);
  }

  Serial.println("Inicializamos el dispositivo BlueTooth central");
  delay(mseg);

  BLE.setLocalName("MiCentral");  //set nombre local

  BLE.setConnectable(true); //el periferico es conectable después de publicitarlo
  Serial.println("Indicamos dispositivo BLE central conectable");
  delay(mseg);

}

void loop() {
  // put your main code here, to run repeatedly:
  if (!ScanActive) {
    BLE.scan();
    Serial.println("Escaneamos en busca de dispositivo BLE periferico");
    ScanActive = 1;
    delay(mseg);
  }
  BLEDevice periferico = BLE.available();  //dispositivo periferico disponible
  Serial.println(periferico);

  if (periferico) { //el dispositivo BLE esta disponible
    Serial.println("Dispositivo BLE periferico esta disponible");
    Serial.println(periferico);
    delay(mseg);

    if (periferico.hasLocalName()) { //dispone de localName?
      Serial.print("Local name: ");
      Serial.println(periferico.localName());
    } //end haslocalname
    else Serial.println("Local name: no encontrado");

    if (periferico.hasAdvertisedServiceUuid()) { //dispone de Servicios?
      Serial.print("Service UUIds: ");
      for (int i = 0; i < periferico.advertisedServiceUuidCount(); i++) {
        Serial.print(periferico.advertisedServiceUuid(i));
        Serial.print(" ");
      } //end for
      Serial.println();
    } //end hasadvertisedserviceuuid
    else Serial.println("Service UUIDs: no encontrados");
    delay(mseg);

    if (periferico.localName() == "MiPeriferico") { //encontramos el dispositivo BLE que buscamos
      BLE.stopScan(); //paramos el escaneo de dispositivos.
      Serial.println("Conectando...");
      delay(mseg);

      if (periferico.connect()) { //Conectamos al dispositivo BLE encontrado
        Serial.println("Conectado");
        delay(mseg);

        //añadimos descubrir atributos
        Serial.println("Discovering attributes ...");
        if (periferico.discoverAttributes()) {
          Serial.println("Atributos descubiertos");
        } else {
          Serial.println("Fallo al descubrir atributos");
        }
        delay(mseg);
        //fin del añadido descubrir atributos

        Serial.print("Device name: ");
        Serial.println(periferico.deviceName());
        Serial.print("Local name: ");
        Serial.println(periferico.localName());
        delay(mseg);

        if (Caracteristica1.valueUpdated()) {
          cuenta = Caracteristica1.value();
          Serial.println(cuenta);
          delay(mseg);
        } //end valueupdated

      } //end periferico.connect
      else {
        Serial.println("Fallo en la conexion");
        //        BLE.disconnect();
        periferico.disconnect();
        Serial.println("Desconectado");
        ScanActive = 0;
      } //end else
      delay(mseg);
    } //end periferico.localName
  } //end periferico
  else {
    Serial.println("Dispositivo BLE periferico no esta disponible");
    Serial.println(periferico);
    BLE.disconnect();
    ScanActive = 0;
    delay(mseg);
  } //end else

} //end loop

Code of Arduino NANO 33 SENSE, peripherical device:

#include <ArduinoBLE.h> //libreria Bluetooth
BLEService Servicio("0001");  //declaramos el servicio Servicio
BLEIntCharacteristic Caracteristica1("0002", BLERead | BLENotify);  //declaramos caracteristica numero al servicio Servicio
int cuenta = 0;
unsigned int mseg = 4000;
bool Add = 0;

void setup() {
  // put your setup code here, to run once:
  delay(mseg);
  Serial.begin(9600); //inicializamos la comunicacion monitor serie

  if (!BLE.begin()) { //inicializamos Bluetooth
    Serial.println("fallo al inicializar BLE");
    while (1);
  }

  Serial.println("Inicializamos el dispositivo BlueTooth periferico");
  delay(mseg);

  BLE.setLocalName("MiPeriferico");  //set nombre local

  BLE.setAdvertisedService(Servicio); //indicamos que el servicio tambien se publicite

  Servicio.addCharacteristic(Caracteristica1);  //añadimos caracteristica Caracteristica al servicio Servicio

  BLE.addService(Servicio); //añadimos el servicio

  BLE.setConnectable(true); //el periferico es conectable después de publicitarlo
  Serial.println("Indicamos dispositivo BLE periferico conectable");
  delay(mseg);

}

void loop() {
  // put your main code here, to run repeatedly:
  if (!Add) {
    if (BLE.advertise()) { //publicitando periferico
      Serial.println("Dispositivo BLE periferico visible");
      Add = 1;
    }
    else {
      Serial.println("Dispositivo BLE periferico no visible");
      Add = 0;
    }
    delay(mseg);
  }
  BLEDevice zentral = BLE.central(); //preguntamos si central se ha conectado
  Serial.println("Dispositivo BLE central conectando...");
  delay(mseg);

  if (zentral) {  //si Lector esta disponible
    Serial.println("Dispositivo BLE central conectado");
    delay(mseg);

    while (zentral.connected()) {  //y mientras central permanezca conectado
      Caracteristica1.writeValue(cuenta);
      Serial.println(cuenta);
      cuenta++;
      if (cuenta == 30000) {
        cuenta = 0;
      }
    }
  }
  else {
    Serial.println("Dispositivo BLE central no conectado");
    Add = 0;
  }
  delay(mseg);

}

Serial monitor messages from central device:

20:20:31.429 -> Indicamos dispositivo BLE central conectable
20:20:35.469 -> Escaneamos en busca de dispositivo BLE periferico
20:20:39.469 -> 1
20:20:39.469 -> Dispositivo BLE periferico esta disponible
20:20:39.469 -> 1
20:20:43.449 -> Local name: MiPeriferico
20:20:43.449 -> Service UUIds: 0001
20:20:47.489 -> Conectando...
20:20:51.489 -> Conectado
20:20:55.480 -> Discovering attributes ...
20:21:05.079 -> Fallo al descubrir atributos
20:21:09.079 -> Device name:
20:21:09.079 -> Local name: MiPeriferico
20:21:17.078 -> 0
20:21:17.078 -> Dispositivo BLE periferico no esta disponible
20:21:17.078 -> 0
20:21:22.109 -> Escaneamos en busca de dispositivo BLE periferico
20:21:26.109 -> 1
20:21:26.109 -> Dispositivo BLE periferico esta disponible
20:21:26.109 -> 1
20:21:30.109 -> Local name: MiPeriferico
20:21:30.109 -> Service UUIds: 0001
20:21:34.093 -> Conectando...
20:21:38.253 -> Conectado
20:21:42.253 -> Discovering attributes ...
20:21:50.172 -> Fallo al descubrir atributos
20:21:54.172 -> Device name:
20:21:54.172 -> Local name: MiPeriferico
20:22:02.172 -> 0
20:22:02.172 -> Dispositivo BLE periferico no esta disponible
20:22:02.172 -> 0

Serial monitor messages from peripherical device:

20:23:11.770 -> Inicializamos el dispositivo BlueTooth periferico
20:23:15.769 -> Indicamos dispositivo BLE periferico conectable
20:23:19.799 -> Dispositivo BLE periferico visible
20:23:23.800 -> Dispositivo BLE central conectando...
20:23:27.813 -> Dispositivo BLE central no conectado
20:23:31.821 -> Dispositivo BLE periferico no visible
20:23:35.810 -> Dispositivo BLE central conectando...
20:23:39.820 -> Dispositivo BLE central no conectado
20:23:43.819 -> Dispositivo BLE periferico no visible
20:23:47.819 -> Dispositivo BLE central conectando...
20:23:51.819 -> Dispositivo BLE central no conectado
20:23:55.859 -> Dispositivo BLE periferico visible
20:23:59.840 -> Dispositivo BLE central conectando...
20:24:03.873 -> Dispositivo BLE central conectado
20:24:07.874 -> 0
20:24:07.874 -> 1
...

rsanalo:
Sorry, you will find all comments and serial messages in Spanish, I hope it will not be a problem for you.

May I be honest here? I am not a native English speaker and some of my country men do the same thing and it makes programming so much harder. It drives me nuts. You must read two languages, have more chance of errors, can’t use tutorials and examples without changes and it makes it harder for others to help. For instance, your own code, why do you write zentral and central?

while ( zentral.connected() ) //y mientras central permanezca conectado

I can only recommend use the language of the programming language. This will make your life a lot easier in the long run.

rsanalo:
I want to create a little meteorologicel station with Arduino. The first idea was used NANO 33 SENSE to provide information about temperature, humidity and barometric pressure (peripheric) to NANO 33 BLE (central).

Do you still like to do this? I can help you.

The first issues I came across with the peripheral.

  • You should not use delay() especially with communication stacks. On the Nano 33 BLE it puts the system to sleep. You want to exchange data packets. Your Arduino is no human it does not need vacation. You can use delay for sleeping/power saving when you know what you are doing. For now, do not use it. Use an application like BLE Scanner on a smartphone and connect to your device (I use it on iPhone). You will see that everything is slow and information (the available service) is displayed with a very long delay. Most users would have closed the app after 3 seconds. :slight_smile:

  • For your own characteristics and services, you must use 128-bit random UUIDs. You can use a UUID creator online or write yourself a script.

You can use 16-bit UUIDs for things standardized by the Bluetooth SIG

Some little stuff

I would change your variables names

  • Add: should not be a variable name, is this about addition?
  • Caracteristica1: is that a one or L? What do you do when you have more characteristics? I prefer obvious names for BLE e.g. humidityCharacteristic
  • mseg - is that a millisecond? No. Its a constant value chosen by you. Many use capital with underscore for constant naming e.g. JUST_SOME_DELAY

I would set bool variables with TRUE and FALSE. With good variable names the statements are easier to understand. Add = 1 -> advertismentEnabled = TRUE -> if ( advertismentEnabled )

I would recommend to first make sure the peripheral work fine with a smartphone BLE app (does not need to be complete but basics should work) and then look at the central.

Thanks to all for taking a look of my post and thaks a lot to Klaus_K for give a answer on it.

I will do a simple meteo when I get more knowledge about BLE and this little project works without problems (I hope it happens soon) :slight_smile:

I give you answer about questions that you posted:

  • zentral: I used zentral instead of central because it appears in red (like a special word in the library) and, when I perform the first time it did not work (or I did not understand it).
  • delay: I used it in the program with serial monitor to get information that I could follow, but you are right, I did not think about the time use BLE devices to communicate between them. Now I delete in the new version of perfipherical program and serial monitor goes like a thunder, I can not follow all print that I include in the code but It works.
  • BLE Scanner: I download to my tablet and now I can see my NANO 33 SENSE (peripheral device) on it. I can connect with it. I can see “GENERIC ACCESS”, “GENERIC ATTRIBUTE” (these ones I do not perform so I believe that is another layer of Bluetooth specifications). I can see a “CUSTOM SERVICE” with UUID I type in the code. And I can see a “CUSTOM CHARACTERISTIC” with UUID I type, and I see the properties, sometimes appears “VALUE” that show some characters, and finally I see “HEX” with values in hexadecimal.
  • UUID: in this program I type two diferent 128-bit UUID that you can check in the code.

I follow your recomendations and change the name of variables like: ‘Add’ → ‘advertiseHabilitado’ or ‘Caracteristica1’ → ‘Caracteristica’.
The same with the boolean variables.

The new code, with your indications is here:

#include <ArduinoBLE.h> //libreria Bluetooth
BLEService Servicio("00000001-0001-0001-0001-000000000001");  //declaramos el servicio Servicio
BLEIntCharacteristic Caracteristica("00000001-0001-0001-0001-000000000002", BLERead | BLENotify);  //declaramos caracteristica Caracterisitca al servicio Servicio
int cuenta = 0;
bool advertiseHabilitado = false;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600); //inicializamos la comunicacion monitor serie

  if (!BLE.begin()) { //inicializamos Bluetooth
    Serial.println("fallo al inicializar BLE");
    while (1);
  }

  Serial.println("Inicializamos el dispositivo BlueTooth periferico");

  BLE.setLocalName("MiPeriferico");  //set nombre local

  BLE.setAdvertisedService(Servicio); //indicamos que el servicio tambien se publicite

  Servicio.addCharacteristic(Caracteristica);  //añadimos caracteristica Caracteristica al servicio Servicio

  BLE.addService(Servicio); //añadimos el servicio

  BLE.setConnectable(true); //el periferico es conectable después de publicitarlo
  Serial.println("Indicamos dispositivo BLE periferico conectable");

}

void loop() {
  // put your main code here, to run repeatedly:
  if (!advertiseHabilitado) {
    if (BLE.advertise()) { //publicitando periferico
      Serial.println("Dispositivo BLE periferico visible");
      advertiseHabilitado = true;
    }
    else {
      Serial.println("Dispositivo BLE periferico no visible");
      advertiseHabilitado = false;
    }
  }
  BLEDevice central = BLE.central(); //preguntamos si central se ha conectado
  Serial.println("Dispositivo BLE central conectando...");

  if (central) {  //si Lector esta disponible
    Serial.println("Dispositivo BLE central conectado");

    while (central.connected()) {  //y mientras central permanezca conectado
      Caracteristica.writeValue(cuenta);
      Serial.println(cuenta);
      cuenta++;
      if (cuenta == 30000) {
        cuenta = 0;
      }
    }
  }
  else {
    Serial.println("Dispositivo BLE central no conectado");
    advertiseHabilitado = false;
  }

}

Now your sketch is responsive. Well done. :slight_smile:

Why do you call BLE advertise again and again? You only need to do this once.

Your UUID are 128-bit now, but not random. :slight_smile:

Here is an example I wrote for a Environmental Sensing Service using the sensors on the NANO 33 BLE. I used the 16-bit UUID defined by the Bluetooth SIG. Links and information are in the source code.

/*
  This example creates a BLE peripheral with a Environmental Sensing Service (ESS)
  that contains a temperature and a humidity characteristic.
  The yellow LED shows the BLE module is initialized.
  The green LED shows RSSI of zero. The more it blinks the worse the connection.

  The circuit:
  - Arduino Nano 33 BLE Sense board.

  You can use a generic BLE central app, like LightBlue (iOS and Android) or
  nRF Connect (Android), to interact with the services and characteristics
  created in this sketch.

  This example code is in the public domain.
*/

#include <ArduinoBLE.h>
#include <Arduino_HTS221.h>

//----------------------------------------------------------------------------------------------------------------------
// BLE UUIDs
//----------------------------------------------------------------------------------------------------------------------

// https://www.bluetooth.com/specifications/assigned-numbers/environmental-sensing-service-characteristics/

#define BLE_UUID_ENVIRONMENTAL_SENSING_SERVICE    "181A"
#define BLE_UUID_TEMPERATURE                      "2A6E"
#define BLE_UUID_HUMIDITY                         "2A6F"

//----------------------------------------------------------------------------------------------------------------------
// BLE
//----------------------------------------------------------------------------------------------------------------------

BLEService environmentalSensingService( BLE_UUID_ENVIRONMENTAL_SENSING_SERVICE );
BLEShortCharacteristic temperatureCharacteristic( BLE_UUID_TEMPERATURE, BLERead | BLENotify );
BLEUnsignedShortCharacteristic humidityCharacteristic( BLE_UUID_HUMIDITY, BLERead | BLENotify );

const int BLE_LED_PIN = LED_BUILTIN;
const int RSSI_LED_PIN = LED_PWR;


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

  pinMode( BLE_LED_PIN, OUTPUT );
  pinMode( RSSI_LED_PIN, OUTPUT );

  // Without Serial when using USB power bank HTS sensor seems to needs some time for setup
  delay( 10 );
  
  if ( !HTS.begin() )
  {
    Serial.println( "Failed to initialize Humidity Temperature Sensor!" );
    while ( 1 )
    {
      digitalWrite( BLE_LED_PIN, HIGH );
      delay(100);
      digitalWrite( BLE_LED_PIN, LOW );
      delay(1000);
    }
  }

  if( setupBleMode() )
  {
    digitalWrite( BLE_LED_PIN, HIGH );
  }
}


void loop()
{
  static long previousMillis = 0;
  #define SENSOR_UPDATE_INTERVAL 1000

  // listen for BLE peripherals to connect:
  BLEDevice central = BLE.central();

  if ( central )
  {
    Serial.print( "Connected to central: " );
    Serial.println( central.address() );

    while ( central.connected() )
    {
      unsigned long currentMillis = millis();
      if( currentMillis - previousMillis > SENSOR_UPDATE_INTERVAL )
      {
        previousMillis = currentMillis;

        Serial.print( "Central RSSI: " );
        Serial.println( central.rssi() );

        if( central.rssi() != 0 )
        {
          digitalWrite( RSSI_LED_PIN, LOW );

          // BLE defines Temperature UUID 2A6E Type sint16
          // Unit is in degrees Celsius with a resolution of 0.01 degrees Celsius
          int16_t temperature = round( HTS.readTemperature() * 100.0 );
          temperatureCharacteristic.writeValue( temperature );

          // BLE defines Humidity UUID 2A6F Type uint16
          // Unit is in percent with a resolution of 0.01 percent
          uint16_t humidity = round( HTS.readHumidity() * 100.0 );
          humidityCharacteristic.writeValue( humidity );
        }
        else
        {
          digitalWrite( RSSI_LED_PIN, HIGH );
        }
      }
    }
    Serial.print( F( "Disconnected from central: " ) );
    Serial.println( central.address() );
  }
}


bool setupBleMode()
{
  if ( !BLE.begin() )
  {
    return false;
  }

  // set advertised local name and service UUID:
  BLE.setDeviceName( "Arduino Nano 33 BLE" );
  BLE.setLocalName( "Arduino Nano 33 BLE" );
  BLE.setAdvertisedService( environmentalSensingService );

  // BLE add characteristics
  environmentalSensingService.addCharacteristic( temperatureCharacteristic );
  environmentalSensingService.addCharacteristic( humidityCharacteristic );

  // add service
  BLE.addService( environmentalSensingService );

  // set the initial value for the characeristic:
  temperatureCharacteristic.writeValue( 0 );
  humidityCharacteristic.writeValue( 0 );

  // start advertising
  BLE.advertise();

  return true;
}

Thanks Klaus_K, it was too hard to do it :stuck_out_tongue: .

I call BLE.advertise() every cycle because I will connect two NANO 33 SENSE to NANO 33 BLE so NANO 33 BLE will connect and disconnect to the peripherals, but for this project, for sure it is not needed.

Do you know any function that generates UUID numbers?

And finally I create a central program that it works… not really ok. I can connect with peripheral device and serial monitor can show me values (you can see below), but the problem with the values what central device gets from peripheral devices is limited to byte data type (peripheral device works with integer data type) so I can not see the real values that peripheral counts.

And I show you at the end of this reply my “Enviromental Sensing Device” that it works (similar results that I get with peripheral program) in BLE Scanner.

Code that works (almost) well (central device):

#include <ArduinoBLE.h> //libreria Bluetooth

bool ScanActive = false;  //Indicar si scan() esta activo

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600); //inicializamos la comunicacion monitor serie

  if (!BLE.begin()) { //inicializamos Bluetooth
    Serial.println("Fallo al inicializar BLE");
    while (1);
  }

  Serial.println("Inicializamos el dispositivo BlueTooth central");

  BLE.setLocalName("MiCentral");  //set nombre local

}

void loop() {
  // put your main code here, to run repeatedly:
  if (!ScanActive) {  //si ScanActive = false escaneamos BLE devices
    BLE.scan(); //Dispositivo BLE escaneando perifericos
    Serial.println("Escaneamos en busca de dispositivo BLE periferico");
    ScanActive = true;
  }
  BLEDevice peripheral = BLE.available();  //dispositivo peripheral disponible
  Serial.println(peripheral);

  if (peripheral) { //el dispositivo BLE esta disponible
    Serial.println("Dispositivo BLE periferico esta disponible");

    if (peripheral.hasLocalName()) { //dispone de localName?
      Serial.print("Local name: ");
      Serial.println(peripheral.localName());
    } //end haslocalname
    else Serial.println("Local name: no encontrado");

    if (peripheral.hasAdvertisedServiceUuid()) { //dispone de Servicios?
      Serial.print("Service UUIDs: ");
      for (int i = 0; i < peripheral.advertisedServiceUuidCount(); i++) {
        Serial.print(peripheral.advertisedServiceUuid(i));
        Serial.print(" ");
      } //end for
      Serial.println();
    } //end hasadvertisedserviceuuid
    else Serial.println("Service UUIDs: no encontrados");

    if (peripheral.localName() == "MiPeriferico") { //encontramos el dispositivo BLE que buscamos
      BLE.stopScan(); //paramos el escaneo de dispositivos.
      ScanActive = 0;
      Serial.println("Conectando...");

      bool Conectado = peripheral.connect();  //conectamos con el periferico

      if (Conectado) { //Conectamos al dispositivo BLE encontrado
        Serial.println("Conectado");

        if (peripheral.discoverAttributes()) {  //descubrimos los atrivutos del periferico
          Serial.println("Atributos descubiertos");
        }
        else Serial.println("No Atributos");

        BLECharacteristic Caracteristica = peripheral.characteristic("00000001-0001-0001-0001-000000000002"); //creamos caracteristica como la que nos da el periferico

        Serial.print("Device name: ");
        Serial.println(peripheral.deviceName());
        Serial.print("Local name: ");
        Serial.println(peripheral.localName());

        int numero_Caracteristicas = peripheral.characteristicCount();  //numero de caracteristicas del periferico
        Serial.print("Caracteristicas encontradas: ");
        Serial.println(numero_Caracteristicas);

        Serial.print("Tamaño del valor = ");  //tamaño en bytes del valor del periferico
        Serial.print(Caracteristica.valueSize());
        Serial.println(" bytes");

        byte value;
        while (!ScanActive) { //mientras NO este el scan() activo (hemos conectado con el perifercio)
          Caracteristica.readValue(value);  //leemos el valor que nos entrega el periferico.
          Serial.print("Valor leido del periferico: ");
          Serial.println(value);
        }

      } //end peripheral.connect
      else {
        Serial.println("Fallo en la conexion");
        //        peripheral.disconnect();
        Serial.println("Desconectado");
        ScanActive = false;
      } //end else
    } //end peripheral.localName
  } //end peripheral
  else {
    Serial.println("Dispositivo BLE periferico no esta disponible");
    Serial.println(peripheral);
    ScanActive = false;
  } //end else
  delay(1000);
} //end loop

Here you can see messages from serial monitor:

20:31:29.167 -> 1
20:31:29.167 -> Dispositivo BLE periferico esta disponible
20:31:29.167 -> Local name: MiPeriferico
20:31:29.167 -> Service UUIDs: 00000001-0001-0001-0001-000000000001 
20:31:29.201 -> Conectando...
20:31:29.273 -> Conectado
20:31:30.122 -> Atributos descubiertos
20:31:30.122 -> Device name: Arduino
20:31:30.122 -> Local name: MiPeriferico
20:31:30.122 -> Caracteristicas encontradas: 4 <- this value is not correct, there is 1 characteristic
20:31:30.122 -> Tamaño del valor = 0 bytes <-this value is not correct too
20:31:30.122 -> Valor leido del periferico: 199 <-this value never shows more than 255
20:31:30.122 -> Valor leido del periferico: 192
20:31:30.122 -> Valor leido del periferico: 178
20:31:30.122 -> Valor leido del periferico: 170
20:31:30.122 -> Valor leido del periferico: 162
20:31:30.122 -> Valor leido del periferico: 219
20:31:30.152 -> Valor leido del periferico: 48
20:31:30.192 -> Valor leido del periferico: 130
20:31:30.231 -> Valor leido del periferico: 149
20:31:30.272 -> Valor leido del periferico: 146
20:31:30.339 -> Valor leido del periferico: 142

Here I show you my “Environmental Sensing Service”, it works with BLE Scanner:

#include <ArduinoBLE.h> //libreria Bluetooth
#include <Arduino_LPS22HB.h>  //libreria presion
#include <Arduino_HTS221.h> //libreria temperatura-humedad

BLEService MeteoExterior("0x181A"); //declaramos el servicio MeteoExterior 'org.bluetooth.service.environmental_sensing' 0x181A

BLEFloatCharacteristic Presion("0x2A6D", BLERead | BLENotify);  //declaramos caracteristica presion al servicio MeteoExterior 'org.bluetooth.characteristic.pressure' 0x2A6D
BLEFloatCharacteristic Temperatura("0x2A6E", BLERead | BLENotify);  //declaramos caracteristica temperatura al servicio MeteoExterior 'org.bluetooth.characteristic.temperature' 0x2A6E
BLEFloatCharacteristic Humedad("0x2A6F", BLERead | BLENotify);  //declaramos caracteristica humedad al servicio MeteoExterior 'org.bluetooth.characteristic.humidity' 0x2A6F

bool advertiseHabilitado = false;

void setup() {
  // put your setup code here, to run once:

  if (!BLE.begin()) { //inicializamos Bluetooth
    while (1);
  }

  BLE.setLocalName("Exterior");  //set nombre local

  BLE.setAdvertisedService(MeteoExterior);  //indicamos que el servicio tambien se publicite

  MeteoExterior.addCharacteristic(Presion);  //añadimos caracteristica presion al servicio MeteoExterior
  MeteoExterior.addCharacteristic(Temperatura);  //añadimos caracteristica temperatura al servicio MeteoExterior
  MeteoExterior.addCharacteristic(Humedad);  //añadimos caracteristica humedad al servicio MeteoExterior

  BLE.addService(MeteoExterior); //añadimos el servicio MeteoPresion

  BLE.setConnectable(true); //el periferico es conectable después de publicitarlo

  BARO.begin(); //inicializo sensor de presion
  HTS.begin();  //inicializo sensores de temperatura y humedad

}

void loop() {
  // put your main code here, to run repeatedly:
  if (!advertiseHabilitado) {
    if (BLE.advertise()) { //publicitando periferico
      advertiseHabilitado = true;
    }
    else {
      advertiseHabilitado = false;
    }
  }

  BLEDevice central = BLE.central(); //preguntamos si central se ha conectado

  if (central) {  //si central esta disponible

    while (central.connected()) {  //y mientras central permanezca conectado
      Presion.writeValue(BARO.readPressure());  //escribo el valor de presion del sensor en la caracteristica Presion del servicio MeteoExterior

      Temperatura.writeValue(HTS.readTemperature());  //escribo el valor de temperatura del sensor en la caracteristica Temperatura del servicio MeteoExterior
      Humedad.writeValue(HTS.readHumidity()); //escribo el valor de humedad del sensor en la caracteristica Humedad del servicio MeteoExterior
    }
  }
  else {
    advertiseHabilitado = false;
  }
}

Hi to all,

I updated my code and now I can see 4 different services on serial monitor :sweat_smile: so the code before was right.

The rest of the problems that I detected on my code before persists, like

I can connect with peripheral device and serial monitor can show me values (you can see below), but the problem with the values what central device gets from peripheral devices is limited to byte data type (peripheral device works with integer data type) so I can not see the real values that peripheral counts.

Central code updated:

#include <ArduinoBLE.h> //libreria Bluetooth

bool ScanActive = false;  //Indicar si scan() esta activo

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600); //inicializamos la comunicacion monitor serie

  if (!BLE.begin()) { //inicializamos Bluetooth
    Serial.println("Fallo al inicializar BLE");
    while (1);
  }

  Serial.println("Inicializamos el dispositivo BlueTooth central");

  BLE.setLocalName("MiCentral");  //set nombre local

}

void loop() {
  // put your main code here, to run repeatedly:
  if (!ScanActive) {  //si ScanActive = false escaneamos BLE devices
    BLE.scan(); //Dispositivo BLE escaneando perifericos
    Serial.println("Escaneamos en busca de dispositivo BLE periferico");
    ScanActive = true;
  }
  BLEDevice peripheral = BLE.available();  //dispositivo peripheral disponible
  Serial.println(peripheral);

  if (peripheral) { //el dispositivo BLE esta disponible
    Serial.println("Dispositivo BLE periferico esta disponible");

    if (peripheral.hasLocalName()) { //dispone de localName?
      Serial.print("Local name: ");
      Serial.println(peripheral.localName());
    } //end haslocalname
    else Serial.println("Local name: no encontrado");

    if (peripheral.hasAdvertisedServiceUuid()) { //dispone de Servicios?
      Serial.print("Service UUIDs: ");
      for (int i = 0; i < peripheral.advertisedServiceUuidCount(); i++) {
        Serial.print(peripheral.advertisedServiceUuid(i));
        Serial.print(" ");
      } //end for
      Serial.println();
    } //end hasadvertisedserviceuuid
    else Serial.println("Service UUIDs: no encontrados");

    if (peripheral.localName() == "MiPeriferico") { //encontramos el dispositivo BLE que buscamos
      BLE.stopScan(); //paramos el escaneo de dispositivos.
      ScanActive = false;
      Serial.println("Conectando...");

      bool Conectado = peripheral.connect();  //conectamos con el periferico

      if (Conectado) { //Conectamos al dispositivo BLE encontrado
        Serial.println("Conectado");

        if (peripheral.discoverAttributes()) {  //descubrimos los atributos del periferico
          Serial.println("Atributos descubiertos");
        }
        else Serial.println("No Atributos");

        BLECharacteristic Caracteristica = peripheral.characteristic("00000001-0001-0001-0001-000000000002"); //creamos caracteristica como la que nos da el periferico

        Serial.print("Device name: ");
        Serial.println(peripheral.deviceName());
        Serial.print("Local name: ");
        Serial.println(peripheral.localName());

        for (int i = 0; i < peripheral.serviceCount(); i++) { //mostramos todos los servicios que tiene el dispositivo periferico
          BLEService service = peripheral.service(i);
          Serial.print("Servicio ");
          Serial.println(service.uuid());

          for (int j = 0; j < service.characteristicCount(); j++) { //mostramos todas las caracteristicas que tiene el dispositivo periferico
            BLECharacteristic characteristic = service.characteristic(j);
            Serial.print("\tCaracteristica ");
            Serial.println(characteristic.uuid());
          }
        }

        Serial.print("Tamaño del valor = ");  //tamaño en bytes del valor del periferico
        Serial.print(Caracteristica.valueSize());
        Serial.println(" bytes");

        byte value;
        while (!ScanActive) { //mientras este conectado al periferico, mostramos los valores que lee del ultimo serivio y caracteristica leida
          Caracteristica.readValue(value);  //leemos el valor que nos entrega el periferico.
          Serial.print("Valor leido del periferico: ");
          Serial.println(value);
        }

        ScanActive = false;

      } //end peripheral.connect
      else {
        Serial.println("Fallo en la conexion");
        Serial.println("Desconectado");
        ScanActive = false;
      } //end else
    } //end peripheral.localName
  } //end peripheral

  else {
    Serial.println("Dispositivo BLE periferico no esta disponible");
    Serial.println(peripheral);
    ScanActive = false;
  } //end else

  delay(1000);

} //end loop

Serial monitor:

22:54:32.145 -> 1
22:54:32.145 -> Dispositivo BLE periferico esta disponible
22:54:32.145 -> Local name: MiPeriferico
22:54:32.145 -> Service UUIDs: 00000001-0001-0001-0001-000000000001 
22:54:32.179 -> Conectando...
22:54:32.212 -> Conectado
22:54:32.789 -> Atributos descubiertos
22:54:32.789 -> Device name: Arduino
22:54:32.822 -> Local name: MiPeriferico
22:54:32.822 -> Servicio 1800
22:54:32.822 -> 	Caracteristica 2a00
22:54:32.822 -> 	Caracteristica 2a01
22:54:32.822 -> Servicio 1801
22:54:32.822 -> 	Caracteristica 2a05
22:54:32.822 -> Servicio 00000001-0001-0001-0001-000000000001
22:54:32.822 -> 	Caracteristica 00000001-0001-0001-0001-000000000002
22:54:32.822 -> Tamaño del valor = 0 bytes
22:54:32.857 -> Valor leido del periferico: 222
22:54:32.926 -> Valor leido del periferico: 215
22:54:32.959 -> Valor leido del periferico: 204
22:54:32.994 -> Valor leido del periferico: 196
22:54:33.027 -> Valor leido del periferico: 209
22:54:33.061 -> Valor leido del periferico: 36

Sorry for the delay. Here is my central example for the ESS peripheral example. It reads 16-bit data values.

/*
  This example creates a BLE central that scans for a peripheral with a Environmental Sensing Service (ESS).
  If that contains temperature and humidity characteristics the values are displayed.

  The circuit:
  - Arduino Nano 33 BLE or Arduino Nano 33 IoT board.

  This example code is in the public domain.
*/

#include <ArduinoBLE.h>

//----------------------------------------------------------------------------------------------------------------------
// BLE UUIDs
//----------------------------------------------------------------------------------------------------------------------

// https://www.bluetooth.com/specifications/assigned-numbers/environmental-sensing-service-characteristics/

#define BLE_UUID_ENVIRONMENTAL_SENSING_SERVICE    "181A"
#define BLE_UUID_TEMPERATURE                      "2A6E"
#define BLE_UUID_HUMIDITY                         "2A6F"

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

  BLE.begin();

  BLE.scanForUuid( BLE_UUID_ENVIRONMENTAL_SENSING_SERVICE );
}

void loop()
{
  static long previousMillis = 0;

  long interval = 5000;
  unsigned long currentMillis = millis();
  if ( currentMillis - previousMillis > interval )
  {
    previousMillis = currentMillis;

    BLEDevice peripheral = BLE.available();

    if ( peripheral )
    {
      if ( peripheral.localName() != "Arduino Nano 33 BLE" )
      {
        return;
      }

      BLE.stopScan();

      explorePeripheral( peripheral );

      BLE.scanForUuid( BLE_UUID_ENVIRONMENTAL_SENSING_SERVICE );
    }
  }
}


bool explorePeripheral( BLEDevice peripheral )
{
  if ( !peripheral.connect() )
  {
    return false;
  }

  if ( !peripheral.discoverAttributes() )
  {
    peripheral.disconnect();
    return false;
  }

  BLECharacteristic temperatureCharacterisic = peripheral.characteristic( BLE_UUID_TEMPERATURE );
  if ( temperatureCharacterisic )
  {
    int16_t temperature;
    temperatureCharacterisic.readValue( temperature );
    Serial.print( "Temperature: " );
    Serial.print( temperature / 100.0 );
    Serial.println( "°C" );
  }

  BLECharacteristic humidityCharacterisic = peripheral.characteristic( BLE_UUID_HUMIDITY );
  if ( humidityCharacterisic )
  {
    uint16_t humidity;
    humidityCharacterisic.readValue( humidity );
    Serial.print( "Humidity: " );
    Serial.print( humidity / 100.0 );
    Serial.println( "%" );
  }

  peripheral.disconnect();
  return true;
}

You need to change the type of your “value” variable.

For the UUIDs I wrote myself a script in a macro tool I use. There are online UUID generators.

Hi to all,

Do not worry, Klaus_K, everyone has other stuff to do, so for me I do not care abuot how many days last till new answer.

At the end, I get the final code for central device that works (for sure anyone find something that is incorrect). I use an array to get the information from the peripheral, I am not sure that is right when I try to get information from integer or float data type.

This example is OK, so I continue with “Meteo Station” with BLE library and NANO 33 BLE and NANO 33 SENSE devices. I will post every doubt and success.

Here you can see the code (and below you can see the serial monitor):

#include <ArduinoBLE.h> //libreria Bluetooth

bool ScanActive = false;  //Indicar si scan() esta activo

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600); //inicializamos la comunicacion monitor serie

  if (!BLE.begin()) { //inicializamos Bluetooth
    Serial.println("Fallo al inicializar BLE");
    while (1);
  }

  Serial.println("Inicializamos el dispositivo BlueTooth central");

  BLE.setLocalName("MiCentral");  //set nombre local

}

void loop() {
  // put your main code here, to run repeatedly:
  if (!ScanActive) {  //si ScanActive = false escaneamos BLE devices
    BLE.scan(); //Dispositivo BLE escaneando perifericos
    Serial.println("Escaneamos en busca de dispositivo BLE periferico");
    ScanActive = true;
  }
  BLEDevice peripheral = BLE.available();  //dispositivo peripheral disponible
  Serial.println(peripheral);

  if (peripheral) { //el dispositivo BLE esta disponible
    Serial.println("Dispositivo BLE periferico esta disponible");

    if (peripheral.hasLocalName()) { //dispone de localName?
      Serial.print("Local name: ");
      Serial.println(peripheral.localName());
    } //end haslocalname
    else Serial.println("Local name: no encontrado");

    if (peripheral.hasAdvertisedServiceUuid()) { //dispone de Servicios?
      Serial.print("Service UUIDs: ");
      for (int i = 0; i < peripheral.advertisedServiceUuidCount(); i++) {
        Serial.print(peripheral.advertisedServiceUuid(i));
        Serial.print(" ");
      } //end for
      Serial.println();
    } //end hasadvertisedserviceuuid
    else Serial.println("Service UUIDs: no encontrados");

    if (peripheral.localName() == "MiPeriferico") { //encontramos el dispositivo BLE que buscamos
      BLE.stopScan(); //paramos el escaneo de dispositivos.
      ScanActive = false;
      Serial.println("Conectando...");

      bool Conectado = peripheral.connect();  //conectamos con el periferico

      if (Conectado) { //Conectamos al dispositivo BLE encontrado
        Serial.println("Conectado");

        if (peripheral.discoverAttributes()) {  //descubrimos los atributos del periferico
          Serial.println("Atributos descubiertos");
        }
        else Serial.println("No Atributos");

        BLECharacteristic Caracteristica = peripheral.characteristic("00000001-0001-0001-0001-000000000002"); //creamos caracteristica como la que nos da el periferico

        Serial.print("Device name: ");
        Serial.println(peripheral.deviceName());
        Serial.print("Local name: ");
        Serial.println(peripheral.localName());

        for (int i = 0; i < peripheral.serviceCount(); i++) { //mostramos todos los servicios que tiene el dispositivo periferico
          BLEService service = peripheral.service(i);
          Serial.print("Servicio ");
          Serial.println(service.uuid());

          for (int j = 0; j < service.characteristicCount(); j++) { //mostramos todas las caracteristicas que tiene el dispositivo periferico
            BLECharacteristic characteristic = service.characteristic(j);
            Serial.print("\tCaracteristica ");
            Serial.println(characteristic.uuid());
            if (characteristic.canRead()) {
              Serial.println(characteristic.read());
            }
          }
        }

        Serial.print("Tamaño del valor = ");  //tamaño en bytes del valor del periferico
        int tamano = Caracteristica.valueSize();
        Serial.print(tamano);
        Serial.println(" bytes");

        int value[tamano - 1];
        while (peripheral.connected()) { //mientras este conectado al periferico, mostramos los valores que lee del ultimo serivio y caracteristica leida
          Caracteristica.readValue(value, Caracteristica.valueSize());  //leemos el valor que nos entrega el periferico.
          Serial.print("Valor leido del periferico: ");
          Serial.println(value[0]);
        }

        ScanActive = false;

      } //end peripheral.connect
      else {
        Serial.println("Fallo en la conexion");
        Serial.println("Desconectado");
        ScanActive = false;
      } //end else
    } //end peripheral.localName
  } //end peripheral

  else {
    Serial.println("Dispositivo BLE periferico no esta disponible");
    Serial.println(peripheral);
    ScanActive = false;
  } //end else

  delay(1000);

} //end loop

Serial monitor:

19:10:46.427 -> 1
19:10:46.427 -> Dispositivo BLE periferico esta disponible
19:10:46.427 -> Local name: MiPeriferico
19:10:46.427 -> Service UUIDs: 00000001-0001-0001-0001-000000000001 
19:10:46.460 -> Conectando...
19:10:47.302 -> Conectado
19:10:47.880 -> Atributos descubiertos
19:10:47.880 -> Device name: Arduino
19:10:47.915 -> Local name: MiPeriferico
19:10:47.915 -> Servicio 1800
19:10:47.915 -> 	Caracteristica 2a00
19:10:47.948 -> 1
19:10:47.948 -> 	Caracteristica 2a01
19:10:47.982 -> 1
19:10:47.982 -> Servicio 1801
19:10:47.982 -> 	Caracteristica 2a05
19:10:47.982 -> Servicio 00000001-0001-0001-0001-000000000001
19:10:47.982 -> 	Caracteristica 00000001-0001-0001-0001-000000000002
19:10:48.017 -> 1
19:10:48.017 -> Tamaño del valor = 4 bytes
19:10:48.052 -> Valor leido del periferico: 27086
19:10:48.119 -> Valor leido del periferico: 28529
19:10:48.152 -> Valor leido del periferico: 29970
19:10:48.185 -> Valor leido del periferico: 1453
19:10:48.218 -> Valor leido del periferico: 2962
19:10:48.254 -> Valor leido del periferico: 4429
19:10:48.321 -> Valor leido del periferico: 5895
19:10:48.355 -> Valor leido del periferico: 7403
19:10:48.389 -> Valor leido del periferico: 8866
19:10:48.422 -> Valor leido del periferico: 10324
19:10:48.456 -> Valor leido del periferico: 11770
19:10:48.489 -> Valor leido del periferico: 13257
19:10:48.557 -> Valor leido del periferico: 14702
19:10:48.591 -> Valor leido del periferico: 16147

rsanalo:
At the end, I get the final code for central device that works

Good news.

rsanalo:
I will post every doubt and success.

Good luck with your project. Looking forward to your success story or new questions. :slight_smile:

Hi to all,

I found the final code (code from Klaus_K was very helpful) what I want for my project. I only need around 4 weeks (2 of them was vacations :smiley: ).

I found a issue when worked on code. I typed UUID numbers in peripheral device (0x2A6D) and different way in central device (00000000-0000-0000-0000-000000002A6D). When I tryed central device’s code with same style like in Peripheral device’s code, compiler works well and did not show any issues with code, but devices could not establish conection, so I typed these 2 diferent ways.

You can see me code below. There are lot of comment lines because it is ready for work with 2 peripheral devices (my first idea is working with 2 perihperals and 1 central devices).

I connect to my central device an OLED display and I can see, at the moment, all data from peripheral device.

Special thanks to Klaus_K for his help.

Final code:

#include <ArduinoBLE.h> //libreria Bluetooth
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

//Constantes
#define ANCHO_PANTALLA 128
#define ALTO_PANTALLA 64

Adafruit_SSD1306 myDisplay(ANCHO_PANTALLA, ALTO_PANTALLA, &Wire, -1);

//Variables
byte Int_Ext;
uint16_t presion_Exterior;
int16_t temperatura_Exterior;
int16_t humedad_Exterior;
uint16_t presion_Interior;
int16_t temperatura_Interior;
int16_t humedad_Interior;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600); //inicializamos la comunicacion monitor serie

  if (!BLE.begin()) { //inicializamos Bluetooth
    Serial.println("fallo al inicializar BLE");
    while (1);
  }

  Serial.println("Inicializamos el dispositivo BlueTooth central");

  BLE.setLocalName("LectorMeteos");  //set nombre local

  BLE.scan(); //dispositivo BLE escaneando perifericos
  Serial.println("Escaneamos en busca de dispositivo BLE periferico");

  myDisplay.begin(SSD1306_SWITCHCAPVCC, 0x3C);
}

void loop() {
  // put your main code here, to run repeatedly:

  BLEDevice perifericoExterior = BLE.available();  //dispositivo periferico disponible
  Serial.println(perifericoExterior);

  if (perifericoExterior) { //el dispositivo BLE esta disponible
    Serial.println(perifericoExterior.localName());

    if (perifericoExterior.hasLocalName()) { //dispone de localName?
      Serial.print("Local name: ");
      Serial.println(perifericoExterior.localName());
    }
    else Serial.println("Local name: no encontrado");

    if (perifericoExterior.hasAdvertisedServiceUuid()) { //dispone de Servicios?
      Serial.print("Service UUIds: ");
      for (int i = 0; i < perifericoExterior.advertisedServiceUuidCount(); i++) {
        Serial.print(perifericoExterior.advertisedServiceUuid(i));
        Serial.print(" ");
      }
      Serial.println();
    }
    else Serial.println("Service UUIDs: no encontrados");

    Int_Ext = 0;

    funcionDisponibilidadDispositivo(perifericoExterior, Int_Ext);

  }
  else {
    Serial.println("Dispositivo BLE periferico no esta disponible");
    Serial.println(perifericoExterior);
  }

  //  BLEDevice perifericoInterior = BLE.available();  //dispositivo periferico disponible
  //  Serial.println(perifericoInterior);
  //
  //  if (perifericoInterior) { //el dispositivo BLE esta disponible
  //    Serial.println("Dispositivo BLE periferico esta disponible");
  //
  //    if (perifericoInterior.hasLocalName()) { //dispone de localName?
  //      Serial.print("Local name: ");
  //      Serial.println(perifericoInterior.localName());
  //    }
  //    else Serial.println("Local name: no encontrado");
  //
  //    if (perifericoInterior.hasAdvertisedServiceUuid()) { //dispone de Servicios?
  //      Serial.print("Service UUIds: ");
  //      for (int i = 0; i < perifericoInterior.advertisedServiceUuidCount(); i++) {
  //        Serial.print(perifericoInterior.advertisedServiceUuid(i));
  //        Serial.print(" ");
  //      }
  //      Serial.println();
  //    }
  //    else Serial.println("Service UUIDs: no encontrados");

  //  Int_Ext=1;

  //  funcionDisponibilidadDispositivo(perifericoInterior);

  //  }
  //  else {
  //    Serial.println("Dispositivo BLE periferico no esta disponible");
  //    Serial.println(perifericoInterior);
  //  }

  myDisplay.clearDisplay();

  myDisplay.setTextSize(1);

  myDisplay.setTextColor(SSD1306_WHITE);

  myDisplay.setCursor(0, 0);

  myDisplay.print("P: ");
  myDisplay.print(presion_Exterior);
  myDisplay.println(" kPa");

  myDisplay.print("HR: ");
  myDisplay.print(humedad_Exterior);
  myDisplay.println(" %");

  myDisplay.print("T: ");
  myDisplay.print(temperatura_Exterior);
  myDisplay.println(" C");
  myDisplay.display();
  delay(5000);

}

uint16_t funcionLecturaPresion(BLECharacteristic Presion) {
  uint16_t pres;
  Presion.readValue(pres);
  Serial.print("Presion: ");
  Serial.print(pres / 100.0);
  Serial.println(" Kpa");
  return (pres / 100.0);
}

int16_t funcionLecturaTemperatura(BLECharacteristic Temperatura) {
  int16_t temp;
  Temperatura.readValue(temp);
  Serial.print("Temperatura: ");
  Serial.print(temp / 100.0);
  Serial.println(" ºC");
  return (temp / 100.0);
}

int16_t funcionLecturaHumedad(BLECharacteristic Humedad) {
  int16_t hum;
  Humedad.readValue(hum);
  Serial.print("Humedad: ");
  Serial.print(hum / 100.0);
  Serial.println(" %");
  return (hum / 100.0);
}

void funcionDisponibilidadDispositivo(BLEDevice dispositivo, byte selector) {
  if (dispositivo.localName() == "Exterior") { //encontramos el dispositivo BLE que buscamos
    BLE.stopScan(); //paramos el escaneo de dispositivos.
    Serial.println("Connectando...");

    bool Conectado = dispositivo.connect(); //conectamos con el periferico

    if (Conectado) {  //Conectamos al dispositivo BLE encontrado
      Serial.println("Conectado");

      if (dispositivo.discoverAttributes()) { //descubrimos los atributos del periferico
        Serial.println("Atributos descubiertos");
      }
      else Serial.println("No Atributos");

      Serial.print("Device name: ");
      Serial.println(dispositivo.deviceName());
      Serial.print("Local name: ");
      Serial.println(dispositivo.localName());

      BLEService MeteoService = dispositivo.service("00000000-0000-0000-0000-00000000181A");
      Serial.println(MeteoService);

      BLECharacteristic Presion = MeteoService.characteristic("00000000-0000-0000-0000-000000002A6D");
      if (Presion) {  //si caracteristica Presion esta disponible obtenemos el valor
        switch (selector) {
          case 0:
            presion_Exterior = funcionLecturaPresion(Presion);
            break;
          case 1:
            presion_Interior = funcionLecturaPresion(Presion);
            break;
        }
      }

      BLECharacteristic Temperatura = MeteoService.characteristic("00000000-0000-0000-0000-000000002A6E");
      if (Temperatura) {  //si caracteristica Temperatura esta disponible obtenemos el valor
        switch (selector) {
          case 0:
            temperatura_Exterior = funcionLecturaTemperatura(Temperatura);
            break;
          case 1:
            temperatura_Interior = funcionLecturaTemperatura(Temperatura);
            break;
        }
      }

      BLECharacteristic Humedad = MeteoService.characteristic("00000000-0000-0000-0000-000000002A6F");
      if (Humedad) {  //si caracteristica Humedad esta disponible obtenemos el valor
        switch (selector) {
          case 0:
            humedad_Exterior = funcionLecturaHumedad(Humedad);
            break;
          case 1:
            humedad_Interior = funcionLecturaHumedad(Humedad);
            break;
        }
      }

      dispositivo.disconnect();
      Serial.println("Desconectado");
      BLE.scan(); //dispositivo BLE escaneando perifericos

    }
    else {
      Serial.println("Fallo en la conexion");
      Serial.println("Desconectado");
      BLE.scan(); //dispositivo BLE escaneando perifericos

    }
  }
}

Hello all,Do you guys have the example of connection between the laptop and the nano 33 ble sense board through bluetooth.
If anyone knows how to do it .Please share with us. Thanks.
I just don't know how to connect ,even though the laptop can find the bluetooth device of the nano 33 ble sense in the ble device list.

Thanks guys

@jerrick Please do not post your questions in different sub forums. The is called cross posting and prohibited by the forum rules.

This rule ensures we are not wasting our time answering questions multiple times. Most of us here are doing this for fun.

I have answered your question in the "Nano 33 BLE" sub forum.

This is just a friendly personal warning. When forum admins find cross post they will issue an official warning and can block you.

Additionally, please do not hijack other posts. This does not help you. Old posts get less attention. Most of the people helping look for new cases where they can help first.