Hello,
I have a simple BLE framework here that has worked previously with a Seeeduino XIAO BLE nRF52840. I was able to set up a service and a characteristic on that uC and transmit data via the characteristic to a free app called LightBlue that can easily detect and connect to peripheral bluetooth devices within range. On the app, once the peripheral device/uC is connected the UUID of the advertised service can easily be located and once clicked on one can click the 'read' button to read any transmitted values from the code [sent via bleCharacteristic.writeValue() ]. I am currently using a Nano 33 IOT (SAMD21 ARM Cortex) and am able to connect to the device and everything with more or less the same code but under the service UUID on the app I see 'No characteristic available', and I am unable to transmit any data even though I am writing data to it. Is there any way around this issue? Any help, suggestions on what to do or what exact framework I should use for BLE would be greatly appreciated!
Thank you!
Here is the code I am using. All bluetooth related functions are defined as in the ArduinoBLE Library. I am suspicious that there could be something wrong with 'BLELongCharacteristic' in that I would think the best option would be to use 'BLECharacteristic' but I have had problems getting this (latter) function to work.
#include <ArduinoBLE.h>
#include <stdio.h>
//BLUETOOTH SETUP
//Peripheral Device Setup:
//Create Service, assign 128-bit custom UUID
BLEService Service1("ec70e16f-ca8b-4c18-9118-dcdd339e5288");
//Create Bluetooth® Characteristic(s) for the Service. Same 128-bit UUID, read and writable by central
BLELongCharacteristic Char1("ec70e16f-ca8b-4c18-9118-dcdd339e5288", BLERead | BLEWrite | BLENotify);
void setup() {
Serial.begin(9600);
while (!Serial);
// begin initialization
if (!BLE.begin()) {
Serial.println("BLE Connection Failed!");
while (1);
}
//Set advertised local name and service UUID:
BLE.setDeviceName("Arduino Nano"); //Look for this name on Central device
BLE.setLocalName("Arduino Nano");
//Add services
BLE.addService(Service1);
BLE.setAdvertisedService(Service1);
//Add the characteristic to the service
Service1.addCharacteristic(Char1);
// set the initial value for the characeristic:
Char1.writeValue(0);
// start advertising
BLE.advertise();
Serial.println("Begin Advertising...");
}
void loop() {
//Wait to connect to BLE central device:
BLEDevice central = BLE.central();
if (central) {
Serial.print("Connected to central: ");
Serial.println(central.address()); // print the central's MAC address:
while (central.connected()) {
char Ser = Serial.read();
if (Serial.read() != -1) {
Serial.print("Received: ");
Serial.println(Ser);
Char1.writeValue(Ser); } //BLE
}
// when the central disconnects, print it out:
Serial.print(F("Disconnected from central: "));
Serial.println(central.address());
}
}