Skip to content

Commit

Permalink
New Scan Wizard commands to easier add new buttons.
Browse files Browse the repository at this point in the history
Get button UUID command.
Option to wait for hci to become ready instead of exiting on startup.
New acknowledgement method for button events to be sure no button events are dropped if the bluetooth connection gets dropped after click.
Dropped the libcurl dependency.
A lot of stability fixes.
  • Loading branch information
Emill committed Jul 13, 2016
1 parent 93b3ff6 commit f5265c8
Show file tree
Hide file tree
Showing 74 changed files with 3,816 additions and 2,103 deletions.
117 changes: 116 additions & 1 deletion ProtocolDocumentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Summary
* [BdAddrType](#bdaddrtype)
* [LatencyMode](#latencymode)
* [BluetoothControllerState](#bluetoothcontrollerstate)
* [ScanWizardResult](#scanwizardresult)
* [Commands](#commands)
* [CmdGetInfo](#cmdgetinfo)
* [CmdCreateScanner](#cmdcreatescanner)
Expand All @@ -33,6 +34,9 @@ Summary
* [CmdForceDisconnect](#cmdforcedisconnect)
* [CmdChangeModeParameters](#cmdchangemodeparameters)
* [CmdPing](#cmdping)
* [CmdGetButtonUUID](#cmdgetbuttonuuid)
* [CmdCreateScanWizard](#cmdcreatescanwizard)
* [CmdCancelScanWizard](#cmdcancelscanwizard)
* [Events](#events)
* [EvtAdvertisementPacket](#evtadvertisementpacket)
* [EvtCreateConnectionChannelResponse](#evtcreateconnectionchannelresponse)
Expand All @@ -45,6 +49,11 @@ Summary
* [EvtGotSpaceForNewConnection](#evtgotspacefornewconnection)
* [EvtBluetoothControllerStateChange](#evtbluetoothcontrollerstatechange)
* [EvtPingResponse](#evtpingresponse)
* [EvtGetButtonUUIDResponse](#evtgetbuttonuuidresponse)
* [EvtScanWizardFoundPrivateButton](#evtscanwizardfoundprivatebutton)
* [EvtScanWizardFoundPublicButton](#evtscanwizardfoundpublicbutton)
* [EvtScanWizardButtonConnected](#evtscanwizardbuttonconnected)
* [EvtScanWizardCompleted](#evtscanwizardcompleted)

Enums
-----
Expand Down Expand Up @@ -152,6 +161,30 @@ The server software has just got connected to the HCI socket and initiated a res
**Attached** -
The bluetooth controller has done initialization and is up and running.

### ScanWizardResult
The result of a scan wizard. When the scan wizard is completed it will stop and return a result.

**WizardSuccess** -
Indicates that a button was successfully paired and verified. You may now create a connection channel to that button.

**WizardCancelledByUser** -
A CmdCancelScanWizard was sent.

**WizardFailedTimeout** -
The scan wizard did not make any progress for some time. Current timeouts are 20 seconds for finding any button, 20 seconds for finding a public button (in case of a private button was found), 10 seconds for connecting the button, 30 seconds for pairing and verifying the button.

**WizardButtonIsPrivate** -
First the button was advertising public status, but after connecting it reports private. Probably it switched from public to private just when the connection attempt was started.

**WizardBluetoothUnavailable** -
The bluetooth controller is not attached.

**WizardInternetBackendError** -
The internet request to the Flic backend failed.

**WizardInvalidData** -
According to the Flic backend, this Flic button supplied invalid identity data.

Commands
--------
### CmdGetInfo
Expand Down Expand Up @@ -234,6 +267,30 @@ _uint8\_t_: **opcode**: 7
_uint32\_t_: **ping_id**:
An identifier that will be sent back in return.

### CmdGetButtonUUID
Get the 128-bit identifier for a verified button. Each button has a unique identifier. An EvtGetButtonUUIDResponse will be sent back immediately in return with the bd\_addr field set to the same value as in the request. The uuid will be filled in as well. If the button with the given bluetooth address is not verified, the uuid will be all zeros.

_uint8\_t_: **opcode**: 8

_bdaddr\_t_: **bd_addr**:
Bluetooth device address of the button to look up.

### CmdCreateScanWizard
Starts a scan wizard. If there already exists a scan wizard with the same id, this does nothing.

_uint8\_t_: **opcode**: 9

_uint32\_t_: **scan_wizard_id**:
A unique identifier.

### CmdCancelScanWizard
Cancel a scan wizard that was previously started. If there exists a scan wizard with this id, it is cancelled and an EvtScanWizardCompleted is sent with the reason set to WizardCancelledByUser.

_uint\_t_: **opcode**: 10

_uint32\_t_: **scan_wizard_id**:
The identifier that was given when the scan wizard was started.

Events
------
### EvtAdvertisementPacket
Expand All @@ -250,7 +307,7 @@ The bluetooth address of this Flic button. Use it to establish a connection chna
_uint8\_t_ **name_length**:
The length in bytes of the name following.

_char[16] **name**:
_char[16]_ **name**:
The first _name\_length_ bytes of this array contain the UTF-8 encoding of the advertised name. The other bytes will be zeros.

_int8\_t_ **rssi**:
Expand Down Expand Up @@ -312,6 +369,9 @@ The following event types are defined:

_uint8\_t_ **opcode**: 4, 5, 6 or 7 for the different types of event, in the same order as above.

_uint32\_t_ **conn_id**:
Connection channel identifier.

_enum ClickType_ **click_type**:
The click type. For each opcode, there are different possible values.

Expand Down Expand Up @@ -393,3 +453,58 @@ _uint8\_t_: **opcode**: 13

_uint32\_t_: **ping_id**:
Same ping id as sent in the CmdPing.

### EvtGetButtonUUIDResponse
Sent in return to a CmdGetButtonUUID.

_uint8\_t_: **opcode**: 14

_bdaddr\_t_: **bd_addr**:
The bluetooth device address of the request.

_uint8\_t[16]_: **uuid**:
The uuid if the button with the given bluetooth address was found and verified. Otherwise all zeros.

### EvtScanWizardFoundPrivateButton
Sent once if a private button is found during the scan. If this is received, tell the user to hold the button down for 7 seconds.

_uint8\_t_: **opcode**: 15

_uint32\_t_: **scan_wizard_id**:
Scan wizard id.

### EvtScanWizardFoundPublicButton
Sent once if a public button is found during scan. Now the scan wizard stops scanning internally and instead initiates a connection to this button.

_uint8\_t_: **opcode**: 16

_uint32\_t_: **scan_wizard_id**:
Scan wizard id.

_bdaddr\_t_: **bd_addr**:
The bluetooth address of the Flic button that was found.

_uint8\_t_ **name_length**:
The length in bytes of the name following.

_char[16]_ **name**:
The first _name\_length_ bytes of this array contain the UTF-8 encoding of the advertised name. The other bytes will be zeros.

### EvtScanWizardButtonConnected
Sent when the found button connects for the first time. Now the verification and pairing process will begin.

_uint8\_t_: **opcode**: 17

_uint32\_t_: **scan_wizard_id**:
Scan wizard id.

### EvtScanWizardCompleted
Sent when the scan wizard has completed. See ScanWizardResult documentation for more information.

_uint8\_t_: **opcode**: 18

_uint32\_t_: **scan_wizard_id**:
Scan wizard id.

_enum ScanWizardResult_: **result**:
Result of the scan wizard.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ If you have compiled your own kernel you must make sure to include support for B
### Bluetooth controllers
All Bluetooth controllers with support for Bluetooth 4.0 and Bluetooth Low Energy (Bluetooth Smart) that have Linux support should work. We have tested compatibility with some common Bluetooth controllers. The following devices have been tested and confirmed:

**Plugable USB Bluetooth 4.0 Low Energy Micro Adapter (Broadcom BCM20702 Bluetooth 4.0)**
**Plugable USB Bluetooth 4.0 Low Energy Micro Adapter / Asus USB-BT400 (Broadcom BCM20702 Bluetooth 4.0)**
- Supports 14 concurrent connections and in total 32 pending connections.

**Raspberry Pi 3 model B (Broadcom BCM43438 Bluetooth 4.1)**
Expand All @@ -40,15 +40,15 @@ All Bluetooth controllers with support for Bluetooth 4.0 and Bluetooth Low Energ

## Quick start
### Packages
The only dependency is libcurl, which should be installed by default on most Linux distributions.
There are no dependencies except the standard C/C++ libraries, which should be installed by default on most Linux distributions.
### Running
It might be a good idea to disable a currently running bluez daemon (bluetoothd) to avoid interference, although not necessary. To see if it's running, run `ps aux | grep bluetoothd`. If it's running, try to disable it through the system's tools `service bluetooth stop` or `systemctl stop bluetooth` on Ubuntu, or just kill the process.

The server process needs to have access to the Bluetooth HCI channel. There are two ways to get this. Either run the daemon as root or give the process permissions by executing `sudo setcap cap_net_admin=ep ./flicd` which enables you to run it later as a normal user.

Now start the daemon in one terminal by executing `./flicd -f flic.sqlite3`. Additional options are listed if you leave out the database argument.

In another terminal, `cd simpleclient`, compile it with `make` and run with `./simpleclient localhost`. You will be shown the available commands. Type `startScan` and press enter to start scanning for buttons. Then press your flic button (and make sure it is disconnected to any other devices such as a smartphone) and you should see it appear. Type `stopScan` and press enter to stop scanning (it's ok if output text are interleaved with what you type). Hold your Flic button for 7 seconds to make it public, and make sure that it glows red. Then enter the command `connect <BDADDR> <id>` where `<BDADDR>` is the address that appeared during scan. For `<id>`, put any integer that will be used later to refer to this connection. The button should now connect and you will see click events appear. Type `disconnect <id>` to later disconnect.
In another terminal open the simpleclient directory, compile it with make and run with `./simpleclient localhost`. You will be shown the available commands. Type `startScanWizard` and press enter to scan and add a button. Then press your flic button (and make sure it is disconnected to any other devices such as a smartphone) and follow the instructions in the console. After your button has been added, enter the command `connect <BDADDR> <id>` where `<BDADDR>` is the address that appeared during scan. For `<id>`, put any integer that will be used later to refer to this connection. The button should now connect and you will see click events appear. Type `disconnect <id>` to later disconnect.

You can also try out the websocket example. Run both the daemon and the websocket proxy. Then open up the client html page.

Expand Down Expand Up @@ -78,6 +78,8 @@ Usage: ./flicd -f sqlite_db_file.db [options]
-d --daemon Run flicd as a Linux daemon.
-l --log-file Specify a log file name instead of using stderr.
-w --wait-for-hci When starting flicd, wait for hci endpoint to become available instead of exiting with failure status.
```

## Troubleshooting
Expand Down
Binary file modified bin/armv6l/flicd
Binary file not shown.
Binary file modified bin/x86_64/flicd
Binary file not shown.
12 changes: 7 additions & 5 deletions clientlib/java/lib/docs/allclasses-frame.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
<!-- NewPage -->
<html lang="sv">
<head>
<!-- Generated by javadoc (1.8.0_92) on Mon May 09 11:28:02 CEST 2016 -->
<!-- Generated by javadoc (version 1.7.0_71) on Wed Jul 13 20:46:57 CEST 2016 -->
<title>All Classes</title>
<meta name="date" content="2016-05-09">
<meta name="date" content="2016-07-13">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<h1 class="bar">All&nbsp;Classes</h1>
<h1 class="bar">All Classes</h1>
<div class="indexContainer">
<ul>
<li><a href="io/flic/fliclib/javaclient/Bdaddr.html" title="class in io.flic.fliclib.javaclient" target="classFrame">Bdaddr</a></li>
Expand All @@ -24,10 +23,13 @@ <h1 class="bar">All&nbsp;Classes</h1>
<li><a href="io/flic/fliclib/javaclient/enums/DisconnectReason.html" title="enum in io.flic.fliclib.javaclient.enums" target="classFrame">DisconnectReason</a></li>
<li><a href="io/flic/fliclib/javaclient/FlicClient.html" title="class in io.flic.fliclib.javaclient" target="classFrame">FlicClient</a></li>
<li><a href="io/flic/fliclib/javaclient/GeneralCallbacks.html" title="class in io.flic.fliclib.javaclient" target="classFrame">GeneralCallbacks</a></li>
<li><a href="io/flic/fliclib/javaclient/GetButtonUUIDResponseCallback.html" title="class in io.flic.fliclib.javaclient" target="classFrame">GetButtonUUIDResponseCallback</a></li>
<li><a href="io/flic/fliclib/javaclient/GetInfoResponseCallback.html" title="class in io.flic.fliclib.javaclient" target="classFrame">GetInfoResponseCallback</a></li>
<li><a href="io/flic/fliclib/javaclient/enums/LatencyMode.html" title="enum in io.flic.fliclib.javaclient.enums" target="classFrame">LatencyMode</a></li>
<li><a href="io/flic/fliclib/javaclient/enums/RemovedReason.html" title="enum in io.flic.fliclib.javaclient.enums" target="classFrame">RemovedReason</a></li>
<li><a href="io/flic/fliclib/javaclient/TimerTask.html" title="interface in io.flic.fliclib.javaclient" target="classFrame"><span class="interfaceName">TimerTask</span></a></li>
<li><a href="io/flic/fliclib/javaclient/ScanWizard.html" title="class in io.flic.fliclib.javaclient" target="classFrame">ScanWizard</a></li>
<li><a href="io/flic/fliclib/javaclient/enums/ScanWizardResult.html" title="enum in io.flic.fliclib.javaclient.enums" target="classFrame">ScanWizardResult</a></li>
<li><a href="io/flic/fliclib/javaclient/TimerTask.html" title="interface in io.flic.fliclib.javaclient" target="classFrame"><i>TimerTask</i></a></li>
</ul>
</div>
</body>
Expand Down
12 changes: 7 additions & 5 deletions clientlib/java/lib/docs/allclasses-noframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
<!-- NewPage -->
<html lang="sv">
<head>
<!-- Generated by javadoc (1.8.0_92) on Mon May 09 11:28:02 CEST 2016 -->
<!-- Generated by javadoc (version 1.7.0_71) on Wed Jul 13 20:46:57 CEST 2016 -->
<title>All Classes</title>
<meta name="date" content="2016-05-09">
<meta name="date" content="2016-07-13">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<h1 class="bar">All&nbsp;Classes</h1>
<h1 class="bar">All Classes</h1>
<div class="indexContainer">
<ul>
<li><a href="io/flic/fliclib/javaclient/Bdaddr.html" title="class in io.flic.fliclib.javaclient">Bdaddr</a></li>
Expand All @@ -24,10 +23,13 @@ <h1 class="bar">All&nbsp;Classes</h1>
<li><a href="io/flic/fliclib/javaclient/enums/DisconnectReason.html" title="enum in io.flic.fliclib.javaclient.enums">DisconnectReason</a></li>
<li><a href="io/flic/fliclib/javaclient/FlicClient.html" title="class in io.flic.fliclib.javaclient">FlicClient</a></li>
<li><a href="io/flic/fliclib/javaclient/GeneralCallbacks.html" title="class in io.flic.fliclib.javaclient">GeneralCallbacks</a></li>
<li><a href="io/flic/fliclib/javaclient/GetButtonUUIDResponseCallback.html" title="class in io.flic.fliclib.javaclient">GetButtonUUIDResponseCallback</a></li>
<li><a href="io/flic/fliclib/javaclient/GetInfoResponseCallback.html" title="class in io.flic.fliclib.javaclient">GetInfoResponseCallback</a></li>
<li><a href="io/flic/fliclib/javaclient/enums/LatencyMode.html" title="enum in io.flic.fliclib.javaclient.enums">LatencyMode</a></li>
<li><a href="io/flic/fliclib/javaclient/enums/RemovedReason.html" title="enum in io.flic.fliclib.javaclient.enums">RemovedReason</a></li>
<li><a href="io/flic/fliclib/javaclient/TimerTask.html" title="interface in io.flic.fliclib.javaclient"><span class="interfaceName">TimerTask</span></a></li>
<li><a href="io/flic/fliclib/javaclient/ScanWizard.html" title="class in io.flic.fliclib.javaclient">ScanWizard</a></li>
<li><a href="io/flic/fliclib/javaclient/enums/ScanWizardResult.html" title="enum in io.flic.fliclib.javaclient.enums">ScanWizardResult</a></li>
<li><a href="io/flic/fliclib/javaclient/TimerTask.html" title="interface in io.flic.fliclib.javaclient"><i>TimerTask</i></a></li>
</ul>
</div>
</body>
Expand Down
37 changes: 14 additions & 23 deletions clientlib/java/lib/docs/constant-values.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,25 @@
<!-- NewPage -->
<html lang="sv">
<head>
<!-- Generated by javadoc (1.8.0_92) on Mon May 09 11:28:02 CEST 2016 -->
<!-- Generated by javadoc (version 1.7.0_71) on Wed Jul 13 20:46:57 CEST 2016 -->
<title>Constant Field Values</title>
<meta name="date" content="2016-05-09">
<meta name="date" content="2016-07-13">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="Constant Field Values";
}
}
catch(err) {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="Constant Field Values";
}
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar.top">
<div class="topNav"><a name="navbar_top">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.top.firstrow">
</a><a href="#skip-navbar_top" title="Skip navigation links"></a><a name="navbar_top_firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
Expand All @@ -47,10 +40,10 @@
</ul>
<ul class="navList">
<li><a href="index.html?constant-values.html" target="_top">Frames</a></li>
<li><a href="constant-values.html" target="_top">No&nbsp;Frames</a></li>
<li><a href="constant-values.html" target="_top">No Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="allclasses-noframe.html">All&nbsp;Classes</a></li>
<li><a href="allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
Expand All @@ -64,7 +57,7 @@
//-->
</script>
</div>
<a name="skip.navbar.top">
<a name="skip-navbar_top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
Expand All @@ -73,11 +66,9 @@ <h1 title="Constant Field Values" class="title">Constant Field Values</h1>
<h2 title="Contents">Contents</h2>
</div>
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<div class="bottomNav"><a name="navbar_bottom">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.bottom.firstrow">
</a><a href="#skip-navbar_bottom" title="Skip navigation links"></a><a name="navbar_bottom_firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
Expand All @@ -97,10 +88,10 @@ <h2 title="Contents">Contents</h2>
</ul>
<ul class="navList">
<li><a href="index.html?constant-values.html" target="_top">Frames</a></li>
<li><a href="constant-values.html" target="_top">No&nbsp;Frames</a></li>
<li><a href="constant-values.html" target="_top">No Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="allclasses-noframe.html">All&nbsp;Classes</a></li>
<li><a href="allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
Expand All @@ -114,7 +105,7 @@ <h2 title="Contents">Contents</h2>
//-->
</script>
</div>
<a name="skip.navbar.bottom">
<a name="skip-navbar_bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
Expand Down
Loading

0 comments on commit f5265c8

Please sign in to comment.