Skip to content

Commit eb0ef66

Browse files
committed
Small delay before resetart
This avoids getting errors on the Browser side.
1 parent 44823de commit eb0ef66

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

lib/ble/ble_uart_peripheral.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#from .ble_advertising import advertising_payload
55
import struct
66
from micropython import const
7+
from machine import Timer
78

89
#Advertise info
910
# org.bluetooth.characteristic.gap.appearance.xml
@@ -47,6 +48,12 @@
4748
(_UART_TX, _UART_RX, _UART_DATA_RX, _UART_DATA_TX,),
4849
)
4950

51+
_timer = Timer(-1)
52+
53+
def delayedRestart(_arg):
54+
import machine
55+
machine.reset()
56+
5057
class BLEUART:
5158
def __init__(self, ble, name="mpy-uart", rxbuf=100):
5259
self._ble = ble
@@ -86,8 +93,8 @@ def _irq(self, event, data):
8693
FILE_PATH = '/lib/ble/isrunning'
8794
with open(FILE_PATH, 'r+b') as file:
8895
file.write(b'\x01')
89-
import machine
90-
machine.reset()
96+
# slight delay to avoid errors on the browser side.
97+
_timer.init(mode=Timer.PERIODIC, period=50, callback=delayedRestart)
9198
elif conn_handle in self._connections and value_handle == self._data_rx_handle:
9299
new_data = self._ble.gatts_read(self._data_rx_handle)
93100
if self._data_callback:

0 commit comments

Comments
 (0)