def run(): SRVC_UUID = '00000000-0000-4b23-9358-f235b978d07c' CHAR_SENSOR_IR_UUID = '11111111-1111-4b23-9358-f235b978d07c' CHAR_WII_STATUS_UUID = '22222222-2222-4b23-9358-f235b978d07c' CHAR_WII_BUTTONS_UUID = '33333333-3333-4b23-9358-f235b978d07c' CHAR_DEBUG_COUNTER_UUID = '99999999-1111-4b23-9358-f235b978d07c' wiimote = None app = peripheral.Application() service = peripheral.Service(SRVC_UUID, True) # Primary service service.add_characteristic(IRCharacteristic(CHAR_SENSOR_IR_UUID, service)) wii_status_char = WiiStatusCharacteristic(CHAR_WII_STATUS_UUID, service, lambda: wiimote) service.add_characteristic(wii_status_char) service.add_characteristic( WiiButtonsCharacteristic(CHAR_WII_BUTTONS_UUID, service, lambda: wiimote)) service.add_characteristic( CounterCharacteristic(CHAR_DEBUG_COUNTER_UUID, service)) app.add_service(service) app.start()
def __init__(self): self.app = peripheral.Application() self.ble_uart = peripheral.Service(HM_10_UART_SERIVCE, True) self.rxtx_uart = peripheral.Characteristic( HM_10_UART_CHARACTERISTIC, ['write', 'write-without-response', 'notify'], self.ble_uart) self.rxtx_uart.add_write_event(self.uart_print) self.rxtx_uart.add_notify_event(print) self.rxtx_uart.StartNotify() self.ble_uart.add_characteristic(self.rxtx_uart) self.app.add_service(self.ble_uart) self.other_service = peripheral.Service( '0000180A-0000-1000-8000-00805F9B34FB', True) self.app.add_service(self.other_service)
def __init__(self): self.app = peripheral.Application() self.ble_uart = peripheral.Service(UART_SERVICE, True) self.rx_uart = peripheral.Characteristic( RX_CHARACTERISTIC, ['write', 'write-without-response'], self.ble_uart) self.tx_uart = peripheral.Characteristic(TX_CHARACTERISTIC, ['notify'], self.ble_uart) self.rx_uart.add_write_event(self.uart_print) self.tx_uart.add_notify_event(print) self.tx_uart.StartNotify() self.ble_uart.add_characteristic(self.rx_uart) self.ble_uart.add_characteristic(self.tx_uart) self.app.add_service(self.ble_uart)
import sys import os sys.path.insert(0, os.path.split(os.path.dirname(os.path.realpath(__file__)))[0]) from time import sleep from threading import Thread from bluezero import peripheral # Bluetooth Service service1 = peripheral.Service('12341000-1234-1234-1234-123456789abc', True) char1 = peripheral.Characteristic('12341002-1234-1234-1234-123456789abc', ['read', 'write', 'notify'], service1) service1.add_characteristic(char1) service2 = peripheral.Service('12341000-1234-1234-1234-123456789def', True) char2 = peripheral.Characteristic('12341002-1234-1234-1234-123456789def', ['read', 'write', 'notify'], service2) service2.add_characteristic(char2) app1 = peripheral.Application() app1.add_service(service1) app2 = peripheral.Application() app2.add_service(service2) TOGGLE_DELAY = 30
import sys import os sys.path.insert(0, os.path.split(os.path.dirname(os.path.realpath(__file__)))[0]) from bluezero import peripheral from bluezero import tools # Bluetooth # Add beacon information ukBaz_beacon = peripheral.Service('FEAA', True, type='broadcast') service_data = tools.url_to_advert('https://github.com/ukBaz', frame_type=0x10, tx_power=0xFF) ukBaz_beacon.add_service_data(service_data) # Add application app = peripheral.Application() app.add_service(ukBaz_beacon) app.add_device_name('ukBazBeacon') # Start service and advertise try: app.start() except KeyboardInterrupt: print('KeyboardInterrupt') finally: app.stop() print('finally')
print('Turning LED off') switch_characteristic.send_notify_event(0) state_characteristic.send_notify_event(0) led.off() else: print('Turning LED on') state_characteristic.send_notify_event(1) switch_characteristic.send_notify_event(1) led.on() button.when_pressed = button_callback # Bluetooth # Service light_service = peripheral.Service('12341000-1234-1234-1234-123456789abc', True) print('**light service', light_service) # Swtich switch_characteristic = peripheral.Characteristic( '12341001-1234-1234-1234-123456789abc', ['read', 'write'], light_service, value=0) switch_characteristic.add_write_event(ble_state_callback) # Descriptor switch_descriptor = peripheral.UserDescriptor('Switch', switch_characteristic) switch_characteristic.add_descriptor(switch_descriptor) # Add characteristic light_service.add_characteristic(switch_characteristic)