<?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>Handling 128-bit UUIDs with Python pc_ble_driver</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/91308/handling-128-bit-uuids-with-python-pc_ble_driver</link><description>Hi, 
 I&amp;#180;m developing a BLE-OTA driver for a BLE SoC and I try to use the nRF52840 dongle with my PC as the second device for the OTA mechanism by using Python and the pc_ble_driver.py. I have an OTA service with the UUID AABB A7B0000000000000000000000501</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 31 Aug 2022 09:03:22 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/91308/handling-128-bit-uuids-with-python-pc_ble_driver" /><item><title>RE: Handling 128-bit UUIDs with Python pc_ble_driver</title><link>https://devzone.nordicsemi.com/thread/384078?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2022 09:03:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:07b59c10-7e26-4330-9da3-7a9fe686224f</guid><dc:creator>Kampino</dc:creator><description>&lt;p&gt;Hi &lt;a href="https://devzone.nordicsemi.com/members/hungbui"&gt;Hung Bui&lt;/a&gt;&amp;nbsp;,&lt;/p&gt;
&lt;p&gt;thanks for your response! I will change it :)&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Handling 128-bit UUIDs with Python pc_ble_driver</title><link>https://devzone.nordicsemi.com/thread/384066?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2022 08:12:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:db074dcd-f270-4f24-86a8-368a0b3f0573</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Daniel,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Is it possible to change the UUID of the characteristic and service in your application ?&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;If you are freely to change them I would suggest to follow what we did with the NUS example to have the same UUID base for the characteristic and the service, the only difference is the offset at byte 3rd and 4th.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1661933158189v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If it&amp;#39;s not possible to change the UUIDs, then what you need to do is to define 3 different UUID base , and each of them would have byte 3rd and 4rd set to 0. In your case the 3rd and 4rd bytes are&amp;nbsp;also 0 so you don&amp;#39;t need to do anything.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For example you can define this:&lt;br /&gt; self.your_base1 = BLEUUIDBase([&lt;br /&gt;0x04, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB0, 0xA7, 0x74, 0x4C&lt;br /&gt; ])&lt;/p&gt;
&lt;p&gt;self.your_base2 = BLEUUIDBase([&lt;br /&gt;0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB0, 0xA7, 0x74, 0x4C&lt;br /&gt;])&lt;/p&gt;
&lt;p&gt;&amp;nbsp; self.adapter.driver.ble_vs_uuid_add(&lt;span&gt;self.your_base1)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;self.adapter.driver.ble_vs_uuid_add(self.your_base2)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Then you can call:&lt;/p&gt;
&lt;p&gt;self.your_first_char = BLEUUID(0x0000, self.your_base1)&lt;br /&gt; self.your_second_char&amp;nbsp;= BLEUUID(0x0000, self.your_base2)&lt;/p&gt;
&lt;p&gt;After that you can use&amp;nbsp;&lt;span&gt;your_first_char&lt;/span&gt;&lt;span&gt;&amp;nbsp; and&amp;nbsp;your_second_char&amp;nbsp; the same as what we did with the&amp;nbsp;nus_rx and&amp;nbsp;nus_tx.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;In short the&amp;nbsp;BLEUUID() is the combination of the 3rd and 4th bytes and the base_uuid.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Handling 128-bit UUIDs with Python pc_ble_driver</title><link>https://devzone.nordicsemi.com/thread/383843?ContentTypeID=1</link><pubDate>Tue, 30 Aug 2022 09:38:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7af37f1f-b1f8-42e6-821c-0781d6d1abfd</guid><dc:creator>Kampino</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;yes, I have tried it and everything is okay. But I don&amp;acute;t know how to use this for my problem.&lt;br /&gt;The NUS example uses the following base UUID&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;0x4C, 0x74, 0xA7, 0xB0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x01&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;And the BLEUUID class is generating the following UUIDs based on a base UUID and an offset&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;6E400002-B5A3-F393-E0A9-E50E24DCCA9E
6E400003-B5A3-F393-E0A9-E50E24DCCA9E&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;But my UUID is entirely different. The UUID for the service is&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;pre class="ui-code" data-mode="text"&gt;0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB0, 0xA7, 0x74, 0x4C&lt;/pre&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;and for each characteristic it is&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;0x04, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB0, 0xA7, 0x74, 0x4C
0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB0, 0xA7, 0x74, 0x4C&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Can I handle this with an offset too? So I have to add&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;as an offset?&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;What is a good way to insert the correct UUIDs in this Python script?&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Handling 128-bit UUIDs with Python pc_ble_driver</title><link>https://devzone.nordicsemi.com/thread/383469?ContentTypeID=1</link><pubDate>Fri, 26 Aug 2022 12:28:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bf781121-6e89-4d21-93fe-69a682377bb9</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Have you tried to test with the example from Vidar ?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I&amp;#39;m not sure what the exception is about, but you may want to give the whole log so that I can find more information.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Handling 128-bit UUIDs with Python pc_ble_driver</title><link>https://devzone.nordicsemi.com/thread/383446?ContentTypeID=1</link><pubDate>Fri, 26 Aug 2022 11:19:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8197ca74-1980-405f-9766-194198c7578b</guid><dc:creator>Kampino</dc:creator><description>&lt;p&gt;Hi,&lt;br /&gt;&lt;br /&gt;I have changed the code to the following:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;import sys
import time
import logging
from queue import Queue, Empty
from pc_ble_driver_py.observers import *

