# 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. # In this case we declare that the device has only an output capability (CAP_DISPLAY_ONLY), # that we require a bonding (storage of the keys after pairing) # and that we want both secure connection and main in the middle protection. # Since we have CAP_DISPLAY_ONLY, we also declare a passkey that will be shown to the user # to be entered on the master (i.e. the smartphone) to finalize the bonding. ble.security(capabilities=ble.CAP_DISPLAY_ONLY, bonding=ble.AUTH_BOND, scheme=ble.AUTH_SC | ble.AUTH_MITM, key_size=16, passkey=225575) # To do so, we need a callback to display the passkey when needed ble.add_callback(ble.EVT_SHOW_PASSKEY, show_key_cb)
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 ble.advertising(50) # Start the BLE stack ble.add_callback(ble.EVT_SCAN_REPORT, scan_report_cb) ble.add_callback(ble.EVT_SCAN_STOPPED, scan_stop_cb) ble.scanning(100, 50, duplicates=0) ble.start() ble.start_advertising()