-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't connect to Client - is server mode possible? #47
Comments
Interesting question. The thing is that the Bluetooth architecture has different roles for devices. Usually the peripheral device provides a server and constantly sends out advertisements, then other devices can scan and connect in client mode. For example HM19 is per default a server (can be changed through AT commands) and ble-serial is always the client. Now Android mostly also acts as client, connecting to servers in headphones etc. That is why it will not directly work with ble-serial, because it is just another client with the Terminal. |
Thank you Jakeler. I actually need to use an existing Android app that acts as a client, so to get this working I need to find a way to send serial data over BLE from Windows with the BLE USB dongle acting as a server. I haven't found anything doing so. Have you come across anything along these lines during your own research? I understand that what I'm looking for isn't the standard scheme when it comes to IoT and typical makers' arduino sensor projects... |
Ok, I see, making the PC a server should work too. Problem is that the BLE lib (bleak) which I use is only a client implementation, so I can't easily enable it. There are APIs that would allow this though, on Linux with BlueZ/DBus: Edit: Some related discussion happened already on bleak: hbldh/bleak#81 |
with bless, which I could only get working on Windows so far
I made an experimental server implementation now, it can be installed like this:
Note this this version always acts as server, you have to install the normal version if the client function is needed again. (this will be different in the final release) To start it the service, read and write UUIDs have to be specified, for example the Nordic UART profile:
The device argument |
Thanks for the work! Not working for me, here is what I get:
I tried with 3 different USB BLE dongles, Details of the last one:
|
Hmm, interesting. Your BCM20702 should support the server role in theory, are you sure the driver is correct? I used a RTL8761B, which is in most generic/cheap BT 5.0 adapters and for example the Asus USB-BT500. |
The other ones show as "Generic Bluetooth Radio" (Cambridge Silicon Radio Ltd.). I uninstalled all bluetooth devices including hidden/not connected one from Device Manager, then let Windows load the drivers as well as check for updated rivers, no change. Any suggestion to ensure it's the proper driver? |
Maybe try a different driver package, I would not recommend downloading from random websites, but for example Lenovo offers a old version and newer version (still 2015 though). You are using Windows 10, right? Otherwise I honestly don't know. You could try to run this example script (just download and start it with |
with bless (working on Windows + Linux, Mac untested)
with bless (working on Windows + Linux, Mac untested)
I've looked to changes in the branch and see that parameter name to used is -g, not -d. I've tried now on my Ubunty 22.04 and I can get this result:
And I could see my Ubuntu advertising as "BLE Serial Server 674248". I can connect to it from Android, using "nRF Connect" app from Nordic. Also, I could connect from "Serial Bluetooth Terminal" app too, and send serial data, which I send/receive data on Linux on /tmp/ttyBLE in both directions !
Not every time connecting is successful, I often get error: BT applet on my KDE Plasma properly shows that I have active connection from my Anroid phone name So, maybe this should be merged to Master branch to be ready used when needed? The only issue I have is, when I try to specify custom UUIDs, it fails:
I think this 'badly formed hexadecimal UUID string' issue can be easily fixed. |
After googling about reading this https://stackoverflow.com/questions/63220786/django-how-to-fix-uuid-valueerrorbadly-formed-hexadecimal-uuid-string
But I could not get "Serial Bluetooth Terminal" successfully connected afterward (it has some issues with discovering UUIDs, I know, when device is BLE+Classic simultaneously). But "nRF Connect" could connect and send/receive data. |
with bless (working on Windows + Linux, Mac untested)
So, to get this new feature there is a PR #60, which is based on "server-mode" branch. I've forked this repo to https://github.com/zalexua/ble-serial and managed to successfully rebase Master to "server-mode" branch and then merge "server-mode" back to Master. Then I've tested both Client and Server modes, including Server mode with forwarding data to TCP socket and it really worked! So, while in PR #60 are some concerns about data integrity (on high speed?) I think "server-mode" branch really worth to be merged to upstream Master to get both features available. I'm going to do some minor improvements further. Like possibility to specify BLE name instead of generate it as predefined with a random PID part. |
Hey @zalexua, thanks for trying it out and working on it. Before declaring a release with this feature I would really like to get the 2 points sorted out:
Also since I am also on Linux, have to do at least do some basic checks on Windows as most users are there. |
with bless (working on Windows + Linux, Mac untested)
Hello @Jakeler ! I should share impression that Server mode works really well ! |
with bless (working on Windows + Linux, Mac untested)
Just a heads up, I worked more on the server mode branch recently and finally consider it ready! |
@Jakeler thank you for recent work on this !!!!! |
Congratulations for the project and thank you for making it open source.
Can ble-serial send a serial stream over BLE to an Android phone?
I got your stack working as I am able to scan and ble-serial connect to an HM19 module. But instead to connect to an HM10/HM19, I would like to establish a serial link over BLE via a USB BLE dongle (without using the HM19) to my android phone.
FYI without ble-serial and a USB-BLE dongle, I am able to connect my phone to the HM19: I first connected the HM19 to a USB-to-serial module CP210x and data sent to the COM port of the CP210x module would show on “Serial Bluetooth Terminal” on Android.
How come my phone doesn’t show with a ble-scan?
Is It possible to ble-serial to the phone?
The text was updated successfully, but these errors were encountered: