-
Notifications
You must be signed in to change notification settings - Fork 0
4. State of Knowledge Findings
These findings and
notes refer to the Lego
Technic Hub 2 (#88012).
in here we present a tidied collection of all our
notes taken during the realization of the project.
-
Command/Message format:
-
Example 1: A Command, resp. a
Message/Notification has the format, e.g.:
Byte
position index
0
1
2
3
4
5
6
7
8
9
Message
M
0X0a
0×00
0×47
0×00
0×02
0×01
0×00
0×00
0×00
0×01
Meaning
-
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><font face="Liberation Sans, sans-serif"><font size="2" style="font-size: 10pt"><span style="font-style: normal"><span style="font-weight: normal">total length in bytes</span></span></font></font></span></font></span>
-
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><font face="Liberation Sans, sans-serif"><font size="2" style="font-size: 10pt"><span style="font-style: normal"><span style="font-weight: normal">here 10 bytes ≡ 0x0a</span></span></font></font></span></font></span>
-
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><font size="2" style="font-size: 10pt"><span style="font-style: normal"><span style="font-weight: normal">Hub ID</span></span></font></span></font></span>
-
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><font size="2" style="font-size: 10pt"><span style="font-style: normal"><span style="font-weight: normal">as per </span></span></font></span></font></span>
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><a href="https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#common-message-header">►</a> </span></font></span>
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><font size="2" style="font-size: 10pt"><span style="font-style: normal"><span style="font-weight: normal">set ALWAYS to 0x00 </span></span></font></span></font></span>
-
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><font size="2" style="font-size: 10pt"><span lang="en-GB"><span style="font-style: normal"><span style="font-weight: normal">Command ID</span></span></span></font></span></font></span>
-
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><font size="2" style="font-size: 10pt"><span lang="en-GB"><span style="font-style: normal"><span style="font-weight: normal">here 0x47: Port Input Format (Single) as a reply to a port subscription</span></span></span></font></span></font></span>
-
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><font size="2" style="font-size: 10pt"><span lang="en-GB"><span style="font-style: normal"><span style="font-weight: normal">Port ID</span></span></span></font></span></font></span>
-
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><font size="2" style="font-size: 10pt"><span lang="en-GB"><span style="font-style: normal"><span style="font-weight: normal">here 0x00: Port A </span></span></span></font></span></font></span>
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><font size="2" style="font-size: 10pt"><span lang="en-GB"><span style="font-style: normal"><span style="font-weight: normal">(</span></span></span></font></span></font></span>
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><font size="2" style="font-size: 10pt"><span lang="en-GB"><span style="font-style: normal"><span style="font-weight: normal">see <a href="#Tabelle1|table">#Tabelle1|table</a></span></span></span></font></span></font></span>
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><font size="2" style="font-size: 10pt"><span lang="en-GB"><span style="font-style: normal"><span style="font-weight: normal">)</span></span></span></font></span></font></span>
-
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><font size="2" style="font-size: 10pt"><span style="font-style: normal"><span style="font-weight: normal">Message Type </span></span></font></span></font></span>
-
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><font size="2" style="font-size: 10pt"><span style="font-style: normal"><span style="font-weight: normal">here 0x02: <br/> Hub Action <br/> (see <a href="https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#hub-actions">►</a>)</span></span></font></span></font></span>
-
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><font size="2" style="font-size: 10pt"><span lang="en-GB"><span style="font-style: normal"><span style="font-weight: normal">Message Event</span></span></span></font></span></font></span>
-
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><font size="2" style="font-size: 10pt"><span lang="en-GB"><span style="font-style: normal"><span style="font-weight: normal">here 0x01: Attached I/O, i.e. the port has been connected<br/> (see <a href="https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#io-evt">►</a>) </span></span></span></font></span></font></span>
-
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><font size="2" style="font-size: 10pt"><span lang="en-GB"><span style="font-style: normal"><span style="font-weight: normal">MAYBE</span></span></span></font></span></font></span>
:
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><font size="2" style="font-size: 10pt"><span lang="en-GB"><span style="font-style: normal"><span style="font-weight: normal">IO Type ID</span></span></span></font></span></font></span>
-
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><font size="2" style="font-size: 10pt"><span lang="en-GB"><span style="font-style: normal"><span style="font-weight: normal">here 0x00 0x00<br/> not in doc (see <a href="https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#io-type-id">►</a>)</span></span></span></font></span></font></span>
-
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><font size="2" style="font-size: 10pt"><span lang="en-GB"><span style="font-style: normal"><span style="font-weight: normal">MORE LIKELY: Hardware Revision / Software Revision (not clear, see <a href="https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#ver-no">►</a>)</span></span></span></font></span></font></span>
-
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><font size="2" style="font-size: 10pt"><span style="font-style: normal"><span style="font-weight: normal">MAYBE: Hardware Revision / Software Revision (not clear, see <a href="https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#ver-no">►</a>)</span></span></font></span></font></span>
-
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><font size="2" style="font-size: 10pt"><span style="font-style: normal"><span style="font-weight: normal">MORE LIKELY: IO Type ID</span></span></font></span></font></span>
-
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><font size="2" style="font-size: 10pt"><span style="font-style: normal"><span style="font-weight: normal">here 0x00 0x01: Type is MOTOR, </span></span></font></span></font></span>
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><font face="Liberation Mono, monospace"><font size="2" style="font-size: 10pt"><span style="font-style: normal"><span style="font-weight: normal">needs</span></span></font></font></span></font></span>
<span style="font-variant: normal"><font color="#000000"><span style="text-decoration: none"><font size="2" style="font-size: 10pt"><span style="font-style: normal"><span style="font-weight: normal"> cross-checking with different type of Device, e.g. ColorSensor etc. (see <a href="https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#io-type-id">►</a>)</span></span></font></span></font></span>
-
-
Example 2:
M = 08 00 45 00 d5 02 00
00
parts:
byte pos 0: length of message (e.g. 0×08 = 8,
length 8 bytes)
byte pos 1: HUB ID, should be 0×00 as of
https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#common-message-header
byte
pos 2: Command (e.g. 0×45: Port Value (Single) as a reply to a
port subscription) (see
https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#port-value-single)
byte
pos 3: Port ID (e.g. 0×00: Port A (see 1.1))
byte pos 4 – 7:
Little Endian; Value of the Port (here Port A) : 00 00 02 d5 =
725
meaning of Example M:
the motor at port A (0×00)
stands at 725 degrees, i.e. it has made ≈ 2.014 complete
turns
2. Starting with the command line:
2.1
Finding the Hub ID:
- Input:
sudo hcitool
lescan
-Output, e.g.:
LE Scan …
49:39:A4:17:A4:56
(unknown)
49:39:A4:17:A4:56 (unknown)
17:E9:EA:39:F7:4D
(unknown)
2A:32:FD:01:54:EA (unknown)
90:84:2B:98:CF:1F
(unknown)
90:84:2B:98:CF:1F LEGO Bootloader
90:84:2B:5E:CF:1F
(unknown)
90:84:2B:5E:CF:1F Technic Hub
88:C6:26:EA:FF:16
-Conclusion:
- Technic Hub MAC: 90:84:2B:5E:CF:1F
2.2
Connect with gatttool:
- Input:
gatttool -b
90:84:2B:5E:CF:1F -I
- Output: gatttool
shell
[90:84:2B:5E:CF:1F][LE]>
2.2.1 Commands
in gatttool shell:
2.2.1.1 connect to
HUB:
[90:84:2B:5E:CF:1F][LE]>connect
turn on HUB, by
pressing green button for >= 3s , then release
button
-output:
Attempting to connect to
90:84:2B:5E:CF:1F
Connection successful
2.2.1.2
read characteristics after successful connection:
[90:84:2B:5E:CF:1F][LE]>characteristics
-
output:
handle: 0×0002, char properties: 0×20, char value
handle: 0×0003, uuid: 00002a05-0000-1000-8000-00805f9b34fb
handle:
0×0006, char properties: 0×4e, char value handle: 0×0007, uuid:
00002a00-0000-1000-8000-00805f9b34fb
handle: 0×0008, char
properties: 0×4e, char value handle: 0×0009, uuid:
00002a01-0000-1000-8000-00805f9b34fb
handle: 0×000a, char
properties: 0×02, char value handle: 0×000b, uuid:
00002a04-0000-1000-8000-00805f9b34fb
handle: 0×000d, char
properties: 0×1e, char value handle: 0×000e, uuid:
00001624-1212-efde-1623-785feabcd123
- conclusion:
all
communication is done via
handle: 0×000d, char properties:
0×1e, char value handle: 0×000e, uuid:
00001624-1212-efde-1623-785feabcd123
2.2.1.3 subscribe
to notifications from sensors/ports in
general:
[90:84:2B:5E:CF:1F][LE]>char-write-req 0×0f
0100
- output:
Characteristic value was written
successfully
Notification handle = 0×000e value: 0f 00 04 00
01 2f 00 00 10 00 00 00 10 00 00
Notification handle =
0×000e value: 0f 00 04 01 01 2f 00 00 10 00 00 00 10 00 00
Notification handle = 0×000e value: 0f 00 04 02 01 2e 00 00
10 00 00 00 10 00 00
Notification handle = 0×000e value: 0f
00 04 32 01 17 00 00 00 00 10 00 00 00 10
Notification
handle = 0×000e value: 0f 00 04 3b 01 15 00 00 00 00 10 00 00 00
10
Notification handle = 0×000e value: 0f 00 04 3c 01 14 00
00 00 00 10 00 00 00 10
Notification handle = 0×000e value:
0f 00 04 3d 01 3c 00 00 00 00 10 00 00 00 10
Notification
handle = 0×000e value: 0f 00 04 60 01 3c 00 01 00 00 00 01 00 00
00
Notification handle = 0×000e value: 0f 00 04 61 01 39 00
01 00 00 00 01 00 00 00
Notification handle = 0×000e value:
0f 00 04 62 01 3a 00 01 00 00 00 01 00 00 00
Notification
handle = 0×000e value: 0f 00 04 63 01 3b 00 01 00 00 00 01 00 00
00
Notification handle = 0×000e value: 0f 00 04 64 01 36 00
01 00 00 00 01 00 00 00
2.2.1.4 subscribe to
notifications for a device on port
A:
[90:84:2B:5E:CF:1F][LE]>char-write-cmd 0×0e
0a004100020100000001
- output:
Notification handle =
0×000e value: 0a 00 47 00 02 01 00 00 00 01
Notification
handle = 0×000e value: 08 00 45 00 00 00 00 00
Notification
handle = 0×000e value: 08 00 45 00 ff ff ff ff
Notification
handle = 0×000e value: 08 00 45 00 fe ff ff ff
Notification
handle = 0×000e value: 08 00 45 00 ff ff ff ff
-
findings:
The last 4 Bytes (LITTLE ENDIAN) are the sum of all
degrees turned (degrees in positive direction are added, in
negative direction subtracted) so far with this motor.
In the
above output, the motor started at zero degrees and was manually
turned in negative direction. (Hence, all the ff’s)-———- cleaned findings end here
—————
Übersetzung = 2.67
LENKUNG =
1.00
Antwort: Notification handle = 0×000e value: 08 00
45 00 f7 ee ff ff: letzte 4 Byte = Umdrehungen
Port
B:
Abo: char-write-cmd 0×0e 0a004101020100000001 für
Port B
Antwort: Notification handle = 0×000e value: 08 00 45
01 f7 ee ff ff: letzte 4 Byte = Umdrehungen
Port
C:
Abo: char-write-cmd 0×0e 0a004102020100000001 für
Port C
info about ports:
char-write-cmd 0×0e
0a0041XX020100000001 :XX port no a=0, B01, C02
Move
Motor connected to C:
richtung:
char-write-cmd 0×0e 0c
00 81 02 11 09 00 0a 64 64 7f 03 : hat port C (02)
angesteuert
char-write-cmd 0×0e
0c0081101109000a64647f03
gegenrichtung:
char-write-cmd
0×0e 0c 00 81 02 11 09 00 0a 9c 64 7f 03 : hat port C (02)
angesteuert
Drehe um gradanzahl
C:
richtung:
char-write-cmd 0×0e
0e008102110bb400000005327f03: 150°
char-write-cmd 0×0e
0e008102110b78000000ec647f03 :45° inrichtung, break mit gearNotification:
train
char-write-cmd 0×0e 0e008102110b2d000000ec647f03 :45°
in -richtung, break
char-write-cmd 0×0e
0e008102110b2d000000ec647e03 :45° in -richtung, hold
position
char-write-cmd 0×0e 0e008102110b2d000000ec640003
:45° in -richtung, float position
char-write-cmd 0×0e
0e008102110b2d00000020647e03 :45° in richtung, hold
position
char-write-cmd 0×0e 0e008102110b2d00000064147f03
:45° in +richtung, hold position
Drehe um Gradzahl A: -
vorwärts, + rückwärts
char-write-cmd 0×0e
0e008100110b0000002d14647f03 :45° in +Richtung
char-write-cmd
0×0e 0e008100110b0000000164647f03
char-write-cmd 0×0e
0e008100110b0000000100007f03
char-write-cmd 0×0e
0e008100110b0168000014647f03
char-write-cmd 0×0e
0e008100110b0001000014647f03
char-write-cmd 0×0e
0e008100110b0100000014647f03
char-write-cmd 0×0e
0e008100110b6801000014647f03 :360° in +Richtung
char-write-cmd
0×0e 0e008100110bc003000014647f03 :360° in
+Richtung
char-write-cmd 0×0e
0e008100110bb400000014647f03 :180° in +Richtung
char-write-cmd
0×0e 0e008100110bb4000000ec647f03 :180° in -Richtung
Achtung,
bei drüber-raus-drehen passiert komisches: überlauf
o.Ä.?
Reset Motor / STOP
premature
char-write-cmd 0×0e 0b00810011510200000000 : Motor
A
char-write-cmd 0×0e 0b00810111510200000000 : Motor
B
char-write-cmd 0×0e 0b00810211510200000000 : Motor
C
Ports:
A: 00 vorderräder motor
B: 01
hinterräder motor
C: 02 Lenkung
Virtual
ports:
AB neuer virt. Port ?
config: char-write-cmd
0×0e 06 00 61 01 00 01
connect A B
char-write-Notification
handle = 0×000e value: 09 00 04 10 02 2f 00 00 01
virt. Port
event:Attached virt. I/O Type-ID A B
A+B
gemeinsam
char-write-cmd 0×0e
0c0081101109000a64647f03
Drehung A+B
DATA 09 00 82 00 0c 01 0c 10 01
A ?? B ?? virt.P command in
Progress
Ende Drehung:
DATA 05 00 82 10 0a
vPort
Command Ended
-