{"id":16513,"date":"2017-01-27T10:25:03","date_gmt":"2017-01-27T16:25:03","guid":{"rendered":"http:\/\/www.multitech.net\/developer\/?page_id=16513"},"modified":"2022-05-03T12:42:57","modified_gmt":"2022-05-03T17:42:57","slug":"bluetooth-low-energy","status":"publish","type":"page","link":"https:\/\/www.multitech.net\/developer\/software\/mlinux\/using-mlinux\/bluetooth-low-energy\/","title":{"rendered":"Bluetooth Low Energy"},"content":{"rendered":"<p>This feature is only available on certain products and models (not available with all devices).<\/p>\n<p><b>Introduction<\/b><\/p>\n<p>Bluetooth Low Energy (BLE) requires GATT software and a BLE peripheral device(such as a sensor broadcasting temperature data) in order to work. The BLE peripheral device should provide services, and then update them as required. The gatttool or libaries may be used to read and write to the BLE peripheral.\u00a0This requires some prior setup and coding in order to operate.<\/p>\n<p>The example here uses the Texas Instruments Sensortag CC2650, a connectivity kit for IoT sensors to connect to the internet via BLE. (see photo below). Refer to the <a href=\"http:\/\/www.ti.com\/ww\/en\/wireless_connectivity\/sensortag2015\/tearDown.html\">Texas Instruments website<\/a>. Go to the bottom of the page for a list of sensors and services. Click on the plus symbol to see the details of each sensor and its handles. The handles are used to control and read the sensor.<\/p>\n<p>You must develop a custom application to read and accept the data from an IoT device.\u00a0 This code includes the hooks or handles. Your specific approach including desired programming language and related software for this process varies widely based on your application, hardware and software systems.\u00a0 See <a href=\"https:\/\/www.multitech.net\/developer\/software\/mlinux\/mlinux-software-development\/\">Application Development<\/a> for more information.<\/p>\n<p>For mLinux<sup>\u2122<\/sup>, one option is to write a C\/C++ application and use the BlueZ driver already provided on the device.\u00a0 Other options include writing a Python application and using the <b>python gattlib<\/b> library.<\/p>\n<p><strong>NOTE:<\/strong>\u00a0For mLinux 3.x only, BLE does not work with <strong>Bluez 5<\/strong> on a PC in<strong> compatibility mode<\/strong>. \u00a0You must use <strong>Bluez 4<\/strong>.<\/p>\n<p><b>BLE Setup and Start<\/b><\/p>\n<p style=\"padding-left: 30px;\">1. Make sure the RS9113 is started with a BLE compatible mode of: <b>8, 9, 12, or 14<\/b>. For this example, the choice is <b>14<\/b>. If you reboot the system, verify that \/etc\/default\/rs9113 still contains the correct value. <strong>NOTE<\/strong>: Once a WiFi connection is established, you cannot scan. Push the black plastic flap as seen here:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"https:\/\/www.multitech.net\/developer\/wp-content\/uploads\/2017\/01\/cc2650-sensor-w-labels.jpg\" width=\"696\" height=\"658\" \/><\/p>\n<p><i>Photo of the Texas Instruments Sensortag CC2650 used in this BLE example.<\/i><\/p>\n<p><strong>For mLinux 4.x or higher<\/strong>, after step 1, follow these steps:<\/p>\n<p style=\"padding-left: 30px;\">2.Edit <strong>\/etc\/default\/bluetoothd<\/strong> and set B<strong>LUETOOTH_ENABLED=1<\/strong><\/p>\n<p style=\"padding-left: 30px;\">3.Start the bluetooth daemon:<\/p>\n<pre class=\"brush:shell\">sudo \/etc\/init.d\/bluetooth start<\/pre>\n<p style=\"padding-left: 30px;\">To stop the bluetooth daemon (don&#8217;t do this if you wish to proceed on testing this):<\/p>\n<pre class=\"brush:shell\">sudo \/etc\/init.d\/bluetooth stop<\/pre>\n<p style=\"padding-left: 30px;\">4.\u00a0Now use <strong>bluetoothctl<\/strong> to find the BLE device.<\/p>\n<pre class=\"brush:shell\">sudo bluetoothctl\r\n[bluetooth]# power on\r\nChanging power on succeeded\r\n[bluetooth]# scan on\r\nDiscovery started\r\n[CHG] Controller 00:23:A7:EA:2E:D3 Discovering: yes<\/pre>\n<p style=\"padding-left: 30px;\">If the BLE device is advertising, you should soon see:<\/p>\n<pre class=\"brush:shell\">[NEW] Device B0:B4:48:C0:B0:82 CC2650 SensorTag<\/pre>\n<p><strong>For mLinux 3.x<\/strong>, after step 1, follow these steps:<\/p>\n<p style=\"padding-left: 30px;\">2. Put the BLE device in discoverable mode. The green led starts to blink.<br \/>\n3. Enter the following commands:<\/p>\n<pre class=\"brush:shell\">mtcdt: hciconfig hci0 up\r\nmtcdt: hcitool -i hci0 lescan<\/pre>\n<p style=\"padding-left: 30px;\">\u00a0 \u00a0 The resulting output displays:<\/p>\n<pre class=\"brush:shell\">#LE Scan ...\r\nB0:B4:48:C0:B0:82 (unknown)\r\nB0:B4:48:C0:B0:82 CC2650 SensorTag\r\n^C<\/pre>\n<p style=\"padding-left: 30px;\">4. Type &lt;Ctrl-C&gt; to end the scan.<\/p>\n<p style=\"padding-left: 30px;\"><b>Bring BLE up<\/b><\/p>\n<p style=\"padding-left: 30px;\">To bring BLE up, enter the following command:<\/p>\n<pre class=\"brush:shell\">mtcdt: hciconfig hci0 up<\/pre>\n<p style=\"padding-left: 30px;\"><b>Bring BLE down<br \/>\n<\/b><br \/>\nTo bring BLE down, enter the following command:<\/p>\n<pre class=\"brush:shell\">mtcdt: hciconfig hci0 down<\/pre>\n<p style=\"padding-left: 30px;\"><b>BLE Reset<\/b><\/p>\n<p style=\"padding-left: 30px;\">BLE resets automatically upon reboot.<\/p>\n<p><b>Connect to the Sensor<\/b><\/p>\n<p>Now you that you know the address of the BLE device (See <b>BLE Setup and Start<\/b>), you can connect.<\/p>\n<p style=\"padding-left: 30px;\">1. To connect to the sensor, enter the following commands:<\/p>\n<p><span style=\"font-family: 'andale mono', times;\">\u00a0<\/span><\/p>\n<pre class=\"brush:shell\">mtcdt: gatttool -i hci0\u00a0 -b B0:B4:48:C0:B0:82 --interactive\r\n[ \u00a0 \u00a0 \u00a0 \u00a0 ][B0:B4:48:C0:B0:82][LE]&gt; connect<\/pre>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\">2. Once you connect, the blinking led stops. Enter the following command:<span style=\"font-family: 'andale mono', times;\">\u00a0<\/span><\/p>\n<pre class=\"brush:shell\">[CON][B0:B4:48:C0:B0:82][LE]&gt; primary<\/pre>\n<p style=\"padding-left: 30px;\">\u00a0The resulting output displays:<span style=\"font-family: 'andale mono', times;\">\u00a0<\/span><\/p>\n<pre class=\"brush:shell\">[CON][B0:B4:48:C0:B0:82][LE]&gt;\r\nattr handle: 0x0001, end grp handle: 0x0007 uuid: 00001800-0000-1000-8000-00805f9b34fb\r\nattr handle: 0x0008, end grp handle: 0x000b uuid: 00001801-0000-1000-8000-00805f9b34fb\r\nattr handle: 0x000c, end grp handle: 0x001e uuid: 0000180a-0000-1000-8000-00805f9b34fb\r\nattr handle: 0x001f, end grp handle: 0x0026 uuid: f000aa00-0451-4000-b000-000000000000\r\nattr handle: 0x0027, end grp handle: 0x002e uuid: f000aa20-0451-4000-b000-000000000000\r\nattr handle: 0x002f, end grp handle: 0x0036 uuid: f000aa40-0451-4000-b000-000000000000\r\nattr handle: 0x0037, end grp handle: 0x003e uuid: f000aa80-0451-4000-b000-000000000000\r\nattr handle: 0x003f, end grp handle: 0x0046 uuid: f000aa70-0451-4000-b000-000000000000\r\nattr handle: 0x0047, end grp handle: 0x004b uuid: 0000ffe0-0000-1000-8000-00805f9b34fb\r\nattr handle: 0x004c, end grp handle: 0x0050 uuid: f000aa64-0451-4000-b000-000000000000\r\nattr handle: 0x0051, end grp handle: 0x0058 uuid: f000ac00-0451-4000-b000-000000000000\r\nattr handle: 0x0059, end grp handle: 0x0060 uuid: f000ccc0-0451-4000-b000-000000000000\r\nattr handle: 0x0061, end grp handle: 0xffff uuid: f000ffc0-0451-4000-b000-000000000000<\/pre>\n<p style=\"padding-left: 30px;\">3. To get a list of details of characteristics, use the <strong>char-desc<\/strong> command. When using this command , it displays the handle they are at and their UUID:\u00a0\u00a0<span style=\"font-family: 'andale mono', times;\">\u00a0<\/span><\/p>\n<pre class=\"brush:shell\">[CON][B0:B4:48:C0:B0:82][LE]&gt; char-desc<\/pre>\n<p style=\"padding-left: 60px;\">The resulting output displays:<\/p>\n<pre class=\"brush:shell\">[CON][B0:B4:48:C0:B0:82][LE]&gt;\r\nhandle: 0x0001, uuid: 00002800-0000-1000-8000-00805f9b34fb\r\nhandle: 0x0002, uuid: 00002803-0000-1000-8000-00805f9b34fb\r\nhandle: 0x0003, uuid: 00002a00-0000-1000-8000-00805f9b34fb\r\nhandle: 0x0004, uuid: 00002803-0000-1000-8000-00805f9b34fb\r\nhandle: 0x0005, uuid: 00002a01-0000-1000-8000-00805f9b34fb\r\n\r\n...\r\n\r\nhandle: 0x002f, uuid: f000aa22-0451-4000-b000-000000000000\r\n...<\/pre>\n<p style=\"padding-left: 30px;\">4. To read the characteristics that are located at certain handle(s), enter the following command:<\/p>\n<p><span style=\"font-family: 'andale mono', times;\">\u00a0<\/span><\/p>\n<pre class=\"brush:shell\">[CON][B0:B4:48:C0:B0:82][LE]&gt; char-read-hnd 0x0001\r\n[CON][B0:B4:48:C0:B0:82][LE]&gt;\r\nCharacteristic value\/descriptor: 00 18\r\n[CON][B0:B4:48:C0:B0:82][LE]&gt; char-read-hnd 0x0002\r\n[CON][B0:B4:48:C0:B0:82][LE]&gt;\r\nCharacteristic value\/descriptor: 02 03 00 00 2a<\/pre>\n<p style=\"padding-left: 30px;\">5. You can also write characteristics that are located at certain handle(s): The first write command wakes up (activates) the humidity sensor on 01. The second write command puts the sensor to sleep on 00. The read commands is to simply confirm that the change happened.<\/p>\n<p><span style=\"font-family: 'andale mono', times;\">\u00a0<\/span><\/p>\n<pre class=\"brush:shell\">[CON][B0:B4:48:C0:B0:82][LE]&gt; char-write-cmd 0x2f 01\r\n[CON][B0:B4:48:C0:B0:82][LE]&gt; char-read-hnd 0x2f\r\n[CON][B0:B4:48:C0:B0:82][LE]&gt;\r\nCharacteristic value\/descriptor: 01\r\n[CON][B0:B4:48:C0:B0:82][LE]&gt; char-write-cmd 0x2f 00\r\n[CON][B0:B4:48:C0:B0:82][LE]&gt; char-read-hnd 0x2f\r\n[CON][B0:B4:48:C0:B0:82][LE]&gt;\r\nCharacteristic value\/descriptor: 00\r\n[CON][B0:B4:48:C0:B0:82][LE]&gt;<\/pre>\n<p style=\"padding-left: 30px;\">6. Enter the following commands to disconnect and exit. The green LED on the sensor starts blinking again:<\/p>\n<p><span style=\"font-family: 'andale mono', times;\">\u00a0<\/span><\/p>\n<pre class=\"brush:shell\">[CON][B0:B4:48:C0:B0:82][LE]&gt; disconnect\r\n[\u00a0\u00a0 ][B0:B4:48:C0:B0:82][LE]&gt; exit\r\nmtcdt:<\/pre>\n<p style=\"padding-left: 30px;\">7. To save energy, turn off the sensor and the green light stops blinking.<\/p>\n<h3><b><br \/>\nUse the device as a server (not yet supported in mLinux 4.x)<\/b><\/h3>\n<p><strong>For mLinux 5.x<br \/>\n<\/strong><\/p>\n<h4 style=\"padding-left: 30px;\">Example GATT Server<\/h4>\n<p style=\"padding-left: 30px;\">This example only applies to mLinux 5.<\/p>\n<p style=\"padding-left: 30px;\">GATT servers are typically sensors that transmit data to clients using Bluetooth Low Energy.\u00a0 In mLinux 5, it is possible to write a GATT service that sends data collected by the device to a remote GATT client. There are many standard GATT services defined.\u00a0 Here is a list:\u00a0 <a href=\"https:\/\/www.bluetooth.com\/specifications\/gatt\/services\">https:\/\/www.bluetooth.com\/specifications\/gatt\/services<\/a><\/p>\n<p style=\"padding-left: 30px;\">The sample server is only provided as a learning tool to demonstrate how to write a GATT server. Most GATT servers will need to read real sensors, most likely attached to the device.<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/github.com\/Jumperr-labs\/python-gatt-server\">https:\/\/github.com\/Jumperr-labs\/python-gatt-server<\/a><\/p>\n<h4 style=\"padding-left: 30px;\">Prerequisites for the GATT Sample Server<\/h4>\n<p style=\"padding-left: 30px;\">You will need to acquire the python GATT server example from multitech.net.\u00a0 You will need a PC with a GATT client and Bluetooth capability.\u00a0 An alternative to a PC would be a 2<sup>nd<\/sup> Multitech device running mLinux that has Bluetooth capability, and the GATTTool installed.<\/p>\n<p style=\"padding-left: 30px;\">An example of a GATT client for Linux is GATTTool.\u00a0 Another example is the Microsoft Bluetooth LE Explorer.<\/p>\n<p style=\"padding-left: 30px;\">In Gnu-Linux, GATTTool is packaged with BlueZ .This example uses GATTTool from BlueZ.<\/p>\n<h3 style=\"padding-left: 30px;\">Acquiring the python GATT Server Example for the device<\/h3>\n<p style=\"padding-left: 30px;\">The Example GATT server does not come with mLinux by default.\u00a0 The package for the GATT server is found in <a href=\"http:\/\/multitech.net\/mlinux\/feeds\/5.0.0\/all\/\">http:\/\/multitech.net\/mlinux\/feeds\/5.0.0\/all\/<\/a> and the name begins with python-gatt-server.<\/p>\n<p style=\"padding-left: 30px;\">\u00a0The easiest way to install it is using the opkg command, if your device is on the internet, and can connect to multitech.net.\u00a0 Otherwise, download the file python-gatt-server_*.ipk from multitech.net and from there copy it to the device and install it.<\/p>\n<pre class=\"brush:shell\" style=\"padding-left: 30px;\">mtcdt:~$ sudo opkg update\r\nPassword:\r\nDownloading http:\/\/multitech.net\/mlinux\/feeds\/5.0.0\/all\/Packages.gz.\r\nUpdated source 'mlinux-all'.\r\nDownloading http:\/\/multitech.net\/mlinux\/feeds\/5.0.0\/arm926ejste\/Packages.gz.\r\nUpdated source 'mlinux-arm926ejste'.\r\nDownloading http:\/\/multitech.net\/mlinux\/feeds\/5.0.0\/mtcdt\/Packages.gz.\r\nUpdated source 'mlinux-mtcdt'.\r\nmtcdt:~$ sudo opkg install python-gatt-server\r\nInstalling python-gatt-server (1.0) on root.\r\nDownloading http:\/\/multitech.net\/mlinux\/feeds\/5.0.0\/all\/python-gatt-server_1.0-r0.0_all.ipk.\r\nConfiguring useradd.\r\nPATH=${PATH}:\/sbin:\/usr\/sbin\r\nConfiguring python-gatt-server.\r\nmtcdt:~$ opkg files python-gatt-server\r\nPackage python-gatt-server (1.0-r0.0) is installed on root and has the following files:\r\n\/usr\/libexec\/bluetooth\/python-gatt-server\/gatt_server.py\r\n\/usr\/libexec\/bluetooth\/python-gatt-server\/gatt_server_example.py\r\n\/usr\/libexec\/bluetooth\/python-gatt-server\/exceptions.py\r\n\/usr\/libexec\/bluetooth\/python-gatt-server\/advertising.py\r\n\/usr\/libexec\/bluetooth\/python-gatt-server\/adapters.py\r\n\/usr\/libexec\/bluetooth\/python-gatt-server\/<\/pre>\n<h3 style=\"padding-left: 30px;\">Configuring Bluetooth on the device<\/h3>\n<p style=\"padding-left: 30px;\">Because we are using shell commands to write to files that are privileged, we will use a root shell:<\/p>\n<pre class=\"brush:shell\" style=\"padding-left: 30px;\">mtcdt:~$ sudo -s<\/pre>\n<p style=\"padding-left: 30px;\">In \/etc\/default\/bluetooth add the following line of text:<\/p>\n<pre class=\"brush:shell\" style=\"padding-left: 30px;\">mtcdt:$ echo 'MOREOPTIONS=\"--experimental\"' &gt;&gt;\/etc\/default\/Bluetooth<\/pre>\n<p style=\"padding-left: 30px;\">And make sure bluetooth is enabled:<\/p>\n<pre class=\"brush:shell\" style=\"padding-left: 30px;\">mtcdt:~$ sed -i \"s\/BLUETOOTH_ENABLED=0\/BLUETOOTH_ENABLED=1\/\" \/etc\/default\/bluetooth<\/pre>\n<p style=\"padding-left: 30px;\">Set the RS9113 Coexistence mode to a mode that supports BLE.\u00a0 These are 8,9,12, and 14.<\/p>\n<p style=\"padding-left: 30px;\">For this example, I will pick 8.<\/p>\n<pre class=\"brush:shell\" style=\"padding-left: 30px;\">mtcdt:~$ sed -i 's\/^COEX_MODE=.*\/COEX_MODE=8\/' \/etc\/default\/rs9113\r\nmtcdt:~$ \/etc\/init.d\/rs9113 restart<\/pre>\n<h3 style=\"padding-left: 30px;\">Determining the device&#8217;s BT address<\/h3>\n<p style=\"padding-left: 30px;\">We must know the device&#8217;s\u00a0BT Address to reach it from the PC.<\/p>\n<p style=\"padding-left: 30px;\">Log into the device, and as root do the following:<\/p>\n<p style=\"padding-left: 30px;\">1. Start BT:<\/p>\n<pre class=\"brush:shell\" style=\"padding-left: 30px;\">mtcdt:~$ \/etc\/init.d\/bluetooth start\r\nStarting bluetooth\r\nbluetoothd<\/pre>\n<p style=\"padding-left: 30px;\">2. Find the BT device:<\/p>\n<pre class=\"brush:shell\" style=\"padding-left: 30px;\">mtcdt:~$ bluetoothctl\r\nAgent registered<\/pre>\n<p class=\"brush:shell\" style=\"padding-left: 30px;\">3. Enter show command to display device BT address:<\/p>\n<pre class=\"brush:shell\" style=\"padding-left: 30px;\">mtcdt:~$ show\r\nController 00:23:A7:49:43:C1 (public)\r\n\u00a0 \u00a0 \u00a0 \u00a0 Name: MTCDT-Bluez\r\n\u00a0 \u00a0 \u00a0 \u00a0 Alias: MTCDT-Bluez\r\n\u00a0 \u00a0 \u00a0 \u00a0 Class: 0x00000000\r\n\u00a0 \u00a0 \u00a0 \u00a0 Powered: yes\r\n\u00a0 \u00a0 \u00a0 \u00a0 Discoverable: yes\r\n\u00a0 \u00a0 \u00a0 \u00a0 DiscoverableTimeout: 0x00000000|\r\n\u00a0 \u00a0 \u00a0 \u00a0 Pairable: yes\r\n\u00a0 \u00a0 \u00a0 \u00a0 UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)\r\n\u00a0 \u00a0 \u00a0 \u00a0 UUID: A\/V Remote Control\u00a0 \u00a0 \u00a0 \u00a0 (0000110e-0000-1000-8000-00805f9b34fb)\r\n\u00a0 \u00a0 \u00a0 \u00a0 UUID: PnP Information\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0(00001200-0000-1000-8000-00805f9b34fb)\r\n\u00a0 \u00a0 \u00a0 \u00a0 UUID: A\/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)\r\n\u00a0 \u00a0 \u00a0 \u00a0 UUID: Generic Access Profile\u00a0 \u00a0 (00001800-0000-1000-8000-00805f9b34fb)\r\n\u00a0 \u00a0 \u00a0 \u00a0 Modalias: usb:v1D6Bp0246d0532\r\n\u00a0 \u00a0 \u00a0 \u00a0 Discovering: no\r\nmtcdt:~$\u00a0quit<\/pre>\n<p style=\"padding-left: 30px;\">The BT ADDR is:<span style=\"color: black; font-family: Calibri, sans-serif; font-size: 12pt;\">\u00a000:23:A7:49:43:C1<\/span><\/p>\n<h3 style=\"padding-left: 30px;\">Starting the Python GATT Server<\/h3>\n<p style=\"padding-left: 30px;\">On the device switch to the GATT server example directory:<\/p>\n<pre class=\"brush:shell\" style=\"padding-left: 30px;\">mtcdt:$ cd \/usr\/libexec\/bluetooth\/python-gatt-server\/<\/pre>\n<p style=\"padding-left: 30px;\">If you restart the python-GATT-server, you must first restart bluetooth.<\/p>\n<p style=\"padding-left: 30px;\">Start the bluetooth server, and the python GATT server on the device:<\/p>\n<pre class=\"brush:shell\" style=\"padding-left: 30px;\">mtcdt:$ sudo \/etc\/init.d\/bluetooth restart\r\nmtcdt:$ sudo .\/gatt_server_example.py<\/pre>\n<p style=\"padding-left: 30px;\">On the device, you will now see output from the simulated battery function of the server, printing the battery status starting at 100, and counting down to zero.<\/p>\n<h3 style=\"padding-left: 30px;\">Connecting to the Device from a PC Using BLE and using GATTTool<\/h3>\n<p style=\"padding-left: 30px;\">The fake battery level test is at UUID 2a19.\u00a0 The GATTtool <i>char-desc<\/i> command should find the file handle for this feature:<\/p>\n<pre class=\"brush:shell\" style=\"padding-left: 30px;\">PC:~$ sudo gatttool -i hci0 -b 00:23:A7:49:43:C1 --interactive\r\n[00:23:A7:49:43:C1][LE]&gt; connect\r\nAttempting to connect to 00:23:A7:49:43:C1\r\nConnection successful\r\n[00:23:A7:49:43:C1][LE]&gt; char-desc\r\n\u2026\r\nhandle: 0x0016, uuid: 12345678-1234-5678-1234-56789abcdef1\r\n...\r\n\r\nhandle: 0x0024, uuid: 00002a19-0000-1000-8000-00805f9b34fb\r\n...\r\n[00:23:A7:49:43:C1][LE]&gt; char-read-hnd 0x24\r\nCharacteristic value\/descriptor: 50\r\n[00:23:A7:49:43:C1][LE]&gt; char-read-hnd 0x24\r\nCharacteristic value\/descriptor: 4c\r\n[00:23:A7:49:43:C1][LE]&gt;<\/pre>\n<p style=\"padding-left: 30px;\">On the device you will see:<\/p>\n<pre class=\"brush:shell\" style=\"padding-left: 30px;\">...Battery level: 84\r\nBattery level: 82\r\nBattery level: 80\r\nBattery level read: 80\r\nBattery level: 78\r\nBattery level: 76\r\nBattery level read: 76\r\nBattery level: 74\r\nBattery level: 72\r\nBattery level: 70\r\n\u2026<\/pre>\n<p class=\"brush:shell\" style=\"padding-left: 30px;\">Note that 80 is 0x50, and 76 is the same as 0x4C.<\/p>\n<p style=\"padding-left: 30px;\">There is a feature of the test server which allows writing a value, and reading it back. This is the dummy test characteristic, and it has UUID 12345678-1234-5678-1234-56789abcdef1. Likewise, char-desc command should find this UUID.\u00a0 It appears in the listing above, and in our case, the handle is 0x0016.<\/p>\n<p style=\"padding-left: 30px;\">The following commands are executed in GATTtool on the PC:<\/p>\n<pre class=\"brush:shell\" style=\"padding-left: 30px;\">[00:23:A7:49:43:C1][LE]&gt; char-write-cmd 0x16 'a87b'\r\n[00:23:A7:49:43:C1][LE]&gt; char-read-hnd 0x16\r\nCharacteristic value\/descriptor: a8 7b\r\n[00:23:A7:49:43:C1][LE]&gt; char-write-cmd 0x16 'fab4'\r\n[00:23:A7:49:43:C1][LE]&gt; char-read-hnd 0x16\r\nCharacteristic value\/descriptor: fa b4\r\n[00:23:A7:49:43:C1][LE]&gt;<\/pre>\n<p style=\"padding-left: 30px;\">These reads and writes will be noted in the output of the test server on the device:<\/p>\n<pre class=\"brush:shell\" style=\"padding-left: 30px;\">Battery level: 0\r\nTestCharacteristic Write: dbus.Array([dbus.Byte(168), dbus.Byte(123)], signature=dbus.Signature('y'))\r\nBattery level: 0\r\nBattery level: 0\r\nTestCharacteristic Read: dbus.Array([dbus.Byte(168), dbus.Byte(123)], signature=dbus.Signature('y'))\r\nBattery level: 0\r\nBattery level: 0\r\nTestCharacteristic Write: dbus.Array([dbus.Byte(250), dbus.Byte(180)], signature=dbus.Signature('y'))\r\nBattery level: 0\r\nTestCharacteristic Read: dbus.Array([dbus.Byte(250), dbus.Byte(180)], signature=dbus.Signature('y'))\r\nBattery level: 0\r\nBattery level: 0<\/pre>\n<p style=\"padding-left: 30px;\">The fake battery eventually goes to zero.<\/p>\n<pre class=\"brush:shell\" style=\"padding-left: 30px;\">[00:23:A7:49:43:C1][LE]&gt; char-read-hnd 0x24\r\nCharacteristic value\/descriptor: 00<\/pre>\n<h3 style=\"padding-left: 30px;\">Terminating the Python GATT Server<\/h3>\n<p style=\"padding-left: 30px;\">To terminate the python-GATT-server, enter &lt;ctrl-C&gt; on the device.\u00a0 Remember to restart the bluetooth daemon after you do this.<\/p>\n<h3 style=\"padding-left: 30px;\">Finding the UUIDs in GATT Server Code<\/h3>\n<p style=\"padding-left: 30px;\">The uuid values and their associated code can be found on the device after installing the pyton-GATT-server in this location on the device. \u00a0For example to find the Battery UUIDs:<\/p>\n<pre class=\"brush:shell\" style=\"padding-left: 30px;\">mtadm:$ cd \/usr\/libexec\/bluetooth\/python-gatt-server\/\r\nmtadm:$ grep BATTERY gatt_server.py\r\nBATTERY_UUID = '180f'\r\nService.__init__(self, bus, index, self.BATTERY_UUID, True)\r\nBATTERY_LVL_UUID = '2a19'\r\nself.BATTERY_LVL_UUID,<\/pre>\n<p style=\"padding-left: 30px;\">The UUIDs may be used to further inspect or write to the GATT server.<\/p>\n<p><strong>If you wish to use another Conduit, mLinux 3 provides GATTTool in the bluez4 package, and mLinux 4 and mLinux 5 provides GATTTool in the bluez5-noinst-tools package.\u00a0 The GATTTool is normally installed by default on the device.<\/strong><\/p>\n<p><strong>For mLinux 3.x<\/strong><\/p>\n<p>You can use the device as a server and send data to your computer.<\/p>\n<p>Note: These instructions were tested on Ubuntu 14.04 and do not work in Ubuntu 16.04.<\/p>\n<p>To use the device as a server:<\/p>\n<p style=\"padding-left: 30px;\">1. Set the COEX_ MODE of 8\u00a0 for the rs9113 module (8 changes bluetooth config to a peripheral (slave) mode) in \/etc\/default\/rs9113:<\/p>\n<p><span style=\"font-family: 'andale mono', times;\">\u00a0<\/span><\/p>\n<pre class=\"brush:shell\">$\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 8\u00a0\u00a0\u00a0 \u00a0 BT LE MODE \/BT \u00a0 LE \u00a0 PER \u00a0 MODE\r\nCOEX_MODE=8<\/pre>\n<p style=\"padding-left: 30px;\">2. Configure bluetoothd for GATT by entering this command:<\/p>\n<p><span style=\"font-family: 'andale mono', times;\">\u00a0<\/span><\/p>\n<pre class=\"brush:shell\">mtcdt: grep -in gatt \/etc\/bluetooth\/main.conf\r\n63:$ Enable the GATT functionality. Default is false\r\n64: EnableGatt = true<\/pre>\n<p style=\"padding-left: 30px;\">3. To tell the rs9113 module to advertise the device as a BLE device (setup advertising and discovery), enter the following command:<\/p>\n<p style=\"padding-left: 30px;\"><b>Note:<\/b> leadv can only be used on the device in this test. If <i>hcitool hci0 leadv<\/i> is ever run on the PC, the Bluetooth dongle must be removed before gatttool can be run. Otherwise gatttool connect will always fail.<\/p>\n<p><span style=\"font-family: 'andale mono', times;\">\u00a0<\/span><\/p>\n<pre class=\"brush:shell\">mtcdt: hciconfig hci0 up\r\nmtcdt: hciconfig hci0 noleadv\r\nmtcdt: hcitool -i hci0 cmd 0x08 0x0008 10 02 01 1a 0c ff 18 01 48 45 4c 4c 4f 57 4f 52 4c 44\r\nmtcdt: hciconfig hci0 leadv<\/pre>\n<p style=\"padding-left: 30px;\">4. Check the status by entering this command:<\/p>\n<p><span style=\"font-family: 'andale mono', times;\">\u00a0<\/span><\/p>\n<pre class=\"brush:shell\">mtcdt: hciconfig<\/pre>\n<p style=\"padding-left: 30px;\">The resulting output displays:<\/p>\n<p><span style=\"font-family: 'andale mono', times;\">\u00a0<\/span><\/p>\n<pre class=\"brush:shell\">hci0:\u00a0 Type: BR\/EDR\u00a0 Bus: USB\r\nBD Address: 00:23:A7:49:5C:D9\u00a0 ACL MTU: 27:10\u00a0 SCO MTU: 0:0\r\nUP RUNNING\r\nRX bytes:462 acl:0 sco:0 events:38 errors:0\r\nTX bytes:0 acl:0 sco:0 commands:38 errors:0<\/pre>\n<p style=\"padding-left: 30px;\">5. To find the device, log onto a PC with Linux and BLE and enter the scan command:<\/p>\n<p><span style=\"font-family: 'andale mono', times;\">\u00a0<\/span><\/p>\n<pre class=\"brush:shell\">pc: sudo hcitool -i hci0 lescan<\/pre>\n<p style=\"padding-left: 60px;\">\u00a0The resulting output displays:<\/p>\n<p><span style=\"font-family: 'andale mono', times;\">\u00a0<\/span><\/p>\n<pre class=\"brush:shell\">LE Scan ...\r\n00:23:A7:49:5C:D9 (unknown)\r\n00:23:A7:49:5C:D9 SimpleBLEPeripheral<\/pre>\n<p style=\"padding-left: 60px;\">\u00a0The MAC addresses highlighted in bold from the hciconfig output and the hcitool lescan output should match.<\/p>\n<p><b>Bring up bluetoothd on the device<\/b><\/p>\n<p>The files you need for this procedure are created by building the BlueZ 4 package.<\/p>\n<p style=\"padding-left: 30px;\">1.\u00a0Download the package bluez4-plugins_*.ipk onto the device from <a href=\"http:\/\/www.multitech.net\/mlinux\/feeds\/3.3.7\/arm926ejste\/\">http:\/\/www.multitech.net\/mlinux\/feeds\/3.3.7\/arm926ejste\/<br \/>\n<\/a><br \/>\n2.\u00a0 Install the plugins:<br \/>\nopkg install bluez4-plugins_*.ipk<\/p>\n<p style=\"padding-left: 30px;\">3. To start the bluetoothd daemon, enter the following command:<span style=\"font-family: 'andale mono', times;\">\u00a0<\/span><\/p>\n<pre class=\"brush:shell\">mtcdt: bluetoothd -n -d<\/pre>\n<p style=\"padding-left: 30px;\">A large of amount of data displays as output. Look for this specific line to confirm that gatt server started.<\/p>\n<p><span style=\"font-family: 'andale mono', times;\">\u00a0<\/span>&#8230;<\/p>\n<pre class=\"brush:shell\">bluetoothd[5564]: src\/attrib-server.c:btd_adapter_gatt_server_start() Start GATT server in hci0\r\n...<\/pre>\n<p style=\"padding-left: 30px;\">4. This step requires BlueZ 4 already installed. Refer to Bluetooth page for instructions. Log into gatttool on your computer and connect to the device by entering the following commands:<\/p>\n<p><span style=\"font-family: 'andale mono', times;\">\u00a0<\/span><\/p>\n<pre class=\"brush:shell\">mtcdt: gatttool -i hci0 -b 00:23:A7:49:5C:D9 --interactive\r\n[\u00a0\u00a0 ][00:23:A7:49:5C:D9][LE]&gt; connect\r\n[CON][00:23:A7:49:5C:D9][LE]&gt; primary<\/pre>\n<p style=\"padding-left: 60px;\">The following results display:<\/p>\n<p><span style=\"font-family: 'andale mono', times;\">\u00a0<\/span><\/p>\n<pre class=\"brush:shell\">attr handle: 0x0001, end grp handle: 0x0008 uuid: 00001800-0000-1000-8000-00805f9b34fb\r\nattr handle: 0x0010, end grp handle: 0x0010 uuid: 00001801-0000-1000-8000-00805f9b34fb\r\n[CON][00:23:A7:49:5C:D9][LE]&gt; characteristics 0x0001 0x0008\r\n[CON][00:23:A7:49:5C:D9][LE]&gt;\r\nhandle: 0x0004, char properties: 0x02, char value handle: 0x0006, uuid: 00002a00-0000-1000-8000-00805f9b34fb\r\nhandle: 0x0007, char properties: 0x02, char value handle: 0x0008, uuid: 00002a01-0000-1000-8000-00805f9b34fb\r\n[CON][00:23:A7:49:5C:D9][LE]&gt; characteristics 0x0010 0x0010\r\n[CON][00:23:A7:49:5C:D9][LE]&gt;\r\n[CON][00:23:A7:49:5C:D9][LE]&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"font-size: 12.0pt; font-family: 'Calibri',sans-serif; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; color: black; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;\">with 00:23:A7:49:43:C1<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This feature is only available on certain products and models (not available with all devices). Introduction Bluetooth Low Energy (BLE) requires GATT software and a BLE peripheral device(such as a sensor broadcasting temperature data) in order to work. The BLE peripheral device should provide services, and then update them as required. The gatttool or libaries [&hellip;]<\/p>\n","protected":false},"author":1478,"featured_media":0,"parent":9184,"menu_order":9,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"class_list":["post-16513","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/16513","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/users\/1478"}],"replies":[{"embeddable":true,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/comments?post=16513"}],"version-history":[{"count":75,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/16513\/revisions"}],"predecessor-version":[{"id":16568,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/16513\/revisions\/16568"}],"up":[{"embeddable":true,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/9184"}],"wp:attachment":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/media?parent=16513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}