Pycom Documentation
  • Introduction
  • Pycom Products
  • Getting Started
    • Introduction
    • Hardware Setup
      • LoPy
      • LoPy 4
      • SiPy
      • GPy
      • FiPy
      • WiPy
    • Software
      • Drivers
      • Updating Firmware
      • Pymakr
    • Programming the modules
      • Introduction to MicroPython
      • MicroPython Examples
      • Your first Pymakr project
      • REPL
        • Serial USB (UART)
        • Telnet REPL
      • FTP
      • Safe boot
    • Device Registration
      • Sigfox
      • Cellular
      • LoRaWAN
        • The Things Network
        • Objenious
  • Pymakr Plugin
    • Installation
      • Atom
      • Visual Studio Code
    • Tools/Features
    • Settings
  • Pytrack, Pysense, Pyscan
    • Introduction
    • Installing Software
      • Updating Firmware
      • Installing Drivers - Windows 7
      • Installing Libraries
    • API Reference
      • Pytrack
      • Pysense
      • Pyscan
      • Sleep
  • Tutorials & Examples
    • Introduction
    • All Pycom Device Examples
      • REPL
      • WLAN
      • Bluetooth
      • HTTPS
      • MQTT
      • AWS
      • ADC
      • I2C
      • Onewire Driver
      • Threading
      • RGB LED
      • Timers
      • PIR Sensor
      • Modbus
      • OTA update
      • RMT
      • Socket
      • Touch
    • LoRa Examples
      • LoRa-MAC (Raw LoRa)
      • LoRaWAN with OTAA
      • LoRaWAN with ABP
      • LoRa-MAC Nano-Gateway
      • LoPy to LoPy
      • LoRaWAN Nano-Gateway
      • RN2483 to LoPy
      • LoRa Mesh
      • PyMesh Border Router
    • Sigfox Examples
    • LTE Examples
      • CAT-M1
      • NB-IoT
      • Module IMEI
      • Modem Firmware Update
    • Pytrack Examples
    • Pysense Examples
    • Pyscan Examples
  • Firmware & API Reference
    • Introduction
    • Pycom Modules
      • machine
        • ADC
        • DAC
        • I2C
        • Pin
        • PWM
        • RTC
        • SPI
        • UART
        • WDT
        • Timer
        • SD
        • CAN
        • RMT
      • network
        • WLAN
        • Server
        • Bluetooth
          • GATT
          • GATTCConnection
          • GATTCService
          • GATTCCharacteristic
          • GATTSService
          • GATTSCharacteristic
        • LoRa
          • Pymesh
        • Sigfox
        • LTE
      • AES
      • pycom
    • MicroPython Modules
      • micropython
      • uctypes
      • sys
      • uos
      • array
      • cmath
      • math
      • gc
      • ubinascii
      • ujson
      • ure
      • usocket
      • select
      • utime
      • uhashlib
      • ussl
      • ucrypto
      • ustruct
        • uzlib
      • _thread
      • Builtin
    • Notes
  • Product Info, Datasheets
    • Introduction
    • Development Modules
      • WiPy 2.0
      • WiPy 3.0
      • LoPy
      • LoPy 4
      • SiPy
      • GPy
      • FiPy
    • OEM Modules
      • W01
      • L01
      • L04
      • G01
      • L01 OEM Baseboard Reference
      • Universal OEM Baseboard Reference
    • Expansion Boards and Shields
      • Expansion Board 3.0
      • Pytrack
      • Pysense
      • Pyscan
      • Expansion Board 2.0
      • Deep Sleep Shield
        • Deep Sleep API
    • Notes
  • Pybytes
    • Introduction
    • Getting Started with Pybytes
    • Add a device to Pybytes
      • Connect to Pybytes: Quick Add
      • Connect to Pybytes: Flash Pybytes library manually
      • Add Sigfox device
        • DevKit contract
        • Custom contract
    • Visualise data from your device
    • Integrations
      • Amazon IoT
  • Documentation Notes
    • Introduction
    • Syntax
    • REPL vs Scripts
    • Mesh Networks
  • Advanced Topics
    • Firmware Downgrade
    • CLI Updater
    • SecureBoot and Encryption
    • License
  • Have a question?
    • Ask on the Forum
Powered by GitBook
On this page
  1. Firmware & API Reference
  2. Pycom Modules
  3. network
  4. Bluetooth

GATTCCharacteristic

The smallest concept in GATT is the Characteristic, which encapsulates a single data point (though it may contain an array of related data, such as X/Y/Z values from a 3-axis accelerometer, longitude and latitude from a GPS, etc.).

The following class allows you to manage characteristics from a Client.

Methods

characteristic.uuid()

Returns the UUID of the service. In the case of 16-bit or 32-bit long UUIDs, the value returned is an integer, but for 128-bit long UUIDs the value returned is a bytes object.

characteristic.instance()

Returns the instance ID of the service.

characteristic.properties()

Returns an integer indicating the properties of the characteristic. Properties are represented by bit values that can be OR-ed together. See the constants section for more details.

characteristic.read()

Read the value of the characteristic, sending a request to the GATT server. Returns a bytes object representing the characteristic value.

characteristic.value()

Returns the locally stored value of the characteristic without sending a read request to the GATT server. If the characteristic value hasn't been read from the GATT server yet, the value returned will be 0.

characteristic.write(value)

Writes the given value on the characteristic. For now it only accepts bytes object representing the value to be written.

characteristic.write(b'x0f')

characteristic.callback(trigger=None, handler=None, arg=None)

This method allows to register for notifications on the characteristic.

  • trigger can must be Bluetooth.CHAR_NOTIFY_EVENT.

  • handler is the function that will be executed when the callback is triggered.

  • arg is the argument that gets passed to the callback. If nothing is given, the characteristic object that owns the callback will be used.

characteristic.read_descriptor(uuid)

Returns the value of the descriptor specified by the uuid parameter. If no descriptor found for the characteristic returns None.

descriptor = char.read_descriptor(0x2900)
if(descriptor != None):
    print("Characteristic Extended Properties: " + str(binascii.hexlify((descriptor))))

descriptor = char.read_descriptor(0x2901)
if(descriptor != None):
    print("Characteristic User Description: " + str(binascii.hexlify((descriptor))))

descriptor = char.read_descriptor(0x2902)
if(descriptor != None):
    print("Client Characteristic Configuration: " + str(binascii.hexlify((descriptor))))

descriptor = char.read_descriptor(0x2904)
if(descriptor != None):
    print("Characteristic Presentation Format: " + str(binascii.hexlify((descriptor))))
PreviousGATTCServiceNextGATTSService

Last updated 6 years ago