Open adrienlaveau opened 3 years ago
Advertised services and services in app are 2 different things. You can see if nRF connect shows any UUIDs when you scan. If this code returns all 0s, then most likely ATTiny is not advertising any UUIDs:
Serial.println(advertisedDevice.getServiceDataCount());
Serial.println(advertisedDevice.getServiceDataUUIDCount());
Serial.println(advertisedDevice.getServiceUUIDCount());
I have some experience with the RN4871 and I can say that it can give you a lot of headaches specially using the BLE transparent UART service.
Have you configured your module correctly? By the default the service for the transparent UART is not active, so you need to connect to the RN4871 and enter the command mode to activate the service.
I use the same UUIDs that you posted to talk to the RN4871 and turn on the notifications for the characteristic 49535343-1E4D-4BD9-BA61-23C647249616
.
Thanks for the quick feedback.
So indeed I read one post in which you were involved where someone was explaining that he got confused between both advertised services and services. BUt I could not find the post today. Concerning the ATtiny I can confirm that it "emits" info. Because I can see it on nRF Connect. I used the verb "emit" bause indeed I am, not sure that it is advertised. In fact I used the RN4871 chip as transparent UART. And from what I understand from the datasheet is that : What ever is sent on the serial to the RN4871 chip is then re-emitted by the RN4871 chip.
In the datasheet one can read "The Transparent UART TX Characteristic is used for data transmission by the Server or the Client. Once the Client Characteristic Configuration Descriptor (CCCD) of Transparent UART TX Characteristic is enabled, the Server sends data to the Client using the Notify property."
@CLDiego I used the following commands to activate transparant UART ` $$$
+
SS:C0 --> activates transparent UART
R,1 --> Reboot
`
And it works as I can see it on the nRF connect.
Now when you say "turn on the notification for the characteristic" this is ,aybe where I a, doing so,ething wrong. Is it on client or server side ? How should it be done ?
Thanks a lot
There should be an example here or in the arduino IDE for handling notifications using this library. Essentially, whenever new data is generated and sent through the UART service it will send a notification to the client (I'm assuming you are using the RN4871 as a server) and the client will catch the notification along the new data. In lamest terms you should do something like this:
pTXCharacteristic = pUARTService->getCharacteristic( charUUID);
pTXCharacteristic->registerForNotify(notifyCallback, false);
notifyCallback
is your function that will handle the processing of the incoming data
@chegewara, in nRF connect the characteristic has two UUID A "big one" : 49535343-1E4D-4BD9-BA61-23C647249616 A "small one" : 0x2902 that seems to be the UUID of the descriptor Here I admit I do not understand the difference.
By the way I read the whle PDF document by Kolban (https://github.com/nkolban/esp32-snippets/blob/master/Documentation/BLE%20C%2B%2B%20Guide.pdf) which helped a lot to understand the library. Really weel explained and nice to read.
@CLDiego thanks.
Indeed I imagined this possibilty but when looking for example is the IDE it was only to set up the notification on server side. Not to receive on client side. I tried to find how to code it by myself but got a bit demotivated :)
Let me read properly your comment to find how I should integrate it in my code.
Thank you
The UUID descriptor contains the information about the characteristic. i.e. if you can read, write, notify etc. You can see it as a set of flags, the data is going to be published through the characteristic.
The RN4871 handles the notifications by itself, you only need to program it on the esp32. You should see your RN4871 as a UART bridge.
I would encourage you to look at the example for notifications here
Thanks. So this example is exactly the one I based my code on.
But it does not work as such because : This line always returns 0 as I do not have advertised service (only notification) if (advertisedDevice.haveServiceUUID() && advertisedDevice.isAdvertisingService(serviceUUID)) {
If I tweak the code to go for the server connect when hit finds a matching MAC adress then it crashes and reboot the ESP32 on the follfollowing line Serial.print("Forming a connection to "); Serial.println(myDevice->getAddress().toString().c_str());
Correction ... it worked.
I just removed the condition to check the service and to connect directly if the mac address matches. I do not understand why it was not working before.
I will check the steps I have been thourgh and explain what happend.
Thanks you very much.
So, I did the following to make it work. I added a check on the MAC Address and kind of ignore the check on advertised service as the RN4871 does not have one. This way I could make it work because the connection starts and as soon as the RN4871 sends data I get the notification and receive it.
Thank you very much for the help !
I documented all this here for the next one : http://127.0.0.1:8000/assignments/week13/#how-to-setup-the-rn4871
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
/**
* Called for each advertising BLE server.
*/
void onResult(BLEAdvertisedDevice advertisedDevice) {
Serial.print("BLE Advertised Device found: ");
Serial.println(advertisedDevice.toString().c_str());
Server_BLE_Address = new BLEAddress(advertisedDevice.getAddress());
Scaned_BLE_Address = Server_BLE_Address->toString().c_str();
Serial.println(Scaned_BLE_Address);
if(Scaned_BLE_Address == My_BLE_Address){
doConnect = true;
BLEDevice::getScan()->stop();
myDevice = new BLEAdvertisedDevice(advertisedDevice);
}
// We have found a device, let us now see if it contains the service we are looking for.
if (advertisedDevice.haveServiceUUID() && advertisedDevice.isAdvertisingService(serviceUUID)) {
Serial.println("MATCHING SERVICE !!!!!");
BLEDevice::getScan()->stop();
myDevice = new BLEAdvertisedDevice(advertisedDevice);
doConnect = true;
doScan = true;
} // Found our server
} // onResult
}; // MyAdvertisedDeviceCallbacks
Dear all,
I have been reading extensively all the documentation I could find regarding my issue and could not find a solution so I will expose my problem here. Setup : BLE server : ATtiny 1614 sending via UART to RN4871 chip BLE Client : ESP32 using the code below on Arduino IDE
The code is the BLE_client example from Arduino with some debbuging modification of mine.
So I can find my device and match the MAC address BUT it seems there is no Service. The three lines below returns all 0. By the way I do not understand the difference between the three kind of Service (Data, Data UUID, UUID).
Serial.println(advertisedDevice.getServiceDataCount()); Serial.println(advertisedDevice.getServiceDataUUIDCount()); Serial.println(advertisedDevice.getServiceUUIDCount());
I can see the server and the characteristic on nRF connect ( I took the Device and Characteristic UUID from thje application). THe RN4871 chip documentation also confirms the UUID here page 65.I do not know where to look.
Client code
`
include "BLEDevice.h"
`
Any help would be deeply appreciated.