<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>BLE Driver Python Concurrent Notifications</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/8162/ble-driver-python-concurrent-notifications</link><description>Hi Guys, 
 I am currently using the ble driver for windows (Python) to get notifications from two Gatt services (Same Service/charac/descriptors/etc basically same application running on both devices). I think I am getting notifications from both the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 16 Jul 2015 20:14:44 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/8162/ble-driver-python-concurrent-notifications" /><item><title>RE: BLE Driver Python Concurrent Notifications</title><link>https://devzone.nordicsemi.com/thread/29341?ContentTypeID=1</link><pubDate>Thu, 16 Jul 2015 20:14:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b4916d91-0f0d-433e-a141-0a6942f22272</guid><dc:creator>carvalhn</dc:creator><description>&lt;p&gt;Thanks Stian :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Driver Python Concurrent Notifications</title><link>https://devzone.nordicsemi.com/thread/29340?ContentTypeID=1</link><pubDate>Wed, 15 Jul 2015 12:10:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d4102f31-b130-4431-a347-035718080c5f</guid><dc:creator>Stian R&amp;#248;ed Hafskjold</dc:creator><description>&lt;p&gt;###Get connection handle&lt;/p&gt;
&lt;p&gt;To know which handle you get the notifications from you can use &lt;code&gt;ble_event.evt.gap_evt.conn_handle&lt;/code&gt; (documented here: &lt;a href="http://developer.nordicsemi.com/nRF51_SDK/nRF51_SDK_v8.x.x/doc/8.0.0/s120/html/a00124.html)"&gt;developer.nordicsemi.com/.../a00124.html)&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In order to check this quickly you can print the conn_handle inside the &lt;code&gt;ble_evt_handler(ble_event)&lt;/code&gt; function in &lt;strong&gt;main.py&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; elif evt_id == ble_driver.BLE_GATTC_EVT_HVX:
    print &amp;quot;handler&amp;quot;, ble_event.evt.gap_evt.conn_handle
    on_hvx(ble_event.evt.gattc_evt)
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Reset chip&lt;/h3&gt;
&lt;p&gt;The second issue you are facing regarding the script to not be able to re-initiate the scanner after disconnect, is a common issue. I have not found any other solution than to reset the chip using the jlink debugger. I am using linux (JLinkExe) and call this script at the top of &lt;code&gt;main()&lt;/code&gt; in order to reset:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;def reset_device():
    ble_driver.sd_rpc_close()
    cmd = &amp;quot;echo -e &amp;#39;\ndevice nrf51822\nw4 40000544 1\nsi 0\ntck0\nt0\nsleep 10\nt1\nexit\n&amp;#39; | JLinkExe&amp;quot;
    import subprocess
    pcmd = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=&amp;#39;/bin/sh&amp;#39;)
    pcmd.wait()
    pout = pcmd.communicate()
    print pout[0]
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Write to characteristic&lt;/h3&gt;
&lt;p&gt;If you want to write to a characteristic (assuming that you have implemented a write characteristic in the HRM service), you first need to capture the descriptor handle of that characteristic and store it to a global variable, then initiate a write request to that handle.&lt;/p&gt;
&lt;p&gt;In the &lt;code&gt;on_descriptor_discovery_response()&lt;/code&gt; function you can add:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    global hrm_write_handle
    ....
        if descriptor.uuid.uuid == YOUR_WRITE_CHAR_UUID
            hrm_write_handle = descriptor.handle
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now you will have the handle stored in &lt;code&gt;hrm_write_handle&lt;/code&gt;, and this function will execute a write on that characteristic:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;def do_write(value):
    if hrm_write_handle == 0:
        print &amp;quot;Error. No LED handle has been found&amp;quot;
        return

    led_value = [value]
    led_array = util.list_to_uint8_array(led_value)

    write_params = ble_driver.ble_gattc_write_params_t()
    write_params.handle = hrm_write_handle
    write_params.len = 1
    write_params.p_value = led_array.cast()
    write_params.write_op = ble_driver.BLE_GATT_OP_WRITE_REQ
    write_params.offset = 0

    ble_driver.sd_ble_gattc_write(connection_handle, write_params)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can of course pass the &lt;code&gt;connection_handle&lt;/code&gt; variable to this function as well to choose which peripheral you want to send the write to. You can call this function from &lt;code&gt;on_hvx()&lt;/code&gt; to test.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;sd_ble_gattc_write&lt;/code&gt; is documented here: &lt;a href="http://developer.nordicsemi.com/nRF51_SDK/nRF51_SDK_v8.x.x/doc/8.0.0/s120/html/a00710.html#ga90298b8dcd8bbe7bbe69d362d1133378"&gt;developer.nordicsemi.com/.../a00710.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And the sequence diagram for that function is here: &lt;a href="http://developer.nordicsemi.com/nRF51_SDK/nRF51_SDK_v8.x.x/doc/8.0.0/s120/html/a00607.html"&gt;developer.nordicsemi.com/.../a00607.html&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>