csash7 / mbed-BLE-Mouse

BLE Mouse library for Arduino boards with BLE support and mbed OS
17 stars 6 forks source link

Pairing Problem and no results on screen #2

Closed LucaImperial closed 3 years ago

LucaImperial commented 3 years ago

Hi csash7,

Thank you very much for your package. It helps a lot for creating a BLE mouse with the Arduino Nano 33 BLE.

After downloading and including the library I faced an error. After trying to upload the 'moveAndScroll' example onto the Arduino, I got the following error: '.....\Arduino\libraries\mbed-BLE-Mouse-master\src\HIDMouse.cpp: In member function 'void HIDMouse::start_advertising()': .....\Arduino\libraries\mbed-BLE-Mouse-master\src\HIDMouse.cpp:160:13: error: 'GapAdvertisingParams' has not been declared GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED, ^~~~~~~~'.

So what I did is I downloaded the file 'GapAdvertisingParams.h' from https://gitlab.serveur.io/nicolas/nucleo-64-lcd/-/blob/988172055d8504224d3164988c269187161bc41a/mbed-os/features/FEATURE_BLE/ble/GapAdvertisingParams.h

I then added the file to the library directory and included '#include "GapAdvertisingParams.h"' into the header of HIDMouse.cpp. Afterwards I was able to upload the example to the Arduino and it showed up as a Bluetooth mouse on my Windows computer. I was able to pair and connect to the mouse. Now my problem is that nothing happens (no scrolling, no clicking). I am literally using the example without any modifications.

Furthermore, the connection doesn't seem to be stable. Especally at the beginning it switches between connected, coupled, connected several times. This improves over time on several tries.

Could you help me out?

Best regards, Luca

csash7 commented 3 years ago

Could you please check the mbed version installed for your board? Tools > Boards > Board manager and search mbed. While developing this library, I have mbed version 1.1.4 installed and it is working as intended without any errors. If your installed version is not 1.1.4, please install it, verify and let me know.

If the error is indeed due to the version changes, I might have to update the library. Thank you.

LucaImperial commented 3 years ago

The mbed version installed was 1.3. After installing Version 1.1.4 the issue with the GapAdvertisingPrams was fixed. I can simply install and use the library. So that seems to be an issue with backwards compatibility of the mbed OS.

Still, I don't get any mouse movement on my screen. Connection seems to be stable though.

csash7 commented 3 years ago

Ah! As expected, I have to update the library with a new version. I am unsure why the mouse movement is not working. Different OS, interpret HID profiles differently. However, I have tested the library both in windows and android. Could you please connect it to any other device and verify?

LucaImperial commented 3 years ago

I tested it with an Android phone and another WIndows computer. Both are working fine. I guess it is about my computer then. I'll figure out what the problem is and post it here. Maybe others are ineterested in that, too.

LucaImperial commented 3 years ago

So what I found out upto now is it is not a matter of the device. It works fine with every device (even my computer now) when it was not paired before. When connecting the first time everything is working great. If you disconncect it once, leave it coupled and then pair it again, nothing will happen and the connection is unstable. Is there a way to fix this issue?

csash7 commented 3 years ago

Yeah, I am aware of this issue. To put it in simple terms, this issue is due to the lack of onboard storage in the Arduino BLE board. Laptops and mobiles save the Bluetooth device's info on pairing. So, they can connect to the device again without pairing(it saves time as device info needs not be exchanged again). But, Arduino BLE doesn't have storage to which it can save the pairing info. As a result, this issue occurs. But without the pairing feature, windows doesn't connect to a Bluetooth device as it is unsafe. So, before connecting Arduino BLE to a previously paired device, remove the device from paired devices first, and then attempt to connect.

LucaImperial commented 3 years ago

I see, makes sense. Maybe someone will find a way to get the paired device to connect propperly. You might put that into the description of the library. Would make it easier for people to understand it. Thanks a lot for your support!