-
Notifications
You must be signed in to change notification settings - Fork 177
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
Is it possible to "free" the physical Bluetooth interface so that it can be used by external commands? #17
Comments
Hi @josephroberts from a reading of the current code this is not currently possible, at least not in the manner you described. At least on Linux, the |
Speaking of the "Stop()" method (in ble/linux/device.go), it doesn't appear to work. I try to use it to stop the Gatt server and it is completely ineffectual. Looking at the code I can see why. The method simply calls HCl.Close(), and HCI.Close() does nothing but return nil. I tried modifying the "Stop()" method to instead call HCI.Stop(), but that is ineffectual as well. What I want to do is detect when a peripheral has connected to the Gatt server; get the address of the peripheral; and if it is not what is expected, disconnect the server from the peripheral. I have figured out how to do everything except the disconnect part. I figured I could simply stop the Gatt server to accomplish the disconnect, but I can't find a way to do this. The aforementioned "Stop()" method would seem to be intended to do this but as I wrote above, it's not getting the job done. Any ideas? Thanks |
@bbartol The However, from your description, it sounds more like a "disconnect" at the connection level. We should add that functionality back soon. |
@roylee17, Thanks for the shout back. I have figured out how to do everything that you described as onConnect(conn)'s functionality. What's left is to figure out how to disconnect from the server side. Nothing I have tried so far has worked. Calling Disconnect stops my whole program; and as I wrote before, the code to Stop() the server is ineffectual (because it has only been stubbed out so far). I got so far as finding the code where the HCI device is first opened. In that code, an HCIdown and HCIup is executed at the beginning to effect a reset of the device before proceeding to bind the device to the HCI channel. So I thought maybe I could do the same thing to reset the device and that would cause the server to stop. What I found, however, is that neither HCIdown nor HCIup would work once the device is bound to the HCI channel (they both return non-nIl for error). So then I embarked on trying to figure out how to unbind the device. I searched through the code for a couple of hours and found nothing to do this and became concerned that I was embarking down a rabbit hole. So that's where I'm at. Thanks again. |
Is it blocked or crashed? Can you try it with go routine? On the other hand, the device up/down/reset in #30 is another way to "work around" your scenario. As you tried, once the socket got bound, it can't be up/down/reset. With regular TCP/IP sockets, we can use some socket options, or I was pretty sure that worked for me earlier though I haven't reproduced it in my current environment. Unless I was using multiple HCI USB dongles, and the auto fallback logic (passing -1 as device id) fooled me into believing that I was reusing the same HCI device while it actually picked another for me... Anyway, I'm building my kernel from source so I can peak and poke the it and track what's happening underneath. |
@roylee17 @bbartol I am spending the week trying to get to the bottom of this. I think the HCI interface is System specs:
main.go
Strace output:
|
This is the blocking line. Is it necessary to always trigger a write to complete the read? The finished reads always do this...
The I modified the
I did notice something strange - the read resumes when the process is killed. This line in the strace output below
So far I have tried to force the read to finish with a few methods, none of which work. I attempted to flush the socket before closing it with each of the commented out lines.
I tried to poll for data when the socket is first opened.
|
@josephroberts |
@moogle19 thanks, so perhaps we are issuing an extra read that is not needed. |
I have narrowed it down to the read and writes - small steps haha - by changing the
Here is the strace output, showing the interface being
|
@josephroberts |
@moogle19 yep. I am trying to solve this using Modification to
Modification to
Strace output
it hangs here: BTW - I am being verbose here for my own notes :P |
Non-blocking I/O Let's see if we can tackle this within GO land (tricky though...). |
Fixed by #32 |
Thanks everyone for the feedback to my original post. I was able to accomplish the one piece that was vexing me (disconnecting the client from the server side) by calling Device.HCI.conns[ClientMapKey].Close(). The trick was discerning ClientMapKey (the key that references the connection to the client that is currently connected to my Gatt server). I was able to accomplish everything that I need (at least so far) by adding the attached code to my local copy of the ble library. I organized this code so that none of the existing code (other than the example I discuss below) needed to be modified. If you unzip (keeping the folder structure) into your local copy of the github.com/currantlabs/ble folder (for example, my local copy is at /go/src/github.com/currantlabs/ble), you should be able to rebuild your code with any of the functionality I added and try it out if you want. Included in the attached (in ble/examples/blesh_AGEX) is a scaled down and heavily modified copy of the original blesh example. Changes that I made to said example are commented as "AGEX" (//AGEX). In summary, they are as follows: main.go:
adv.go:
Other
|
I would like to be able to use the physical Bluetooth interface without stopping the go application so I need some way to free up the device once it has been initialised. Is this possible?
While the code is running I get errors as expected:
Is it possible to free the device created and then use external commands during the sleep period?
The text was updated successfully, but these errors were encountered: