I have a new Nano 33 IOT. I am trying to connect to a ble sensor, I can connect then when I try to discover attributes it just locks up. I have to reset it to download an edited sketch. It never discovers any attributes. Im using ArduinoBLE 1.4.0 library. Ive tested with LightBlue and it has the service and characteristic available to subscribe to. I tested with my cell phone and MIT Ai2 and it connected and was able to get the data so I know the sensor is working. If I try to subscribe directly to the cUUID directly it says it doesnt exist?
#include <ArduinoBLE.h>
#include "Timer.h"
void setup() {
Serial.begin(9600);
BLE.begin();
Serial.println("BLE Starting");
BLE.scan();
}
void loop() {
BLEDevice bSensor = BLE.available();
if (bSensor) {
// discovered a , print out address, local name, and advertised service
Serial.print("Found ");
Serial.print(bSensor.address());
Serial.print(" '");
Serial.print(bSensor.localName());
Serial.print("' ");
Serial.print(bSensor.advertisedServiceUuid());
Serial.println();
if (bSensor.localName() != "WTBatSensor") {
return;
}
// stop scanning
BLE.stopScan();
hitDetect(bSensor);
while (1) {}
}
}
void hitDetect(BLEDevice bSensor) {
Serial.println ("Connecting......");
if (bSensor.connect()) {
Serial.print("Connected to: ");
Serial.println(bSensor.address());
Serial.print("Advertised Service: ");
Serial.println(bSensor.advertisedServiceUuid());
} else {
Serial.println("Failed to connect!");
return;
}
BLEService service = bSensor.service("0000ffe4-0000-1000-8000-00805f9a34fb");
Serial.println("Discovering Attributes");
if (!bSensor.discoverAttributes()) {
Serial.println("Attributes discovered");
// Print discovered attributes
for (int i = 0; i < bSensor.characteristicCount(); i++) {
BLECharacteristic characteristic = bSensor.characteristic(i);
Serial.print("Characteristic ");
Serial.print(i);
Serial.print(": ");
Serial.println(characteristic.uuid());
delay(10);
}
}
// if (!bSensor.discoverAttributes()){
// Serial.println("Attribute discovery failed!");
// bSensor.disconnect();
// return;
//}
Serial.println("step");
bSensor.discoverAttributes();
Serial.print("Number of Char: ");
Serial.println(bSensor.characteristicCount());
if (!bSensor.hasCharacteristic("0000ffe4-0000-1000-8000-00805f9a34fb")){
Serial.print("Has Char: ");
Serial.println("No");
}
// retrieve the characteristic
BLECharacteristic notify = bSensor.characteristic("0000ffe4-0000-1000-8000-00805f9a34fb");
if (!notify.canRead()){
Serial.println("Cant READ");
}
if (!notify.canSubscribe()) {
Serial.print("Can Subscribe: ");
Serial.println(notify.descriptorCount());
bSensor.disconnect();
return;
}
if (notify.canSubscribe()) {
Serial.println("Subscribe found");
}
notify.subscribe();
if (notify.subscribed()){
Serial.print("Subscribed ");
}
}
When monitoring the serial monitor it gets to the discovery then just sits and I have to reboot it, then it will do it again but never actually do the discovery.
Im most likely doing something wrong, but i don't know where.

