Exemple #1
0
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()
Exemple #2
0
 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)
    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)
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


def worker():
    try:
        print("Allowing the first app {} secs to run.".format(TOGGLE_DELAY))
        sleep(TOGGLE_DELAY)
        while True:
            print("App1 down, App2 up")
            app1.stop()
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')
    '12341002-1234-1234-1234-123456789abc', ['notify'], light_service, value=0)
state_characteristic.add_notify_event(ble_state_callback)
state_characteristic.StartNotify()

# Descriptor
state_descriptor = peripheral.UserDescriptor('State', state_characteristic)
state_characteristic.add_descriptor(state_descriptor)

# Add characteristic
light_service.add_characteristic(state_characteristic)

for mngd_objcs in light_service.GetManagedObjects():
    print('Managed Objects: ', mngd_objcs)

# Add application [new in 5.38]
app = peripheral.Application('/org/bluez/hci0')
app.add_service(light_service)

app.add_device_name('BluezeroLight')

# Start service and advertise
try:
    app.start()
except KeyboardInterrupt:
    button.when_pressed = None
    print('KeyboardInterrupt')
finally:
    button.when_pressed = None
    app.stop()
    print('finally')