Skip to main content

Library for using the bleuio dongle.

Project description

##Python library v1.1.2 for BleuIO

Supports BleuIO v.2.0.4

Instructions

  • Install the library by running:
pip install bleuio
  • In the python file import:
 from bleuio_lib.bleuio_funcs import BleuIo
  • Initialise an object with BleuIo. You can leave the parameters empty for auto detection.
# Auto-Detect dongle
my_dongle = BleuIo()
# Specific COM port (Win) 'COMX'
my_dongle = BleuIo(port='COM7')
# Specific COM port (Linux) 'dev/tty.xxxxx...'
my_dongle = BleuIo(port='/dev/tty.123546877')
# Specific COM port (Mac) 'dev/cu.xxxx...'
my_dongle = BleuIo(port='/dev/cu.123546877')
  • Start the deamon (background process handler) for rt and tx data.
my_dongle.start_daemon()
  • Access all BleuIo AT-commands from my_dongle object.
  • The functions return a string list.
  • Don't forget that you can stop started scans with:
my_dongle.stop_scan()

and SPS streams with:

my_dongle.stop_sps()

Just remember that scans and streams will run indefinitely if not otherwise specified. They will not return data until stopped using .stop_scan() or stop_sps(). Once stopped you can collect the data from my_dongle.rx_scanning_results or my_dongle.rx_sps_results. You can get a live feed by listening to .rx_buffer().

Some examples can be found in bleuio_tests\test_bleuio_funcs.py

NOTE: The streaming functions of the at_spssend() is unstable. We are working on fixing it. The at_spssend() command with parameters works fine and we suggest you use that instead untill a bugfix is released.

Functions

