Open faceless2 opened 8 years ago
Hi. Thanks for your input. The simpleclient is just a raw sample client to illustrate how the protocol can be used. The protocol documentation can be found at https://github.com/50ButtonsEach/fliclib-linux-hci/blob/master/ProtocolDocumentation.md. The commands in simpleclient directly refer to the protocol commands where you can read exactly what they do in detail. I'd strongly suggest you also check out the sample programs in the clientlib directory which is more high level. You have the scan wizard and the program that connects to all verified buttons.
I guess we should add some high level documentation so things are more clear. Until that is done, here is some info:
A button itself store pairings to devices it has been connected to before (and verified). When it comes from the factory it has no pairings and is therefore in "public mode". When it is in public mode it accepts connections from any device as well as pair requests. As soon at is has at least one pairing it is put in "private mode". Private mode means that it won't accept connections from non-paired devices. When it is in private mode, it can be held down for 7 seconds to be put in "temporary public mode" which means it will be in public mode for 30 seconds and then go back to private mode again.
When you remove the pairing in your phone, the pairing is not removed from the memory inside the button. Why? Since if it is not connected at the moment there is no way to do that. The only way to remove all pairings in the button at the moment is to do a factory reset.
You wondered how the flicd handles connections. When flicd is started or no client is connected, the flicd will not have any connections to any button open, since there is no reason to. If nobody is interested in button events there is no need to have an open connection. A flic button can only be connected to one device at a time so this is also to avoid problems that users think their flic doesn't work but it is in fact connected to some other device they didn't think about. As soon as there are at least one "connection channel" open for that button, the flicd will connect to the button and reconnect if the button becomes disconnected (for example if it goes out of range).
The force disconnect command does exactly what's written in the documentation, it removes all connection channels among all clients for the specified Flic button bluetooth address. It does not remove the pairing keys.
That a button is verified and is inside the db means that it is paired with the button and has the pairing keys needed to establish a connection to the button. If you scan for a button and see that it is private and the button is also not inside the db, there is no point in trying to connect to it since the connection will be refused. Check out the scan wizard sample how to create a user interface for scanning buttons. We are planning to integrate the scan wizard directly in flicd as a command "CmdStartScanWizard" and then events will be sent with the progress as well as messages to show to the user, for example hold down for 7 seconds to make it public.
When you press the button and it fades red, it means it is advertising and not connected at the moment.
Good idea with bringing up the hci interface again if it was up before flicd was started.
Does this answer your questions?
Thanks, that is a huge help. I see where I went wrong.
My presumption was that the flic daemon was directly analogous to the app on the phone: it would sense if a previously connected button was in range, open a connection to it and send events to any client that was listening (which may be none) without me having to explicitly select "connect' (I don't from the app, after all).
I see that's not the case - I will need to open my client and instruct it to ask flicd to scan and/or to connect to everything it knows about. That's fine. I'll revisit my process.
The scan wizard has now been implemented
I'm piling on this issue because I had a problem connecting to my flics as well. With flicd running, I did:
startScanWizard
Please click your Flic button!
Found public button 80:e4:da:71:dc:be F018cdy-, connecting...
Connected, now pairing and verifying...
Scan wizard done with status WizardInternetBackendError
I tried several times, but kept getting WizardInternetBackendError
. Eventually, I figured out that my flic had already been paired and was in private mode. Holding the flic button for 7 seconds and then running the command worked:
startScanWizard
Please click your Flic button!
Found public button 80:e4:da:71:dc:be F018cdy-, connecting...
Connected, now pairing and verifying...
Scan wizard done with status WizardSuccess
New verified button: 80:e4:da:71:dc:be
getInfo
Got info: Attached, b8:27:eb:95:38:8d (PublicBdAddrType), max pending connections: 128, max conns: 10, current pending conns: 0, currently no space: n
Verified buttons:
80:e4:da:71:dc:be
connect 80:e4:da:71:dc:be 10
Create conn: 10 NoError Disconnected
Connection status changed: 10 Connected
Connection status changed: 10 Ready
It was also hilarious to see the button report all of the presses for the last few hours:
Button click/hold: 10, ButtonClick, queued, 4196 seconds ago
Button up/down: 10, ButtonDown, queued, 4196 seconds ago
Button up/down: 10, ButtonUp, queued, 4196 seconds ago
Button click/hold: 10, ButtonClick, queued, 4196 seconds ago
Button single/double click: 10, ButtonDoubleClick, queued, 4196 seconds ago
Button single/double click/hold: 10, ButtonDoubleClick, queued, 4196 seconds ago
Button up/down: 10, ButtonDown, queued, 4195 seconds ago
Button up/down: 10, ButtonUp, queued, 4194 seconds ago
My suggestion is that this part of the process could be better documented. I'm also surprised that the error wasn't WizardButtonIsPrivate
as documented in the protocol.
Hi. Are you running all code from the master branch directly or are you using a previous release?
Anyway, this is strange. If it says it found a public button, that should really be a public button since it advertises a different name when it's private/public. The first letter is 'F' when it is public and 'f' when it is private. Could you try again by stopping flicd, remove the database and then restart flicd?
And yes, the button events will be queued until they are delivered and it's up to the user to possibly drop events if they are considered too old ;)
I just tried it with an empty database and it worked like you said:
startScanWizard
Please click your Flic button!
Found private button. Please hold down it for 7 seconds to make it public.
Scan wizard done with status WizardFailedTimeout
Hmm. Maybe this one was never paired before. Any way I can factory reset it so that I can test it?
Yes. Remove the battery. Click once on the button to discharge possible current that is left. Insert the battery. Once the LED has shut down, press and hold the button for 12 seconds and then release it. The button will now reboot and the pairing list will be empty.
So, I tried that and it still connected correctly. I'm guessing that I tried to pair this button with an Asus VK810 4G (Android 5.0.2) that disconnected halfway through the pairing process. (This is the device I sent you the Bluetooth HCI snoop log for by e-mail.)
I see. Did you get it working with the tablet? Otherwise I'm still waiting for the extended snoop log ;)
Hello, I am running 0.4 and on RasPi 3B+ and I get the same error (different button ID) as leanto. I tried the 7sec reset trick before and during the scan but not luck. I also tried different clients (simpleclient, python wizard, etc) - no difference. Any help is much appreciated.
startScanWizard
Please click your Flic button!
Found public button 80:e4:da:71:dc:be F018cdy-, connecting...
Connected, now pairing and verifying...
Scan wizard done with status WizardInternetBackendError
@Emill - any insights? I tried factory reset and I still have the same challenge.
Hi, Did you ever figure out how to get around this issue on Linux? I am experiencing the same behavior.
I am really struggling to get my buttons working with flicd reliably. I have had one working, and have had all working with the phone app. But the procedure doesn't seem to be repeatable or predictable.
I have verified all of them can be paired with the phone app, and then once paired I have deleted the pairing and removed the device from the list of paired bluetooth devices on the phone. I believe this leaves the buttons in an "unpaired" state.
I then run flicd and start simpleclient, and type "connect XXX N" to pair - the BT address I have found previously by running startScan. This typically gives me no response, or a response about the button being private (without documentation I have to presume this means the button is paired to something else, but it happens even with buttons that had been explicitly deleted from the phone app, or brand new buttons that have never been paired with anything).
The method which finally seemed to work for me was "forceDisconnect XXXX", then hold the button down for 10s, then "connect XXX 0" to pair the button. Finally at this point I could see the button presses, and with this procedure I was able to connect and see presses from all four buttons.
I then quit simpleclient, leaving flicd running, and suddenly my buttons are no longer working! Pressing them gave the "pulsing glow" I have come to realise means they are not paired, and when I fired up simpleclient again I can not see any of their presses.
Here's the current output of "getInfo" from simpleclient:
getInfo Got info: Attached, b8:27:eb:e1:f8:XX (PublicBdAddrType), max pending connections: 128, max conns: 10, current pending conns: 4, currently no space: n Verified buttons: 80:e4:da:71:3b:XX 80:e4:da:71:78:XX 80:e4:da:71:79:XX 80:e4:da:71:86:XX
So I can see they are known to the daemon as "verified buttons". Does this mean they're connected now? They are in the database but aren't currently connected? I have four pending connections, what does that mean? I have no idea what to do next.
The frustrating part is that I have had this working - my initial testing with one button in my own client worked, but when I tried with more than one button I had great difficulty pairing them or and getting them to stay paired. I can't really give more detail I'm afraid, because I was trying dozens of things and buttons I had connected and working would suddenly stop working when I tried something else. It was very hard to identify exactly what was going on.
What I am expecting to be able to do here is:
Are these expectations valid?
I'm filing this is an issue, not just a request for support, because either the simpleclient needs a fix, flicd needs a fix or the documentation needs a fix to correct my expectations.
Regardless of the above, I also have some suggestions which would have made the last few hours trying to figure this out a lot easier.