Connect 2 portenta H7 together via bluetooth?

I was just wondering if there is a way to connect 2 portenta h7 via bluetooth, basically have 2 portenta h7 to communicate to each other via bluetooth, I'm trying to connect them together so that an IR sensor once it detects fire communicates to the other portenta via bluetooth.

Yes, it is possible to connect two Portenta H7 boards via Bluetooth and have them communicate with each other. Here are the general steps you can follow to achieve this:

  1. Enable Bluetooth on both Portenta H7 boards. You can do this by using the BLE.begin() function in your code. Here is an example code snippet:
#include <ArduinoBLE.h>

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

  if (!BLE.begin()) {
    Serial.println("BLE Failed to Initialize!");
    while (1);
  }

  Serial.println("BLE Initialized Successfully!");
}
  1. Configure one of the Portenta H7 boards as a Bluetooth server, and the other as a Bluetooth client. The server board will advertise its services, and the client board will scan for available servers and connect to the desired one. Here is an example code snippet for the server board:
#include <ArduinoBLE.h>

BLEService fireService("19b10010-e8f2-537e-4f6c-d104768a1214"); // create a BLE service
BLECharacteristic fireCharacteristic("19b10011-e8f2-537e-4f6c-d104768a1214", BLERead | BLENotify); // create a BLE characteristic

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

  if (!BLE.begin()) {
    Serial.println("BLE Failed to Initialize!");
    while (1);
  }

  BLE.setLocalName("Fire Sensor");
  BLE.setAdvertisedService(fireService); // add the service UUID
  fireService.addCharacteristic(fireCharacteristic); // add the characteristic UUID
  BLE.addService(fireService); // add the service
  fireCharacteristic.setValue("No fire detected yet."); // set an initial value for the characteristic
  BLE.advertise(); // start advertising the service
  Serial.println("BLE Server Initialized Successfully!");
}

void loop() {
  // Wait for a central to subscribe to the characteristic
  while (!fireCharacteristic.subscribed()) {
    delay(10);
  }

  // Simulate a fire detection event by changing the value of the characteristic
  fireCharacteristic.setValue("Fire detected!");

  delay(1000);
}

And here is an example code snippet for the client board:

#include <ArduinoBLE.h>

BLEService fireService("19b10010-e8f2-537e-4f6c-d104768a1214"); // create a BLE service
BLECharacteristic fireCharacteristic("19b10011-e8f2-537e-4f6c-d104768a1214", BLERead | BLENotify); // create a BLE characteristic

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

  if (!BLE.begin()) {
    Serial.println("BLE Failed to Initialize!");
    while (1);
  }

  BLE.setLocalName("Fire Detector");
  BLE.scanForUuid(fireService.uuid()); // start scanning for the server's service UUID
  Serial.println("Scanning for Fire Sensor...");

  // Wait for the server to be found
  while (!fireCharacteristic) {
    BLEDevice peripheral = BLE.available();
    if (peripheral) {
      // Check if the peripheral has the characteristic we are looking for
      if (peripheral.hasCharacteristic(fireCharacteristic)) {
        fireCharacteristic = peripheral.characteristic(fireCharacteristic.uuid());
        break;
      }
    }
  }

  Serial.println("Connected to Fire Sensor!");
}

void loop() {
  // Wait for notifications from the server
  fireCharacteristic.subscribe();
  while (fireCharacteristic.value() == "") {
    delay(10);
  }

  //

Z