Beispiel #1
0
    def find_bluetooth_adapter(self, tty_port=None):
        if tty_port is None:
            tty_port = self.find_tty()
        if tty_port is None:
            raise ValueError('Bluetooth adapter not found!')

        self.bluetooth = BLE(tty_port)
Beispiel #2
0
 def __init__(self, opc, name="ybb", rxbuf=1024):
     Consumer.__init__(self)
     self._ble = BLE()
     self._ble.active(True)
     self._ble.irq(self._irq)
     self._ble.config(gap_name = name[:16])
     ((self._tx_handle, self._rx_handle),) = self._ble.gatts_register_services((_UART_SERVICE,))
     # Increase the size of the rx buffer and enable append mode.
     self._ble.gatts_set_buffer(self._rx_handle, rxbuf, True)
     self._connections = {}
     self._rx_buffer = bytearray()
     self._opc = opc
     # Optionally add services=[_UART_UUID], but this is likely to make the payload too large.
     self._payload = advertising_payload(name=name[:16], appearance=_ADV_APPEARANCE_GENERIC_COMPUTER)
     self._advertise()
Beispiel #3
0
        raise EventTimeoutError()


def wait_for_event(irq, key, timeout_ms):
    start_time = time.ticks_ms()

    event_queue = _events[irq][key]

    while not event_queue:
        _maybe_raise_timeout(timeout_ms, start_time)
        machine.idle()

    return event_queue.popleft()


_ble = BLE()

gap_advertise = _ble.gap_advertise
gatts_register_services = _ble.gatts_register_services
gatts_read = _ble.gatts_read
gatts_write = _ble.gatts_write
gatts_set_buffer = _ble.gatts_set_buffer
gap_disconnect = _ble.gap_disconnect


def gap_scan(duration_ms, interval_us=None, window_us=None, timeout_ms=None):
    assert not (interval_us is None and window_us is not None), \
        "Argument window_us has to be specified if interval_us is specified"

    start_time = time.ticks_ms()
Beispiel #4
0
_IRQ_GATTC_SERVICE_RESULT = const(1 << 8)
_IRQ_GATTC_CHARACTERISTIC_RESULT = const(1 << 9)
_IRQ_GATTC_DESCRIPTOR_RESULT = const(1 << 10)
_IRQ_GATTC_READ_RESULT = const(1 << 11)
_IRQ_GATTC_WRITE_STATUS = const(1 << 12)
_IRQ_GATTC_NOTIFY = const(1 << 13)
_IRQ_GATTC_INDICATE = const(1 << 14)

#Global functions for the timer
time_after = time.time()
time_before = time.time()
timeCheck = False
global conn_handle

# create BLE variable
bt = BLE()

# set active to True initializing the bluetooth module
bt.active(1)

#adc for the battery level check
adc = machine.ADC(Pin(32))
val = adc.read()

# adding banner message to the device
print("****************************************************")
print("* SER 402 - Project 5 Trynkit                      *")
print("* Micropython on ESP32                             *")
print("* Battery Voltage:" + str(val))
print("****************************************************")
Beispiel #5
0
def create_battery_service():
    service = BatteryService(BLE())
    service.register_services()
    service.start()
    return service