ble.start_advertising() connected = False # Let's define some security callbacks def show_key_cb(passkey): print("ENTER THIS PIN ON THE MASTER:", passkey) 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)
print(" remote device has RSSI of",data[2]) def scan_start_cb(data): print("Scan started") def scan_stop_cb(data): print("Scan stopped") #let's start it up again ble.start_scanning(scan_time) try: # initialize BLE driver bledrv.init() # Set GAP name and no security ble.gap("Zerynth",security=(ble.SECURITY_MODE_1,ble.SECURITY_LEVEL_1)) ble.add_callback(ble.EVT_SCAN_REPORT,scan_report_cb) ble.add_callback(ble.EVT_SCAN_STARTED,scan_start_cb) ble.add_callback(ble.EVT_SCAN_STOPPED,scan_stop_cb) #set scanning parameters: every 100ms for 50ms and no duplicates ble.scanning(100,50,duplicates=0) # Start the BLE stack ble.start() # Now start scanning for 30 seconds ble.start_scanning(scan_time) except Exception as e:
# 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")
_isStop = False def scan_stop_cb(data): global _isStop _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)
# Created at 2018-06-19 22:26:09.099320 # Prueba de un Services con dos Characteristics 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("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
# Author: G. Baldi ############################################################################### 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
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("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