global config, BLEDriver, BLEAdvData, BLEEvtID, BLEAdapter, BLEEnableParams, BLEGapTimeoutSrc, BLEUUID, BLEUUIDBase, BLEConfigCommon, BLEConfig, BLEConfigConnGatt, BLEGapScanParams
from pc_ble_driver_py import config

config.__conn_ic_id__ = &amp;quot;NRF52&amp;quot;

from pc_ble_driver_py.ble_driver import (
	BLEDriver,
	BLEAdvData,
	BLEEvtID,
	BLEEnableParams,
	BLEGapTimeoutSrc,
	BLEUUID,
	BLEUUIDBase,
	BLEGapScanParams,
	BLEConfigCommon,
	BLEConfig,
	BLEConfigConnGatt,
)

from pc_ble_driver_py.ble_adapter import BLEAdapter

global nrf_sd_ble_api_ver
nrf_sd_ble_api_ver = config.sd_api_ver_get()

class OTA(BLEDriverObserver, BLEAdapterObserver):
    OTA_BASE_UUID       = BLEUUIDBase(
        [0x4C, 0x74, 0xA7, 0xB0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x01],
        0x02
    )
    OTA_Control_UUID    = BLEUUIDBase(
        [0x4C, 0x74, 0xA7, 0xB0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x04],
        0x02
    )
    OTA_Data_UUID       = BLEUUIDBase(
        [0x4C, 0x74, 0xA7, 0xB0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x05], 
        0x02
    )

    def __init__(self, Adapter):
        super(OTA, self).__init__()
        self.adapter = Adapter
        self.conn_q = Queue()
        self.adapter.observer_register(self)
        self.adapter.driver.observer_register(self)
        self.adapter.default_mtu = 250

    def open(self):
        self.adapter.driver.open()
        gatt_cfg = BLEConfigConnGatt()
        gatt_cfg.att_mtu = self.adapter.default_mtu
        gatt_cfg.tag = 1
        self.adapter.driver.ble_cfg_set(BLEConfig.conn_gatt, gatt_cfg)
        self.adapter.driver.ble_enable()
        self.adapter.driver.ble_vs_uuid_add(OTA.OTA_BASE_UUID)
        self.adapter.driver.ble_vs_uuid_add(OTA.OTA_Control_UUID)
        self.adapter.driver.ble_vs_uuid_add(OTA.OTA_Data_UUID)

    def close(self):
        self.adapter.driver.close()

    def connect_and_discover(self):
        scan_duration = 5
        params = BLEGapScanParams(interval_ms = 200, window_ms = 150, timeout_s = scan_duration)

        self.adapter.driver.ble_gap_scan_start(scan_params = params)

        try:
            new_conn = self.conn_q.get(timeout = scan_duration)
            self.adapter.service_discovery(new_conn)

            return new_conn
        except Empty:
            print(&amp;quot;No advertising with name &amp;#39;jerry3&amp;#39; found.&amp;quot;)

            return None

    def on_gap_evt_connected(self, ble_driver, conn_handle, peer_addr, role, conn_params):
        print(&amp;quot;New connection: {}&amp;quot;.format(conn_handle))
        self.conn_q.put(conn_handle)

    def on_gap_evt_disconnected(self, ble_driver, conn_handle, reason):
        print(&amp;quot;Disconnected: {} {}&amp;quot;.format(conn_handle, reason))

    def on_gap_evt_adv_report(self, ble_driver, conn_handle, peer_addr, rssi, adv_type, adv_data):
        if(BLEAdvData.Types.complete_local_name in adv_data.records):
            dev_name_list = adv_data.records[BLEAdvData.Types.complete_local_name]
        elif(BLEAdvData.Types.short_local_name in adv_data.records):
            dev_name_list = adv_data.records[BLEAdvData.Types.short_local_name]
        else:
            return

        dev_name = &amp;quot;&amp;quot;.join(chr(e) for e in dev_name_list)
        address_string = &amp;quot;&amp;quot;.join(&amp;quot;{0:02X}&amp;quot;.format(b) for b in peer_addr.addr)
        print(&amp;quot;Received advertisment report, address: 0x{}, device_name: {}&amp;quot;.format(address_string, dev_name))

        if(dev_name == &amp;quot;jerry3&amp;quot;):
            self.adapter.connect(peer_addr, tag = 1)

    def on_notification(self, ble_adapter, conn_handle, uuid, data):
        if(len(data) &amp;gt; 32):
            data = &amp;quot;({}...)&amp;quot;.format(data[0:10])
        print(&amp;quot;Connection: {}, {} = {}&amp;quot;.format(conn_handle, uuid, data))

if(__name__ == &amp;quot;__main__&amp;quot;):
    logging.basicConfig(level = &amp;quot;DEBUG&amp;quot;, format = &amp;quot;%(asctime)s [%(thread)d/%(threadName)s] %(message)s&amp;quot;)

    Driver = BLEDriver(serial_port = &amp;quot;COM9&amp;quot;, auto_flash = False, baud_rate = 1000000, log_severity_level = &amp;quot;info&amp;quot;)
    Adapter = BLEAdapter(Driver)
    OTA_Handler = OTA(Adapter)
    OTA_Handler.open()
    Connection = OTA_Handler.connect_and_discover()

    if(Connection is not None):
        while True:
            data = [1]
            Adapter.write_cmd(Connection, OTA.OTA_Control_UUID, data)

    OTA_Handler.close()
    quit()&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The application throws an exception with the message&lt;/p&gt;
&lt;p&gt;&amp;quot;assert isinstance(uuid, BLEUUID), &amp;quot;Invalid argument type&amp;quot; AssertionError: Invalid argument type&amp;quot;&lt;/p&gt;
&lt;p&gt;Where does the error come from?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Handling 128-bit UUIDs with Python pc_ble_driver</title><link>https://devzone.nordicsemi.com/thread/383242?ContentTypeID=1</link><pubDate>Thu, 25 Aug 2022 11:13:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fd5d42ff-cb0f-4118-b4b8-b0e2fd88565e</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Daniel,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can have a look at this example from our coworker Vidar:&amp;nbsp;&lt;br /&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/70137/adding-custome-characterstics-using-pc-ble-driver-py"&gt;Adding custome characterstics using pc-ble-driver-py&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It&amp;#39;s demonstrating a NUS central on PC and you can test it with a ble_app_uart example that is a NUS server/peripheral.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>