This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Unable to list the device using python API - Sniffer software

I'm using nRF51 BLE dongle as a sniffer and trying to capture BLE packets through CLI. I'm using example.py which came with nRF sniffer software.

I unable to get the list of devices when using 'example.py' code. I have tried the steps as described in "Sniffer API Guide".

Still the output "Sniffer Device List:[]" is sample.

If I'm right once the device is listed, I can able to sniffer the BLE packets of the listed device.Please let me know, If i'm doing anything wrong here.

Attached CLI output and 'example.py' code file which I'm trying to execute.

EDIT :

Adding software & Hardware Config details :

Sniffer software version : nrf_sniffer_for_bluetooth_le_3.0.0_129d2b3

Flash bin file : sniffer_pca10031_129d2b3.hex

Dongle HW version : 1.0.0

# Copyright (c) 2017, Nordic Semiconductor ASA
# 
# All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 
#    1. Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
# 
#    2. Redistributions in binary form must reproduce the above
#       copyright notice, this list of conditions and the following
#       disclaimer in the documentation and/or other materials provided
#       with the distribution.
# 
#    3. Neither the name of Nordic Semiconductor ASA nor the names of
#       its contributors may be used to endorse or promote products
#       derived from this software without specific prior written
#       permission.
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NORDIC
# SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.

import time
from SnifferAPI import Sniffer, UART

nPackets = 0
mySniffer = None

def setup():
    global mySniffer
    
    # Find connected sniffers
    ports = UART.find_sniffer()
    
    if len(ports) > 0:
        # Initialize the sniffer on the first COM port found with baudrate 1000000.
        # If you are using an old firmware version <= 2.0.0, simply remove the baudrate parameter here.
        mySniffer = Sniffer.Sniffer(portnum=ports[0], baudrate=1000000)
    
    else:
        print("No sniffers found!")
        return
    
    # Start the sniffer module. This call is mandatory.
    mySniffer.start()

    # Wait to allow the sniffer to discover device mySniffer.
    time.sleep(5)
    # Retrieve list of discovered devicemySniffer.
    d = mySniffer.getDevices()
    # Find device with name "Example".
    dev = d.find('Example')
    
    if dev is not None:
        # Follow (sniff) device "Example". This call sends a REQ_FOLLOW command over UART.
        mySniffer.follow(dev)
    else:
        print("Could not find device")

def loop():
    # Enter main loop
    nLoops = 0
    while True:
        time.sleep(0.1)
        # Get (pop) unprocessed BLE packets.
        packets = mySniffer.getPackets()
        
        processPackets(packets) # function defined below
        
        nLoops += 1
        
        # print diagnostics every so often
        if nLoops % 20 == 0:
            print(mySniffer.getDevices())
            print("inConnection", mySniffer.inConnection)
            print("currentConnectRequest", mySniffer.currentConnectRequest)
            print("packetsInLastConnection", mySniffer.packetsInLastConnection)
            print("nPackets", nPackets)
            print()
        
# Takes list of packets
def processPackets(packets):
    for packet in packets:
        # packet is of type Packet
        # packet.blePacket is of type BlePacket
        global nPackets
        # if packet.OK:
        # Counts number of packets which are not malformed.
        nPackets += 1
    
