This worked, but only once. I was able to adapt the code to fit my application and it worked the first time I tested it. However, since the first test the BT module won't connect to the android at all. Using BLE Scanner or Light Blue the device no longer appears to connect with.
Here is my code, I mustve changed something small that I didn't notice. Code compiles just fine.
#include <ArduinoBLE.h> //Bluetooth Library
BLEService IDService("180A"); // BLE Generic Attribute Service UUID
BLECharCharacteristic IDChartest("2AC3", BLERead); //Object ID UUID, read only
BLEStringCharacteristic IDString("2AF8", BLERead, 8); //Fixed String 8 UUID, read only
char ID = 7;
String ID2 = "1A2B3C4D";
String ID3 = "";
void setup() {
Serial.begin(9600);
while (!Serial);
// begin initialization
if (!BLE.begin()) {
Serial.println("starting Bluetooth® Low Energy failed!");
while (1);
}
// set advertised local name and service UUID:
BLE.setLocalName("Here Fishy Fishy");
BLE.setAdvertisedService(IDService);
// add the characteristic to the service
IDService.addCharacteristic(IDString);
IDService.addCharacteristic(IDChartest);
// add service
BLE.addService(IDService);
// set the initial value for the characteristic:
IDString.writeValue(ID3);
IDChartest.writeValue(0);
// start advertising
BLE.advertise();
Serial.println("BLE LED Peripheral");
}
void loop() {
// listen for BLE peripherals to connect:
BLEDevice central = BLE.central();
// if a central is connected to peripheral:
if (central) {
Serial.print("Connected to central: ");
Serial.println(central.address()); // print the central's MAC address:
// while the central is still connected to peripheral:
while (central.connected()) {
IDString.writeValue(ID2);
IDChartest.writeValue(ID);
}
// when the central disconnects, print it out:
Serial.print(F("Disconnected from central: "));
Serial.println(central.address()); // print the central's MAC address:
}
}