title: C/C++ BLE read/write example with Bluez
body: <p>I am starting to build up a simple BLE network with a microcontroller and a raspberry pi (tardis BLE dongle).  As a starting point, I am looking for a simple C or C++ example to read/write a BLE device, similar to what I am able to do over the command line.  The examples I have found so far are quite complicated.  As a BLE beginner I need some very simple examples to build from before moving forward with a more complicated design.  I am okay with hard-coding the BLE device name as I have in the gatttool example below.  </p>
  
  <p>Here is how I currently use the command line options from Bluez.</p>
  
  <p>From the command line I am able to use: </p>
  
  <pre><code>$ sudo hcitool lescan
  LE Scan ...
  BB:A0:50:02:18:07 MyDevice
  </code></pre>
  
  <p>Next I am able to connect to the device on the command line with gatttool:</p>
  
  <pre><code>$ sudo gatttol -b BB:A0:50:02:18:07 -I
  [BB:A0:50:02:18:07][LE]&gt; connect
  Attempting to connect to BB:A0:50:02:18:07
  Connection successful
  </code></pre>
  
  <p>Finally I am able to read and write using the appropriate handles</p>
  
  <pre><code>[BB:A0:50:02:18:07][LE]&gt; char-write-req 000f 0100
  Characteristic value was written successfully
  [BB:A0:50:02:18:07][LE]&gt; char-write-cmd 0011 4C467A
  </code></pre>
  
  <p>Some sites I have used for initial research and to get started: <br><a href="http://people.csail.mit.edu/albert/bluez-intro/c404.html" rel="noreferrer">http://people.csail.mit.edu/albert/bluez-intro/c404.html</a>
  <br><a href="https://github.com/carsonmcdonald/bluez-experiments/blob/master/experiments/scantest.c" rel="noreferrer">https://github.com/carsonmcdonald/bluez-experiments/blob/master/experiments/scantest.c</a></p>