{"id":789,"date":"2021-11-14T10:34:41","date_gmt":"2021-11-14T09:34:41","guid":{"rendered":"https:\/\/macchina.io\/blog\/?p=789"},"modified":"2024-04-26T07:43:59","modified_gmt":"2024-04-26T05:43:59","slug":"communication-with-low-energy-bluetooth-devices-on-linux","status":"publish","type":"post","link":"https:\/\/macchina.io\/blog\/internet-of-things\/communication-with-low-energy-bluetooth-devices-on-linux\/","title":{"rendered":"Communication with Bluetooth Low-Energy Devices on Linux"},"content":{"rendered":"<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/bluetooth-IoT-edge-environment.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"707\" src=\"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/bluetooth-IoT-edge-environment.png\" alt=\"macchina.io bluetooth connection for edge devices\" class=\"wp-image-819\" srcset=\"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/bluetooth-IoT-edge-environment.png 1000w, https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/bluetooth-IoT-edge-environment-300x212.png 300w, https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/bluetooth-IoT-edge-environment-768x543.png 768w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/a><\/figure>\n<h2 class=\"wp-block-heading\">What is Bluetooth and Bluetooth Low Energy?<\/h2>\n<p>Bluetooth\u2122\ufe0f is a wireless technology used to build Personal Area Networks (PAN) or piconets. Since it\u2019s original development by Ericsson in 1989, it has grown in popularity to the point where today it has become a standard feature in many segments of the consumer electronic market.<\/p>\n<p>The use of Bluetooth in industrial IoT is also growing, mostly due to Bluetooth LE, a newer variant of Bluetooth optimized for minimum power usage, as is required for wireless, battery-powered sensor devices. <\/p>\n<p>This blog post takes you through the important details of the Bluetooth LE technology from the perspective of an IoT developer. It is based on the presentation at the Internet of Things conference \u201cFrom the sensor to the cloud\u201d 2021, by our Founder &amp; Chief Technologist G\u00fcnter Obiltschnig.<\/p>\n<h2 class=\"wp-block-heading\">A few facts about Bluetooth<\/h2>\n<p>Development of Bluetooth technology was originally initiated by Nils Rydbeck (Ericsson) in 1989. The first use case was not until ten years later, and was released at Comdex in 1999 as the first hands-free mobile headset. It won the &#8220;Best of show Technology Award&#8221;. This first product had a range of 10 meters but nowadays, that range can go up to 100m with Bluetooth 5.0.<\/p>\n<p>Bluetooth uses the globally unlicensed ISM (industrial, scientific, medical) radio bands from 2402 to 2480 GHz. One of the major advantages of Bluetooth is that it does not rely on a wireless network infrastructure.<\/p>\n<p>The Bluetooth standards are developed and maintained by the <a href=\"https:\/\/bluetooth.com\" target=\"_blank\" rel=\"noopener\">Bluetooth Special Interest Group.<\/a><\/p>\n<div class=\"wp-block-image\">\n<figure class=\"alignright size-full is-resized\"><a href=\"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/bluetooth-name.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"250\" height=\"250\" src=\"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/bluetooth-name.jpg\" alt=\"Harald Bl\u00e5tand, kalkmaleri fra 1500-tallet i Roskilde Domkirke, Sj\u00e6lland, Danmark (public domain)\" class=\"wp-image-805\" style=\"width:96px;height:96px\" srcset=\"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/bluetooth-name.jpg 250w, https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/bluetooth-name-150x150.jpg 150w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\">Why \u201cBluetooth\u201d?<\/h2>\n<p>The name Bluetooth is an anglicized version of the Scandinavian Bl\u00e5tand\/Bl\u00e5tann, the epithet of the tenth-century king Harald Bluetooth who united dissonant Danish tribes into a single kingdom. The implication is that Bluetooth unites communication protocols in the same way king Bluetooth united tribes.<\/p>\n<h2 class=\"wp-block-heading\">Bluetooth Low Energy (LE)<\/h2>\n<p>Bluetooth LE (formerly also known as Bluetooth Smart) was introduced with the Bluetooth 4.0 specification in 2010. It is intended to reduce power consumption and cost while maintaining a similar communication range. The actual connection times are reduced to a few milliseconds; significantly less than Bluetooth, which has connection times ranging from a few seconds up to a few hours.<\/p>\n<p>Bluetooth LE can co-exist with Bluetooth on the same controller, however, the Bluetooth LE protocol stack is different from classic Bluetooth. It uses the same 2.4 GHz radio bands as Bluetooth, but a different communication protocol and different channels with 2 MHz bandwidth.&nbsp;<\/p>\n<p>Bluetooth LE is targeted at devices with very low-power requirements, such as fitness and health sensors (heart rate monitors, thermometers, blood pressure, etc) as well as fitness trackers, battery-powered environmental and industrial sensors, beacons, etc.<\/p>\n<p>Bluetooth LE uses a unique 48-bit address per device (MAC address). Similar to Ethernet MAC addresses, the first part of the address is the &#8220;vendor prefix&#8221;, which allows to deduct the vendor of a Bluetooth device (or at least its chipset) from its address.<\/p>\n<h2 class=\"wp-block-heading\">Bluetooth LE Radio<\/h2>\n<p>Bluetooth LE uses 40 channels with 2 MHz bandwidth. Within each channel, Gaussian Frequency Shift Keying (GFSK) is used, similar to classic Bluetooth 1.0. The bitrate is 1 Mbit\/sec, with an option for 2 Mbit\/sec in Bluetooth 5.0.<\/p>\n<p>Bluetooth LE uses frequency hopping like \u201cclassic\u201d Bluetooth, but in a different variant (direct sequence spread spectrum).<\/p>\n<h2 class=\"wp-block-heading\">Bluetooth LE Protocol Stack<\/h2>\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/blue-tooth-Protocol-stack.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"467\" src=\"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/blue-tooth-Protocol-stack.png\" alt=\"Bluetooth Protocol Stack\" class=\"wp-image-810\" srcset=\"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/blue-tooth-Protocol-stack.png 1000w, https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/blue-tooth-Protocol-stack-300x140.png 300w, https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/blue-tooth-Protocol-stack-768x359.png 768w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/a><\/figure>\n<h3 class=\"wp-block-heading\">GAP &#8211; Generic Access Profile<\/h3>\n<p>Bluetooth LE devices use the Generic Access Profile for device discovery and advertisement.<\/p>\n<p>GAP distinguishes between devices based on their roles. Central devices are typically a computer or smartphone. Peripheral devices are often small, low-power and resource-constrained devices like sensors.<\/p>\n<p>In order to discover peripheral devices, a central device sends out a broadcast message (scan response request). Upon receiving the scan response request, the peripheral device will respond with advertising data. This includes device name and address, and other data. Advertising data can also include small amounts of custom data. This is used by Bluetooth LE beacons (e.g., iBeacon).<\/p>\n<p>Both peripheral and central devices can assume one or both of the other GAP roles, which are Broadcaster and Observer. A very typical example would be a sensor in broadcast mode sending data to a central device in observer mode.<\/p>\n<h3 class=\"wp-block-heading\">GATT &#8211; Generic Attribute Profile<\/h3>\n<p>GATT defines the following concepts, which are often reflected in Bluetooth LE APIs.<\/p>\n<p><b>Client:<\/b> typically a computer or smartphone that sends GATT commands and requests and receives responses from servers. Also referred to as central device.<\/p>\n<p><b>Server: <\/b>a device (e.g., a sensor) that receives commands and requests and returns responses. Also referred to as peripheral device.<\/p>\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/Bluetooth-attribute-profile-diagram.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"315\" src=\"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/Bluetooth-attribute-profile-diagram.png\" alt=\"Bluetooth generic attribute profile\" class=\"wp-image-811\" srcset=\"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/Bluetooth-attribute-profile-diagram.png 1000w, https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/Bluetooth-attribute-profile-diagram-300x95.png 300w, https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/Bluetooth-attribute-profile-diagram-768x242.png 768w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/a><\/figure>\n<p><strong>Characteristic:<\/strong> a data value transferred between client and server. Consists of multiple <strong>attributes<\/strong> containing the actual value, as well as configuration options and meta data.<\/p>\n<p>Different data types are supported, but on protocol level an attribute value is always a sequence of bytes. Characteristics and their attributes are used for reporting sensor values (e.g., temperature) and also for configuring devices (e.g., setting sample rate on an accelerometer). The maximum length is 512 bytes. Numeric values are usually stored in little-endian format.<\/p>\n<p><strong>Service:<\/strong> a collection of related characteristics, which operate together, e.g. the sensor value and configuration parameters.<\/p>\n<p><strong>Descriptor:<\/strong> provides additional information about a characteristic&#8217;s attribute, e.g. physical unit or minimum and maximum values.<\/p>\n<p><strong>Identifier:<\/strong> services, characteristics and descriptors are attributes identified by UUIDs. The 128-bit UUIDs are mapped to device-specific 16-bit values (handles) for use in the protocol. Bluetooth reserves UUIDs in range xxxxxxxx-0000-1000-8000-00805F9B34FB for standard attributes, which are transmitted as 16-bit or 32-bit values in the protocol.<\/p>\n<h3 class=\"wp-block-heading\">GATT Operations<\/h3>\n<p>GATT comes into play once a connection is made between two devices. For data to be delivered and received, some or all of the following operations can be executed.<\/p>\n<ul class=\"wp-block-list\">\n<li>discover UUIDs for primary services<\/li>\n<li>find a service with a given UUID<\/li>\n<li>find secondary services for a given primary service<\/li>\n<li>discover all characteristics for a given service<\/li>\n<li>find characteristics matching a given UUID<\/li>\n<li>read descriptors for a particular characteristic<\/li>\n<li>read the value of a characteristic (a sequence of bytes)<\/li>\n<li>write the value of a characteristic (a sequence of bytes)<\/li>\n<li>request notifications and indications.<\/li>\n<\/ul>\n<p>Servers can send notifications and indications to clients on certain state changes (e.g., the sensor value has changed); indications must be acknowledged by the client.<\/p>\n<h2 class=\"wp-block-heading\">Bluetooth LE Profiles<\/h2>\n<p>Like classic Bluetooth, Bluetooth LE defines a number of profiles. All Bluetooth LE profiles are based on GATT, therefore, a Bluetooth LE profile defines the services and characteristics (and their IDs) that a device must support.<\/p>\n<p>Examples:<\/p>\n<ul class=\"wp-block-list\">\n<li>BLP &#8211; Blood Pressure Profile<\/li>\n<li>HTP &#8211; Health Thermometer Profile<\/li>\n<li>GLP &#8211; Glucose Profile<\/li>\n<li>HRP &#8211; Heart Rate Profile<\/li>\n<li>CPP &#8211; Cycling Power Profile<\/li>\n<li>WSP &#8211; Weight Scale Profile<\/li>\n<li>LNP &#8211; Location and Navigation Profile<\/li>\n<li>ESP &#8211; Environmental Sensing Profile<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\">BlueZ \u2013 Bluetooth &amp; Bluetooth LE on Linux<\/h2>\n<p>BlueZ is the official Linux Bluetooth protocol stack. It was originally developed by Max Krasnyansky at Qualcomm (starting in 2001), and is available for Linux kernels 2.4.6 and newer. Currently the main developers are Marcel Holtmann and Johan Hedberg, currently at Intel.<\/p>\n<p>BlueZ is listed as a qualified protocol stack on the Bluetooth Qualification website, which&nbsp;simplifies the product qualification process. It consists of kernel modules and user space libraries and is included in all major Linux distributions. BlueZ has a low-level C API and a high-level D-Bus API.<\/p>\n<p>BlueZ is licensed under the GPL, but is (apparently) in the process of being moved to LGPL.<\/p>\n<h2 class=\"wp-block-heading\">bluepy<\/h2>\n<p><a rel=\"noopener\" href=\"https:\/\/github.com\/IanHarvey\/bluepy\" target=\"_blank\">bluepy<\/a>&nbsp;by Ian Harvey is a Python interface to Bluetooth LE on Linux. bluepy consists of a Python module and an executable (<em>bluepy-helper<\/em>) written in C. The <em>bluepy-helper<\/em> executable wraps the BlueZ C API in a command-line interface.<\/p>\n<p>The output of <em>bluepy-helper<\/em> commands is easily parseable by programs. The bluepy python module starts <em>bluepy-helper<\/em> and sends command via a pipe. It can also be used interactively, which is great for making the first steps with a Bluetooth LE peripheral.<\/p>\n<p><em>bluepy-helper<\/em> is licensed under the GPL, like the BlueZ libraries it uses (derived work), however programs launching <em>bluepy-helper<\/em> and talking to it via a pipe need not be under GPL.<\/p>\n<h2 class=\"wp-block-heading\">Getting Started (Debian\/Ubuntu\/Raspberry Pi OS)<\/h2>\n<h3 class=\"wp-block-heading\">Install Dependencies<\/h3>\n<pre class=\"wp-block-preformatted\"><code>$ <strong>sudo apt-get update &amp;&amp; \\\nsudo apt-get install bluetooth build-essential libglib2.0-dev \\\nlibdbus-1-dev<\/strong><\/code><\/pre>\n<h3 class=\"wp-block-heading\">Get and Build bluepy-helper<\/h3>\n<pre class=\"wp-block-preformatted\"><code>$ <strong>git clone https:\/\/github.com\/IanHarvey\/bluepy.git<\/strong>\n$ <strong>cd bluepy\/bluepy<\/strong>\n$ <strong>make<\/strong><\/code><\/pre>\n<h3 class=\"wp-block-heading\">Enable Bluetooth<\/h3>\n<pre class=\"wp-block-preformatted\"><code>$ <strong>sudo hciconfig hci0 up<\/strong><\/code><\/pre>\n<h3 class=\"wp-block-heading\">Search for Bluetooth LE devices (address and name)<\/h3>\n<pre class=\"wp-block-preformatted\"><code>$ <strong>sudo hcitool lescan<\/strong>\n64:BB:12:3B:05:3E (unknown)\n79:77:B8:8C:E3:F7 (unknown)\n58:2D:34:35:D7:1D (unknown)\n58:2D:34:35:D7:1D MJ_HT_V1\n3B:85:C4:72:1A:29 (unknown)\n3B:85:C4:72:1A:29 (unknown)\n27:05:78:F6:C9:F3 (unknown)\n80:6F:B0:F0:0D:81 Multi-Sensor\n80:6F:B0:F0:0D:81 (unknown)<\/code><\/pre>\n<h2 class=\"wp-block-heading\">Interacting with Bluetooth LE Devices<\/h2>\n<p>Interacting with Bluetooth LE devices typically comprises the following operations:<\/p>\n<ul class=\"wp-block-list\">\n<li>Detecting supported services and characteristics<\/li>\n<li>Writing characteristics to configure device<\/li>\n<li>Reading characteristics to read sensor and other data<\/li>\n<li>Handling notifications and indications<\/li>\n<\/ul>\n<p>We can perform these steps with bluepy-helper<\/p>\n<h2 class=\"wp-block-heading\">Using bluepy-helper<\/h2>\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/bluepy-helper-bluetooth-connectivity-iot.gif\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"450\" src=\"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/bluepy-helper-bluetooth-connectivity-iot.gif\" alt=\"\" class=\"wp-image-795\"\/><\/a><\/figure>\n<h3 class=\"wp-block-heading\"><strong>Start bluepy-helper<\/strong><\/h3>\n<pre class=\"wp-block-preformatted\"><code>$ <strong>.\/bluepy-helper<\/strong>\n# bluepy-helper.c version 1.3.0 built at 10:10:50 on Oct 20 2021\n<\/code><\/pre>\n<p><strong>Connect to a Device<\/strong><\/p>\n<pre class=\"wp-block-preformatted\"><code><strong>conn 58:2D:34:35:D7:1D<\/strong>\nrsp=$stat\u25ab\ufe0estate=$tryconn\u25ab\ufe0edst='58:2D:34:35:D7:1D\u25ab\ufe0emtu=h0\u25ab\ufe0esec='low\nrsp=$stat\u25ab\ufe0estate=$conn\u25ab\ufe0edst='58:2D:34:35:D7:1D\u25ab\ufe0emtu=h0\u25ab\ufe0esec='low<\/code><\/pre>\n<h3 class=\"wp-block-heading\"><strong>Discover Services Offered by Device<\/strong><\/h3>\n<pre class=\"wp-block-preformatted\"><code><strong>svcs<\/strong>\nrsp=$find\u25ab\ufe0ehstart=h1\u25ab\ufe0ehend=h7\u25ab\ufe0euuid='00001800-0000-1000-8000-00805f9b34fb\u25ab\ufe0e\nhstart=h8\u25ab\ufe0ehend=hB\u25ab\ufe0euuid='00001801-0000-1000-8000-00805f9b34fb\u25ab\ufe0e\nhstart=hC\u25ab\ufe0ehend=h15\u25ab\ufe0euuid='226c0000-6476-4566-7562-66734470666d\u25ab\ufe0e\nhstart=h16\u25ab\ufe0ehend=h19\u25ab\ufe0euuid='0000180f-0000-1000-8000-00805f9b34fb\u25ab\ufe0e\nhstart=h1A\u25ab\ufe0ehend=h24\u25ab\ufe0euuid='0000180a-0000-1000-8000-00805f9b34fb\u25ab\ufe0e\nhstart=h25\u25ab\ufe0ehend=h2C\u25ab\ufe0euuid='00001530-1212-efde-1523-785feabcd123\u25ab\ufe0e\nhstart=h2D\u25ab\ufe0ehend=hFFFF\u25ab\ufe0euuid='0000fe95-0000-1000-8000-00805f9b34fb<\/code><\/pre>\n<h3 class=\"wp-block-heading\"><strong>Examining a Service (Battery)<\/strong><\/h3>\n<pre class=\"wp-block-preformatted\"><code>hstart=h16\u25ab\ufe0ehend=h19\u25ab\ufe0euuid='0000180f-0000-1000-8000-00805f9b34fb\u25ab\ufe0e\n\n<strong>char 16 19<\/strong>\nrsp=$find\u25ab\ufe0e\nhnd=h17\u25ab\ufe0eprops=h12\u25ab\ufe0evhnd=h18\u25ab\ufe0euuid='00002a19-0000-1000-8000-00805f9b34fb<\/code><\/pre>\n<h3 class=\"wp-block-heading\"><strong>Reading the Battery<\/strong> Level<\/h3>\n<pre class=\"wp-block-preformatted\"><strong>rd 18<\/strong>\nrsp=$rd\u25ab\ufe0ed=b38<\/pre>\n<p>The returned hexadecimal value 38 is decimal 56, which means 56 % battery level.<\/p>\n<h3 class=\"wp-block-heading\"><strong>Examining another service (Device Information)<\/strong><\/h3>\n<pre class=\"wp-block-preformatted\"><code>hstart=h1A\u25ab\ufe0ehend=h24\u25ab\ufe0euuid='0000180a-0000-1000-8000-00805f9b34fb\n\n<strong>char 1A 24<\/strong>\nrsp=$find\u25ab\ufe0e\nhnd=h1B\u25ab\ufe0eprops=h2\u25ab\ufe0evhnd=h1C\u25ab\ufe0euuid='00002a29-0000-1000-8000-00805f9b34fb\u25ab\ufe0e\nhnd=h1D\u25ab\ufe0eprops=h2\u25ab\ufe0evhnd=h1E\u25ab\ufe0euuid='00002a24-0000-1000-8000-00805f9b34fb\u25ab\ufe0e\nhnd=h1F\u25ab\ufe0eprops=h2\u25ab\ufe0evhnd=h20\u25ab\ufe0euuid='00002a25-0000-1000-8000-00805f9b34fb\u25ab\ufe0e\nhnd=h21\u25ab\ufe0eprops=h2\u25ab\ufe0evhnd=h22\u25ab\ufe0euuid='00002a27-0000-1000-8000-00805f9b34fb\u25ab\ufe0e\nhnd=h23\u25ab\ufe0eprops=h2\u25ab\ufe0evhnd=h24\u25ab\ufe0euuid='00002a26-0000-1000-8000-00805f9b34fb<\/code><\/pre>\n<h3 class=\"wp-block-heading\"><strong>Read Model Number String<\/strong><\/h3>\n<pre class=\"wp-block-preformatted\"><code><strong>rd 1E<\/strong>\nrsp=$rd\u25ab\ufe0ed=b4475636B5F52656C65617365<\/code><\/pre>\n<p>The hexadecimal string <meta charset=\"utf-8\"><code>4475636B5F52656C65617365<\/code> translates to &#8220;Duck_Release&#8221;, which actually does not make much sense, but it is what the specific device (a Xiaomi Mijia temperature and humidity sensor).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"700\" class=\"wp-image-829\" style=\"width: 200px; height: 200px;\" src=\"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/1600x1600_.png\" alt=\"Xiaomi Mijia Temperature and Humidity Sensor\" srcset=\"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/1600x1600_.png 700w, https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/1600x1600_-300x300.png 300w, https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/1600x1600_-150x150.png 150w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/p>\n<h2 class=\"wp-block-heading\">Creating a High-Level Bluetooth LE API<\/h2>\n<p>We can now implement a high-level Bluetooth LE API for a programming language of our<br \/>choice on top of <em>bluepy-helper<\/em>. We only need to be able to start a process and communicate with it via a pipe.<\/p>\n<p>For macchina.io EDGE, we have created a C++ API that can also be used from JavaScript.<\/p>\n<p>You can find the <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/macchina-io\/macchina.io\/blob\/develop\/protocols\/BtLE\/include\/IoT\/BtLE\/Peripheral.h\" target=\"_blank\">interface definition<\/a> and <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/macchina-io\/macchina.io\/tree\/develop\/protocols\/BtLE\/BlueZ\" target=\"_blank\">implementation<\/a> in the macchina.io EDGE (open source) <a href=\"https:\/\/github.com\/macchina-io\/macchina.io\" target=\"_blank\" rel=\"noreferrer noopener\">repository<\/a> on GitHub.<\/p>\n<h2 class=\"wp-block-heading\">Implementation<\/h2>\n<p>The implementation roughly does the following:<\/p>\n<ul class=\"wp-block-list\">\n<li>Connect: start a new <em>bluepy-helper<\/em> helper process for the peripheral.<\/li>\n<li>Disconnect<strong>:<\/strong> kill helper process.<\/li>\n<li>For every operation, send the respective command to <em>bluepy-helper<\/em> and parse the result.<\/li>\n<li>Handle indications and notifications.<\/li>\n<li>Perform some state-keeping.<\/li>\n<\/ul>\n<p>In addition to the generic Peripheral interface, macchina.io EDGE also has high-level support for a few specific Bluetooth LE devices, such as a TI SensorTag or a Bosch XDK.<\/p>\n<p>In a future article, we will show how to use the macchina.io EDGE Bluetooth support to connect to a specific device and communicate with the device using a few lines of JavaScript.<\/p>\n<div class=\"wp-block-buttons is-horizontal is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-499968f5 wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button is-style-fill\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/macchina.io\/remote\">Try macchina.io REMOTE for FREE<\/a><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>What is Bluetooth and Bluetooth Low Energy? Bluetooth\u2122\ufe0f is a wireless technology used to build Personal Area Networks (PAN) or piconets. Since it\u2019s original development by Ericsson in 1989, it has grown in popularity to the point where today it has become a standard feature in many segments of the consumer electronic market. The use [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":798,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","_eb_attr":"","footnotes":""},"categories":[41,3,159,37],"tags":[],"class_list":["post-789","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-edge-computing","category-internet-of-things","category-iot-platforms","category-macchina-io"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Communication with Bluetooth Low-Energy Devices on Linux - macchina.io Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/macchina.io\/blog\/internet-of-things\/communication-with-low-energy-bluetooth-devices-on-linux\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Communication with Bluetooth Low-Energy Devices on Linux - macchina.io Blog\" \/>\n<meta property=\"og:description\" content=\"What is Bluetooth and Bluetooth Low Energy? Bluetooth\u2122\ufe0f is a wireless technology used to build Personal Area Networks (PAN) or piconets. Since it\u2019s original development by Ericsson in 1989, it has grown in popularity to the point where today it has become a standard feature in many segments of the consumer electronic market. The use [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/macchina.io\/blog\/internet-of-things\/communication-with-low-energy-bluetooth-devices-on-linux\/\" \/>\n<meta property=\"og:site_name\" content=\"macchina.io Blog\" \/>\n<meta property=\"article:published_time\" content=\"2021-11-14T09:34:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-26T05:43:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/Bluetooth-connectivity.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"596\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Tristan Boyd\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@macchina_io\" \/>\n<meta name=\"twitter:site\" content=\"@macchina_io\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Tristan Boyd\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/macchina.io\\\/blog\\\/internet-of-things\\\/communication-with-low-energy-bluetooth-devices-on-linux\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/macchina.io\\\/blog\\\/internet-of-things\\\/communication-with-low-energy-bluetooth-devices-on-linux\\\/\"},\"author\":{\"name\":\"Tristan Boyd\",\"@id\":\"https:\\\/\\\/macchina.io\\\/blog\\\/#\\\/schema\\\/person\\\/64d07999dd11520723b5482ab38798b7\"},\"headline\":\"Communication with Bluetooth Low-Energy Devices on Linux\",\"datePublished\":\"2021-11-14T09:34:41+00:00\",\"dateModified\":\"2024-04-26T05:43:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/macchina.io\\\/blog\\\/internet-of-things\\\/communication-with-low-energy-bluetooth-devices-on-linux\\\/\"},\"wordCount\":1662,\"publisher\":{\"@id\":\"https:\\\/\\\/macchina.io\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/macchina.io\\\/blog\\\/internet-of-things\\\/communication-with-low-energy-bluetooth-devices-on-linux\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/macchina.io\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/11\\\/Bluetooth-connectivity.png\",\"articleSection\":[\"Edge Computing\",\"Internet of Things\",\"IoT Platforms\",\"macchina.io\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/macchina.io\\\/blog\\\/internet-of-things\\\/communication-with-low-energy-bluetooth-devices-on-linux\\\/\",\"url\":\"https:\\\/\\\/macchina.io\\\/blog\\\/internet-of-things\\\/communication-with-low-energy-bluetooth-devices-on-linux\\\/\",\"name\":\"Communication with Bluetooth Low-Energy Devices on Linux - macchina.io Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/macchina.io\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/macchina.io\\\/blog\\\/internet-of-things\\\/communication-with-low-energy-bluetooth-devices-on-linux\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/macchina.io\\\/blog\\\/internet-of-things\\\/communication-with-low-energy-bluetooth-devices-on-linux\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/macchina.io\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/11\\\/Bluetooth-connectivity.png\",\"datePublished\":\"2021-11-14T09:34:41+00:00\",\"dateModified\":\"2024-04-26T05:43:59+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/macchina.io\\\/blog\\\/internet-of-things\\\/communication-with-low-energy-bluetooth-devices-on-linux\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/macchina.io\\\/blog\\\/internet-of-things\\\/communication-with-low-energy-bluetooth-devices-on-linux\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/macchina.io\\\/blog\\\/internet-of-things\\\/communication-with-low-energy-bluetooth-devices-on-linux\\\/#primaryimage\",\"url\":\"https:\\\/\\\/macchina.io\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/11\\\/Bluetooth-connectivity.png\",\"contentUrl\":\"https:\\\/\\\/macchina.io\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/11\\\/Bluetooth-connectivity.png\",\"width\":1200,\"height\":596,\"caption\":\"Why are so many IoT developers connecting with Bluetooth?\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/macchina.io\\\/blog\\\/internet-of-things\\\/communication-with-low-energy-bluetooth-devices-on-linux\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/macchina.io\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Communication with Bluetooth Low-Energy Devices on Linux\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/macchina.io\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/macchina.io\\\/blog\\\/\",\"name\":\"macchina.io Blog\",\"description\":\"Internet of Things, edge computing, IoT device software, C++\",\"publisher\":{\"@id\":\"https:\\\/\\\/macchina.io\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/macchina.io\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/macchina.io\\\/blog\\\/#organization\",\"name\":\"macchina.io\",\"url\":\"https:\\\/\\\/macchina.io\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/macchina.io\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/macchina.io\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/macchina.io_emp_logo.png\",\"contentUrl\":\"https:\\\/\\\/macchina.io\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/macchina.io_emp_logo.png\",\"width\":1537,\"height\":529,\"caption\":\"macchina.io\"},\"image\":{\"@id\":\"https:\\\/\\\/macchina.io\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/macchina_io\",\"https:\\\/\\\/www.linkedin.com\\\/showcase\\\/37869369\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/macchina.io\\\/blog\\\/#\\\/schema\\\/person\\\/64d07999dd11520723b5482ab38798b7\",\"name\":\"Tristan Boyd\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Communication with Bluetooth Low-Energy Devices on Linux - macchina.io Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/macchina.io\/blog\/internet-of-things\/communication-with-low-energy-bluetooth-devices-on-linux\/","og_locale":"en_US","og_type":"article","og_title":"Communication with Bluetooth Low-Energy Devices on Linux - macchina.io Blog","og_description":"What is Bluetooth and Bluetooth Low Energy? Bluetooth\u2122\ufe0f is a wireless technology used to build Personal Area Networks (PAN) or piconets. Since it\u2019s original development by Ericsson in 1989, it has grown in popularity to the point where today it has become a standard feature in many segments of the consumer electronic market. The use [&hellip;]","og_url":"https:\/\/macchina.io\/blog\/internet-of-things\/communication-with-low-energy-bluetooth-devices-on-linux\/","og_site_name":"macchina.io Blog","article_published_time":"2021-11-14T09:34:41+00:00","article_modified_time":"2024-04-26T05:43:59+00:00","og_image":[{"width":1200,"height":596,"url":"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/Bluetooth-connectivity.png","type":"image\/png"}],"author":"Tristan Boyd","twitter_card":"summary_large_image","twitter_creator":"@macchina_io","twitter_site":"@macchina_io","twitter_misc":{"Written by":"Tristan Boyd","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/macchina.io\/blog\/internet-of-things\/communication-with-low-energy-bluetooth-devices-on-linux\/#article","isPartOf":{"@id":"https:\/\/macchina.io\/blog\/internet-of-things\/communication-with-low-energy-bluetooth-devices-on-linux\/"},"author":{"name":"Tristan Boyd","@id":"https:\/\/macchina.io\/blog\/#\/schema\/person\/64d07999dd11520723b5482ab38798b7"},"headline":"Communication with Bluetooth Low-Energy Devices on Linux","datePublished":"2021-11-14T09:34:41+00:00","dateModified":"2024-04-26T05:43:59+00:00","mainEntityOfPage":{"@id":"https:\/\/macchina.io\/blog\/internet-of-things\/communication-with-low-energy-bluetooth-devices-on-linux\/"},"wordCount":1662,"publisher":{"@id":"https:\/\/macchina.io\/blog\/#organization"},"image":{"@id":"https:\/\/macchina.io\/blog\/internet-of-things\/communication-with-low-energy-bluetooth-devices-on-linux\/#primaryimage"},"thumbnailUrl":"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/Bluetooth-connectivity.png","articleSection":["Edge Computing","Internet of Things","IoT Platforms","macchina.io"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/macchina.io\/blog\/internet-of-things\/communication-with-low-energy-bluetooth-devices-on-linux\/","url":"https:\/\/macchina.io\/blog\/internet-of-things\/communication-with-low-energy-bluetooth-devices-on-linux\/","name":"Communication with Bluetooth Low-Energy Devices on Linux - macchina.io Blog","isPartOf":{"@id":"https:\/\/macchina.io\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/macchina.io\/blog\/internet-of-things\/communication-with-low-energy-bluetooth-devices-on-linux\/#primaryimage"},"image":{"@id":"https:\/\/macchina.io\/blog\/internet-of-things\/communication-with-low-energy-bluetooth-devices-on-linux\/#primaryimage"},"thumbnailUrl":"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/Bluetooth-connectivity.png","datePublished":"2021-11-14T09:34:41+00:00","dateModified":"2024-04-26T05:43:59+00:00","breadcrumb":{"@id":"https:\/\/macchina.io\/blog\/internet-of-things\/communication-with-low-energy-bluetooth-devices-on-linux\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/macchina.io\/blog\/internet-of-things\/communication-with-low-energy-bluetooth-devices-on-linux\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/macchina.io\/blog\/internet-of-things\/communication-with-low-energy-bluetooth-devices-on-linux\/#primaryimage","url":"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/Bluetooth-connectivity.png","contentUrl":"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2021\/11\/Bluetooth-connectivity.png","width":1200,"height":596,"caption":"Why are so many IoT developers connecting with Bluetooth?"},{"@type":"BreadcrumbList","@id":"https:\/\/macchina.io\/blog\/internet-of-things\/communication-with-low-energy-bluetooth-devices-on-linux\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/macchina.io\/blog\/"},{"@type":"ListItem","position":2,"name":"Communication with Bluetooth Low-Energy Devices on Linux"}]},{"@type":"WebSite","@id":"https:\/\/macchina.io\/blog\/#website","url":"https:\/\/macchina.io\/blog\/","name":"macchina.io Blog","description":"Internet of Things, edge computing, IoT device software, C++","publisher":{"@id":"https:\/\/macchina.io\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/macchina.io\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/macchina.io\/blog\/#organization","name":"macchina.io","url":"https:\/\/macchina.io\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/macchina.io\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2018\/08\/macchina.io_emp_logo.png","contentUrl":"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2018\/08\/macchina.io_emp_logo.png","width":1537,"height":529,"caption":"macchina.io"},"image":{"@id":"https:\/\/macchina.io\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/macchina_io","https:\/\/www.linkedin.com\/showcase\/37869369"]},{"@type":"Person","@id":"https:\/\/macchina.io\/blog\/#\/schema\/person\/64d07999dd11520723b5482ab38798b7","name":"Tristan Boyd"}]}},"_links":{"self":[{"href":"https:\/\/macchina.io\/blog\/wp-json\/wp\/v2\/posts\/789","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/macchina.io\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/macchina.io\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/macchina.io\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/macchina.io\/blog\/wp-json\/wp\/v2\/comments?post=789"}],"version-history":[{"count":29,"href":"https:\/\/macchina.io\/blog\/wp-json\/wp\/v2\/posts\/789\/revisions"}],"predecessor-version":[{"id":1285,"href":"https:\/\/macchina.io\/blog\/wp-json\/wp\/v2\/posts\/789\/revisions\/1285"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/macchina.io\/blog\/wp-json\/wp\/v2\/media\/798"}],"wp:attachment":[{"href":"https:\/\/macchina.io\/blog\/wp-json\/wp\/v2\/media?parent=789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/macchina.io\/blog\/wp-json\/wp\/v2\/categories?post=789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/macchina.io\/blog\/wp-json\/wp\/v2\/tags?post=789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}