示例#1
0
    # !!! 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)
    # Add a callback to be notified of changes
    cc.set_callback(value_cb)

    # Add the Service. You can create additional services and add them one by one
    ble.add_service(s)

    # Configure security. BLE security is very flexible.
示例#2
0
# Prueba2
# Created at 2018-06-27 18:26:27.810830

import streams  # import the streams module
import adc
from nordic.nrf52_ble import nrf52_ble as bledrv
from wireless import ble

streams.serial()
bledrv.init()
ble.gap("RBNBLE1")
s = ble.Service(0x1818)
c = ble.Characteristic(0x2A65, ble.NOTIFY | ble.READ | ble.WRITE, 1, "cY",
                       ble.NUMBER)
s.add_characteristic(c)
ble.add_service(s)
ble.start()
ble.start_advertising()

led_1 = D11
pinMode(led_1, OUTPUT)

while True:
    a = adc.read(A2)
    c.set_value(a)
    if a < 512:
        print("ON")
        digitalWrite(led_1, HIGH)  # turn the LED ON by making the voltage HIGH
        sleep(1000)  # wait for timeON
    else:
        print("OFF")
示例#3
0

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)

    ble.add_service(service_object_transfer)

    #set scanning parameters: every 100ms for 50ms and no duplicates
示例#4
0
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()

while True:
    print(".")
    sleep(1000)
示例#5
0
# 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
ble.start_advertising()

while True:
    print(".")
示例#6
0
# then import the BLE modue
from wireless import ble

streams.serial()

# initialize NRF52 driver
bledrv.init()

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

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

# Create a GATT Characteristic: (uuid for Battery Level is 0x2A19, and it is an 8-bit number)
c = ble.Characteristic(0x2A37, ble.NOTIFY | ble.READ, 1, "Heart Rate",
                       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
ble.start_advertising()

while True:
    print(".")