Nano 33 IOT iPhone Bluetooth issues

Hello!
I'm trying to discover an Arduino BLE service from an iphone.

This is the simple code running on the board:

#include <ArduinoBLE.h>
#include <Arduino.h>


BLEService randomService("8befd7c0-3e3f-11ea-b77f-2e728ce88125");

BLEFloatCharacteristic randomChar("8befd8c1-3e3f-11ea-b77f-2e728ce88125", BLERead | BLEWrite);

void setup() {
  Serial.begin(9600);
  Serial.println("Setting up....");

  while (!Serial);

  if (!BLE.begin()) {
    Serial.println("starting BLE failed!");
    while (1);
  }

  BLE.setLocalName("Random Service");
  BLE.setAdvertisedService(randomService);

  randomService.addCharacteristic(randomChar);

  BLE.addService(randomService);
  BLE.advertise();
  Serial.println("Bluetooth device active, waiting for connections...");
}

void loop() {
  float random = getrandomReading();
  randomChar.writeValue(random);
  BLE.poll();
  delay(1000);
}

float getrandomReading() {
  return random(0, 100);
}

I'm using LightBlue to debug, both on iPhone and on Android.

On Android, I can see the service with the id I'm setting, named "Random Service". On the iPhone, I see a service named Arduino, with a different id. I'm assuming the default id for the board.

On both devices, I can connect to the service and pull random numbers with blue light.

I've restarted the iPhone multiple times, to make sure that there are no caching issues on the iPhone device. Maybe caching doesn't work as I think on the iPhone.

Any ideas on what I might be missing?

Just in case someone else stumbles upon this.

Bluelight in iPhone reports the actual name and UUID of the peripheral (Arduino, original). If you click through you can see the advertised name and UUID if the service. On Andriod it's reporting the advertised values, not the peripheral ones.

If you want access to the advertised UUID and value in your swift app you can use something like this:

    func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
        if !peripherals.contains(peripheral) {
            let advertisedName = advertisementData[CBAdvertisementDataLocalNameKey] as? String
            let advertisedUuid = advertisementData[CBAdvertisementDataServiceUUIDsKey] as? [CBUUID]

            self.peripherals.append(peripheral)
            let name = peripheral.name ?? "N/A"
            let advertisedNameOut = advertisedName ?? "N/A"
            let advertisedUuidString = advertisedUuid?.map { $0.uuidString } ?? ["N/A"]
            let identifier = peripheral.identifier.uuidString
            let fullId = "\(advertisedNameOut) - (\(name)) - \(advertisedUuidString) - (\(identifier))"

            self.peripheralNames.append(fullId)
        }
    }

I hope the swift code is not off topic :slight_smile:

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