Connecting Two arduino nano 33 Iot to each other using BLE

Hello everyone, I am a starting arduino programmer and I have not so much experience as the most of u guys but in project that I am making I need to connect The arduino Nano's to each other Using BLE. I have done some research in the arduino nano ble forums but without succes.

These are my codes for the central and the peripheral:
Central:
//central device
#include <ArduinoBLE.h>

void beginBLE() // zet BLE aan
{
if (!BLE.begin()) // als BLE niet werkt stuur deze tekst door
{
Serial.println("starting BLE failed!");
while (1); // tot hij wel werkt
}
}

void setup()
{
Serial.begin(9600);
beginBLE(); // functie beginBLE voor begin BLE connectie
BLE.setDeviceName("central"); // naam aan de arduino toe kennen

}

void adres() // BLE adres van de arduino nano 33 IOT
{
String address = BLE.address(); // address = BLE adres
Serial.print("central Local address is : ");
Serial.println(address);
}

void loop()
{
// adres(); // functie adres voor het het adres van de BLE component
BLE.scan(); // scan naar een peripheral
BLEDevice peripheral = BLE.available(); // als er een peripheral arduino ontdekt is
if (peripheral)
{
Serial.println("Connecting ..."); // stuur conecting naar seriƫle monitor

if (peripheral.connect()) // als de periphal geconnecteerd is -->
{
Serial.println("Connected"); // stuur dat hij geconnecteerd is
} else // indien niet,
{
Serial.println("Failed to connect!"); // stuur failed to connect
return;
}
}
}
pheripheral:
// peripheral device
#include <ArduinoBLE.h>

void beginBLE() // zet BLE aan
{
if (!BLE.begin()) // als BLE niet werkt stuur deze tekst door
{
Serial.println("starting BLE failed!");
while (1); // tot hij wel werkt
}
}

void setup()
{
pinMode(2, OUTPUT);
Serial.begin(9600);
beginBLE(); // functie beginBLE voor begin BLE connectie
BLE.setDeviceName("peripheral"); // naam aan de arduino toe kennen

}

void adres() // BLE adres van de arduino nano 33 IOT
{
String address = BLE.address(); // address = BLE adres
Serial.print("peripheral Local address is: ");
Serial.println(address);
}

void loop()
{
digitalWrite(2, HIGH);
adres(); // functie adres voor het het adres van de BLE component
BLE.setConnectable(true); // zet de connectiviteit true
BLE.advertise(); // sta open voor connectie
}
They are able to use the BLE and they print there adresses but won't connect to each other and I don't know what to do next. I hope you guys help me and thanks on forward.

Welcome to the forum.

Please read the "How to post". Its at the beginning of each sub forum. Start by modifying your post to use code tags. Should look like that.

Your sample code

Your code misses some fundamental basics.

Did you try any of the examples that come with the library?

Do you know how BLE works? e.g. the GATT, services and characteristics ?

With BLE it is better to start with one side and use your smartphone as central.

Get yourself a BLE app on your smartphone. I use BLE Scanner from bluepixel technologies on iPhone. There are many others you can use.

Download a peripheral example sketch e.g. BatteryMonitor from the library to one of your Arduinos and use the smartphone app to connect and look at the device. Try to find out how the code works.