class BleuIo(object):
    def __init__(self, port='auto', baud=57600, timeout=1, debug=False):
        """
        Initiates the dongle. If port param is left as 'auto' it will auto-detect if bleuio dongle is connected.        :param port: str
        :param baud: int
        :param timeout: int
        :param debug: bool
        """


    def start_daemon(self):
        """
        Initiates a thread which manages all traffic received from serial
        and dispatches it to the appropriate callback
        """

    def stop_daemon(self):
        """
        Stops the thread which is monitoring the serial port for incoming
        traffic from the devices.
        """


    def send_command(self, cmd):
        """
        :param cmd: Data to be sent over serial. Can be used with the sps stream.
        """

    def stop_scan(self):
        """
        Stops any type of scan.
        :return: str list
        """

    def stop_sps(self):
        """
        Stops SPS Stream-mode.
        :return: str list
        """

    def at(self):
        """
        Basic AT-Command.
        :return:
        """

    def ata(self, isOn):
        """
        Shows/hides ascii values from notification/indication/read responses.
        :param isOn: (boolean) True=On, False=Off
        :return:
        """

    def atds(self, isOn):
        """
        Turns auto discovery of services when connecting on/off.
        :param isOn: (boolean) True=On, False=Off
        :return:
        """

    def ate(self, isOn):
        """
        Turns Echo on/off.
        :param isOn: (boolean) True=On, False=Off
        :return:
        """

    def ati(self):
        """
        Device information query.
        :return: str
        """

    def atr(self):
        """
        Trigger platform reset.
        :return: str
        """

    def at_advdata(self, advdata=""):
        """
        Sets or queries the advertising data.
        :param: if left empty it will query what advdata is set
        :param advdata: hex str format: xx:xx:xx:xx:xx.. (max 31 bytes)
        :return: string[]
        """

    def at_advdatai(self, advdata):
        """
        Sets advertising data in a way that lets it be used as an iBeacon.
        Format = (UUID)(MAJOR)(MINOR)(TX)
        Example: at_advdatai(5f2dd896-b886-4549-ae01-e41acd7a354a0203010400)
        :param: if left empty it will query what advdata is set
        :param advdata: hex str
        :return: string[]
        """

    def at_advstart(self, conn_type="", intv_min="", intv_max="", timer=""):
        """
        Starts advertising with default settings if no params.
        With params: Starts advertising with <conn_type><intv_min><intv_max><timer>.
        :param: Starts advertising with default settings.
        :param conn_type: str
        :param intv_min: str
        :param intv_max: str
        :param timer: str
        :return: string[]
        """

    def at_advstop(self):
        """
        Stops advertising.
        """

    def at_advresp(self, respData=""):
        """
        Sets or queries scan response data. Data must be provided as hex string.
        :param: if left empty it will query what advdata is set
        :param respData: hex str format: xx:xx:xx:xx:xx.. (max 31 bytes)
        :return: string[]
        """

    def at_cancel_connect(self):
        """
        While in Central Mode, cancels any ongoing connection attempts.
        :return: string[]
        """

    def at_central(self):
        """
        Sets the device Bluetooth role to central role.
        :return: string[]
        """

    def at_client(self):
        """
        Only in dual role.
        Sets the device role towards the targeted connection to client.
        :return: string[]
        """

    def at_dual(self):
        """
        Sets the device Bluetooth role to dual role.
        :return: string[]
        """

    def at_enter_passkey(self, passkey):
        """
        When faced with this message: BLE_EVT_GAP_PASSKEY_REQUEST use the AT+ENTERPASSKEY command to enter
        the 6-digit passkey to continue the pairing request.
        :param passkey: str: six-digit number string "XXXXXX"
        :return: string[]
        """

    def at_findscandata(self, scandata):
        """
        Scans for all advertising/response data which contains the search params.
        :param scandata: str
        :return: string[]
        """

    def at_gapconnect(self, addr, timeout=0):
        """
        Initiates a connection with a specific slave device.
        :param addr: hex str format: xx:xx:xx:xx:xx:xx
        :return: string[]
        """

    def at_gapdisconnect(self):
        """
        Disconnects from a peer Bluetooth device.
        :return: string[]
        """

    def at_gapdisconnectall(self):
        """
        Disconnects from all peer Bluetooth devices.
        :return: string[]
        """

    def at_gapiocap(self, io_cap=""):
        """
        Sets or queries what input and output capabilities the device has. Parameter is number between 0 to 4.
        :param io_cap: str: number string "x"
        :return: string[]
        """

    def at_gappair(self, bonded=False):
        """
        Starts a pairing (bonded=False) or bonding procedure (bonded=True).
        :param bonded: boolean
        :return: string[]
        """

    def at_gapscan(self, timeout=0):
        """
        Starts a Bluetooth device scan with or without timer set in seconds.
        :param: if left empty it will scan indefinitely
        :param timeout: int (time in seconds)
        :return: string[]
        """

    def at_gapunpair(self, addr_to_unpair=""):
        """
        Unpair paired devices if no parameters else unpair specific device. This will also remove the device bond data
        from BLE storage.
        Usable both when device is connected and when not.
        :param addr_to_unpair: hex str format: [x]xx:xx:xx:xx:xx:xx
        :return: string[]
        """

    def at_gapstatus(self):
        """
        Reports the Bluetooth role.
        :return: string[]
        """

    def at_gattcread(self, uuid):
        """
        Read attribute of remote GATT server.
        :param uuid: hex str format: xxxx
        :return: string[]
        """

    def at_gattcwrite(self, uuid, data):
        """
        Write attribute to remote GATT server in ASCII.
        :param uuid: hex str format: xxxx
        :param data: str
        :return: string[]
        """

    def at_gattcwriteb(self, uuid, data):
        """
        Write attribute to remote GATT server in Hex.
        :param uuid: hex str format: "xxxx"
        :param data: hex str format: "xxxxxxxx.."
        :return: string[]
        """

    def at_gattcwritewr(self, uuid, data):
        """
        Write, without response, attribute to remote GATT server in ASCII.
        :param uuid: hex str format: xxxx
        :param data: str
        :return: string[]
        """

    def at_gattcwritewrb(self, uuid, data):
        """
        Write, without response, attribute to remote GATT server in Hex.
        :param uuid: hex str format: "xxxx"
        :param data: hex str format: "xxxxxxxx.."
        :return: string[]
        """

    def at_get_services(self):
        """
        Rediscovers a peripheral's services and characteristics.
        """

    def at_get_servicesonly(self):
        """
        Rediscovers a peripheral's services and characteristics.
        """

    def at_get_service_details(self, uuid):
        """
        Rediscovers a peripheral's services and characteristics.
        """

    def at_get_conn(self):
        """
        Gets a list of currently connected devices along with their mac addresses and conn_idx.
        :return: string[]
        """

    def at_numcompa(self, auto_accept="2"):
        """
        Used for accepting a numeric comparison authentication request (no params) or enabling/disabling auto-accepting
        numeric comparisons. auto_accept="0" = off, auto_accept="1" = on.
        :param auto_accept: str format: "0" or "1"
        :return: string[]
        """

    def at_peripheral(self):
        """
        Sets the device Bluetooth role to peripheral.
        :return: string[]
        """

    def at_scantarget(self, addr):
        """
        Scan a target device. Displaying it's advertising and response data as it updates.
        :param addr: hex str format: "xx:xx:xx:xx:xx:xx"
        :return: string[]
        """

    def at_sec_lvl(self, sec_lvl=""):
        """
        Sets or queries (no params) what minimum security level will be used when connected to other devices.
        :param sec_lvl:  str: string number between 0 and 3
        :return: string[]
        """

    def at_server(self):
        """
        Only in dual role.
        Sets the device role towards the targeted connection to server.
        :return: string[]
        """

    def at_setnoti(self, handle):
        """
        Enable notification for selected characteristic.
        :param handle: hex str format: "xxxx"
        :return: string[]
        """

    def at_set_passkey(self, passkey=""):
        """
        Setting or quering set passkey (no params) for passkey authentication.
        :param passkey: hex str format: "xxxxxx"
        :return: string[]
        """

    def at_spssend(self, data=""):
        """
        Send a message or data via the SPS profile.
        Without parameters it opens a stream for continiously sending data.
        The streaming functions of the at_spssend() is unstable. We are working on fixing it.
        :param: if left empty it will open Streaming mode
        :param data: str
        :return: string[]
        """

    def at_target_conn(self, conn_idx=""):
        """
        Set or quering the connection index which is the targeted connection.
        :param conn_idx: hex str format: xxxx
        :return: string[]
        """

    def help(self):
        """
        Shows all AT-Commands.
        :return: string[]
        """

#Enjoy!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for bleuio, version 1.1.2
Filename, size File type Python version Upload date Hashes
Filename, size bleuio-1.1.2.tar.gz (14.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page