Klaus_K:
I have created a project where I can switch between WiFi and BLE. I had some issues on the way and have not cleaned the code yet. Currently I need to reset the Nina and restart the WiFi driver.
The switch takes significant amount of time and therefore is only useful for use cases where you want to configure your device via Bluetooth and then switch to WiFi. You can also restart the Bluetooth mode from a webpage.
Interesting Klaus_K I would like to have a look at your code. Curious about the time delay. I just want to read 3 BLE LED's on or off state from 3 different devices, then update the Nano 33 IoT generated webpage. So a 10 second time delay might not be a big deal.
Presently I am having some strange issues just getting my BLE LED Central control program working. Seemed to work fine 3 days ago but now does not connect to the peripheral LED. The peripheral works fine since I can change the LED using nrf-connect for mobile, and my web page javascript BLE program.
My program on github is here
The program scans for devices that contain the local name "LED" then when you send a "1" it connects to the last device found. Then when you send a "2" it goes back to scanning. When it is connected you can connect 3V3 to pin 2 to turn on the LED on both devices (The central and the peripheral).
It was just a test program. It does seem to work, but my serial output is not getting me much useful information.
Update to the above. All three BLE programs work fine just getting strange data from these calls.
// Note the 2 GATT's are slightly different: service=19b10010, LED=19b10011
BLECharacteristic ledCharacteristic = peripheral.service("19b10010-e8f2-537e-4f6c-d104768a1214").characteristic("19b10011-e8f2-537e-4f6c-d104768a1214"); //worked
Serial.print("ledCharacteristic: ");
Serial.println(ledCharacteristic);
Serial.print("ledCharacteristic.descriptor(0): ");
Serial.println(ledCharacteristic.descriptor(0));
Serial.print("ledCharacteristic.descriptor(0).value(): ");
Serial.println((int)ledCharacteristic.descriptor(0).value());
Serial.print("ledCharacteristic.descriptor(1): ");
Serial.println(ledCharacteristic.descriptor(1));
Serial.print("ledCharacteristic.descriptor(1).value(): ");
Serial.println((int)ledCharacteristic.descriptor(1).value());
)
What I want to see is proof about if the LED is on or off, but what I am getting is zero when the LED is on or when it is off.
ledCharacteristic: 1
ledCharacteristic.descriptor(0): 0
ledCharacteristic.descriptor(0).value(): 0
ledCharacteristic.descriptor(1): 0
ledCharacteristic.descriptor(1).value(): 0
... Sorry editing while working on things.
I think I understand what the problem is. Got it working now with some changes, but I do not like this function.
void printData(const unsigned char data[], int length) {
for (int i = 0; i < length; i++) {
unsigned char b = data[i];
if (b < 16) {
Serial.print("0");
}
Serial.print(b, HEX);
}
}
Can someone explain it, or better yet show me a simpler way to tell if the LED is on or off.
The code I needed to get things working is
if (ledCharacteristic.canRead()) {
ledCharacteristic.read();
if (ledCharacteristic.valueLength() > 0) {
Serial.println();
Serial.print(", value 0x");
printData(ledCharacteristic.value(), ledCharacteristic.valueLength());
}
}