setup()
if mySniffer is not None:
    loop()

  • Microsoft Windows [Version 10.0.17763.1339]
    (c) 2018 Microsoft Corporation. All rights reserved.
    
    C:\Program Files\Wireshark\extcap>python
    Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import time
    >>> from SnifferAPI import Sniffer, UART
    >>> nPackets = 0
    >>> mySniffer = None
    >>> global mySniffer
    >>> ports = UART.find_sniffer()
    >>> ports
    ['COM9']
    >>> mySniffer = Sniffer.Sniffer(portnum=ports[0], baudrate=1000000)
    >>> mySniffer.start()
    >>> time.sleep(5)
    >>> d = mySniffer.getDevices()
    >>> d
    Sniffer Device List: []
    >>> tls_dev_addr = [0x14, 0xb4, 0x57, 0x81, 0x90, 0x4a, True]
    >>> for _ in range(10):
    ...  time.sleep(1)
    ...  devlist = mySniffer.getDevices()
    ...  found_dev = [dev for dev in devlist.devices if dev.address == tls_dev_addr]
    ...  if found_dev:
    ...     follow(mySniffer, found_dev[0])
    ...     break
    ...
    >>>
    >>> found_dev
    []
    >>> devlist
    Sniffer Device List: []
    >>> tls_dev_addr = [0x14, 0xb4, 0x57, 0x81, 0x90, 0x4a, True]
    >>> for _ in range(10):
    ...     time.sleep(1)
    ...     devlist = sniffer.getDevices()
    ...     found_dev = [dev for dev in devlist.devices if dev.address == tls_dev_addr]
    ...     if found_dev:
    ...         follow(sniffer, found_dev[0])
    ...         break
    ...
    Traceback (most recent call last):
      File "<stdin>", line 3, in <module>
    NameError: name 'sniffer' is not defined
    >>> tls_dev_addr = [0x14, 0xb4, 0x57, 0x81, 0x90, 0x4a, True]
    >>> for _ in range(10):
    ...     time.sleep(1)
    ...     devlist = Sniffer.getDevices()
    ...     found_dev = [dev for dev in devlist.devices if dev.address == tls_dev_addr]
    ...     if found_dev:
    ...         follow(Sniffer, found_dev[0])
    ...         break
    ...
    Traceback (most recent call last):
      File "<stdin>", line 3, in <module>
    AttributeError: module 'SnifferAPI.Sniffer' has no attribute 'getDevices'
    >>>
    >>> ^Z^Z
    
    
    C:\Program Files\Wireshark\extcap>python
    Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import time
    >>> from SnifferAPI import Sniffer, UART
    >>> nPackets = 0
    >>> mySniffer = None
    >>> ports = UART.find_sniffer()
    >>> mySniffer = Sniffer.Sniffer(portnum=ports[0])
    >>> mySniffer
    <Sniffer(Thread-3, initial daemon)>
    >>> mySniffer.start()
    >>> time.sleep(5)
    >>> d = mySniffer.getDevices()
    >>> d
    Sniffer Device List: []
    >>> tls_dev_addr = [0x14, 0xb4, 0x57, 0x81, 0x90, 0x4a, True]
    >>> for _ in range(10):
    ...     time.sleep(1)
    ...     devlist = mySniffer.getDevices()
    ...     found_dev = [dev for dev in devlist.devices if dev.address == tls_dev_addr]
    ...     if found_dev:
    ...         follow(mySniffer, found_dev[0])
    ...         break
    ...
    >>>
    >>> found_dev
    []
    >>> tls_dev_name = "deviceName"
    >>>
    >>> for _ in range(10):
    ...     time.sleep(1)
    ...     devlist = mySniffer.getDevices()
    ...     found_dev = [dev for dev in devlist.devices if dev.name == tls_dev_name]
    ...     if found_dev:
    ...         follow(mySniffer, found_dev[0])
    ...         break
    ...
    >>> found_dev
    []
    >>> tls_dev_name = "SiliconL_81:90:4a"
    >>> for _ in range(10):
    ...     time.sleep(1)
    ...     devlist = mySniffer.getDevices()
    ...     found_dev = [dev for dev in devlist.devices if dev.name == tls_dev_name]
    ...     if found_dev:
    ...         follow(mySniffer, found_dev[0])
    ...         break
    ...
    >>> found_dev
    []
    >>> tls_dev_name = "SiliconL_81:90:4a"
    >>> for _ in range(10):
    ...     time.sleep(1)
    ...     devlist = mySniffer.getDevices()
    ...     found_dev = [dev for dev in devlist.devices if "prefix" in dev.name]
    ...     if found_dev:
    ...         follow(mySniffer, found_dev[0])
    ...         break
    ...
    >>> found_dev
    []
    >>> for _ in range(10):
    ...     time.sleep(1)
    ...     devlist = mySniffer.getDevices()
    ...     found_dev = [dev for dev in devlist.devices if "Silicon" in dev.name]
    ...     if found_dev:
    ...         follow(mySniffer, found_dev[0])
    ...         break
    ...
    >>> found_dev
    []
    >>> tls_dev_name = "SiliconL_81:90:4a"
    >>> for _ in range(10):
    ...     time.sleep(1)
    ...     devlist = mySniffer.getDevices()
    ...     found_dev = [dev for dev in devlist.devices if "Silicon" in dev.name]
    ...     if found_dev:
    ...         follow(mySniffer, found_dev[0])
    ...         break
    ...
    >>>
    >>> found_dev
    []
    >>>
    
    
    

    Hi Amanda,

    I've tried the above steps and unable to get the device list. Still I'm facing the same issues. Kindly look over the terminal output and let me know if anything needs to be changed. Thanks!

  • Also,FYI ,  I use sniffer software version 3.0 -> "nrf_sniffer_for_bluetooth_le_3.0.0_129d2b3" in 1.1.0 nRF51 Dongle. I flashed with sniffer_pca10031_129d2b3.hex .

    Is this issue due to config conflict ? I'm afraid because I can able to run nRF51 dongle from wireshark. I have issues only when I try to run with Python API directly.

  • It appears that the examples are a bit outdated.

    >>> import time
    >>> from SnifferAPI import Sniffer, UART
    >>> nPackets = 0
    >>> global mySniffer
    >>> ports = UART.find_sniffer
    >>> ports = UART.find_sniffer()
    >>> ports
    ['COM17']
    >>> mySniffer = Sniffer.Sniffer(portnum=ports[0], baudrate=1000000)
    >>> mySniffer
    <Sniffer(Thread-7, initial daemon)>
    >>> mySniffer.start()
    >>> time.sleep(5)
    >>> d = mySniffer.getDevices()
    >>> d
    Sniffer Device List: []
    >>> mySniffer.scan()
    >>> mySniffer.getDevices()
    Sniffer Device List: [BLE device """" ([115, 9, 128, 76, 215, 67, True]), BLE device """" ([124, 100, 86, 53, 157, 53, False]), BLE device """" ([208, 3, 75, 88, 160, 227, False]), BLE device """" ([38, 23, 59, 112, 26, 198, True]), BLE device """" ([200, 105, 205, 110, 174, 101, False]), BLE device ""IDTW218H"" ([217, 199, 249, 113, 70, 199, True]), BLE device ""KICKR SNAP 0443"" ([192, 231, 179, 209, 66, 153, True]), BLE device """" ([61, 44, 48, 209, 80, 224, True])]

  • Hi Joakim,

    Thanks, The following code worked and can able to list the devices. Could you please share the latest example file?

    And I unable to Follow specific device after getting the device list.  Is there any reason or it might be due to outdated code. Could you please help me with latest code for Following specific device?

Related