Exemplo n.º 1
0
try:
    # initialize BLE driver
    bledrv.init()

    # Set GAP name and LEVEL 2 security
    # !!! If security is not set, no secure connection will be possible
    ble.gap("ZNotifier", security=(ble.SECURITY_MODE_1, ble.SECURITY_LEVEL_2))

    # add some GAP callbacks
    ble.add_callback(ble.EVT_CONNECTED, connection_cb)
    ble.add_callback(ble.EVT_DISCONNECTED, disconnection_cb)

    # Create a GATT Service: let's try an Alert Notification Service
    # (here are the specs: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.service.alert_notification.xml)
    s = ble.Service(0x1811)

    # The Alert Notification service has multiple characteristics. Let's add them one by one

    # Create a GATT Characteristic for counting new alerts.
    # specs: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.supported_new_alert_category.xml
    cn = ble.Characteristic(0x2A47, ble.NOTIFY | ble.READ, 16, "New Alerts",
                            ble.BYTES)
    # Add the GATT Characteristic to the Service
    s.add_characteristic(cn)

    # Create anothr GATT Characteristic for enabling/disabling alerts
    # specs: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.alert_notification_control_point.xml
    cc = ble.Characteristic(0x2A44, ble.WRITE, 2, "Alerts control", ble.BYTES)
    # Add the GATT Characteristic to the Service
    s.add_characteristic(cc)
Exemplo n.º 2
0
# import a BLE driver: in this example we use NRF52
from nordic.nrf52_ble import nrf52_ble as bledrv
# then import the BLE modue
from wireless import ble

streams.serial()

# initialize NRF52 driver
bledrv.init()

# Set GAP name
ble.gap("RBKarim1")

# Create a GATT Service: let's try a Battery Service (uuid is 0x180F)
#s = ble.Service(0x180F)
ss = ble.Service(0x181C)

# Create a GATT Characteristic: (uuid for Battery Level is 0x2A19, and it is an 8-bit number)
#c1 = ble.Characteristic(0x2A19,ble.NOTIFY | ble.READ,1,"Battery Level",ble.NUMBER)
c2 = ble.Characteristic(0x2A59, ble.READ, 1, "Analog Output", ble.NUMBER)
# Add the GATT Characteristic to the Service
#s.add_characteristic(c1)
ss.add_characteristic(c2)
# Add the Service
#ble.add_service(s)
ble.add_service(ss)
# Start the BLE stack
ble.start()

# Begin advertising
ble.start_advertising()
Exemplo n.º 3
0
    _isStop = True
    gc.collect()
    #let's start it up again


try:
    # initialize BLE driver
    bledrv.init()

    # Set GAP name and no security
    ble.gap("ct2", security=(ble.SECURITY_MODE_1, ble.SECURITY_LEVEL_1))

    ble.add_callback(ble.EVT_CONNECTED, connected_cb)
    ble.add_callback(ble.EVT_DISCONNECTED, disconnected_cb)

    service_object_transfer = ble.Service(0x1825)

    characteristic_object_changed = ble.Characteristic(0x2AC8,
                                                       ble.NOTIFY | ble.READ,
                                                       16, "Object Changed",
                                                       ble.BYTES)

    characteristic_object_control = ble.Characteristic(0x2AC5, ble.WRITE, 1,
                                                       "Object Control Point",
                                                       ble.BYTES)

    service_object_transfer.add_characteristic(characteristic_object_changed)
    service_object_transfer.add_characteristic(characteristic_object_control)

    characteristic_object_control.set_callback(receive_cb)
Exemplo n.º 4
0
import streams
# import a BLE driver: in this example we use NRF52
from nordic.nrf52_ble import nrf52_ble as bledrv
# then import the BLE modue
from wireless import ble

streams.serial()

# initialize NRF52 driver
bledrv.init()

# Set GAP name
ble.gap("Zerynth")

# Create a GATT Service: let's try a Battery Service (uuid is 0x180F)
s = ble.Service(0x180F)

# Create a GATT Characteristic: (uuid for Battery Level is 0x2A19, and it is an 8-bit number)
c = ble.Characteristic(0x2A19, ble.NOTIFY | ble.READ, 1, "Battery Level",
                       ble.NUMBER)

# Add the GATT Characteristic to the Service
s.add_characteristic(c)

# Add the Service
ble.add_service(s)

# Start the BLE stack
ble.start()

# Begin advertising