ArduinoBLE - services not discoverable

Hi

I have a Arduino nano 33 iot, and I am using the example Bluetooth projects for the ArudionBLE. I am then trying to connect using an android phone to discover the services. I have used various apps from the app store and also made my own using Iconic, but although the monitor for Sketch says its connected, it seems that the mobile device does not discover the services.

Although i say it doesn't discover them, on the odd occasion it has discovered them. (this happens rarely and i cant see any pattern to why this would be)

I have been all of the web looking at what other peoples experiences are and cant find anyone with the same issue.

Can anyone help or point me in the right direction?

Thanks

Can you please post your sketch where you have the issue?

Communication stacks need love and some code constructs that seem harmless like using delay() and tight while loops prevent the BLE stack from doing its job.

void loop()
{
BLEDevice central = BLE.central();

if (central)
{
while (central.connected()) {

   if(buttonCharacteristic.written()){
     Serial.println('changed');
  }

if (scaledValueChar.valueUpdated())
{
Serial.println('changed');
}

// int battery = analogRead(A0);
// int batteryLevel = map(battery, 0, 1023, 0, 100);
// //Serial.print("Battery Level % is now: ");
// //Serial.println(batteryLevel);
// //batteryLevelChar.writeValue(batteryLevel);
// //scaledValueChar.writeValue(something * 5);
delay(200);
}
}
}

Iv enabled the delay(200) and that seems to of made the difference.

I need to make a note of tight loops.

Thanks you very much for this.

That delay is going to bite you sooner or later.

Have a look at the following example

File -> Examples -> 02.Digital -> BlinkWithoutDelay

Use this technique instead. Chose a sensible update interval for your data depending your application.

1 Like

I will take a look.
Thanks for both of your replies. I had almost nearly given up hope of getting it to work.

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