예제 #1
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)
예제 #2
0
    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)
예제 #3
0
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

예제 #4
0
        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)

# state
state_characteristic = peripheral.Characteristic(
    '12341002-1234-1234-1234-123456789abc', ['notify'], light_service, value=0)
state_characteristic.add_notify_event(ble_state_callback)
state_characteristic.StartNotify()