File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ # Connect to an "eval()" service over BLE UART.
2+
3+ from adafruit_ble import BLERadio
4+ from adafruit_ble .advertising .standard import ProvideServicesAdvertisement
5+ from adafruit_ble .services .nordic import UARTService
6+
7+ ble = BLERadio ()
8+
9+ uart_connection = None
10+
11+ while True :
12+ if not uart_connection :
13+ print ("Trying to connect..." )
14+ for adv in ble .start_scan (ProvideServicesAdvertisement ):
15+ if UARTService in adv .services :
16+ uart_connection = ble .connect (adv )
17+ print ("Connected" )
18+ break
19+ ble .stop_scan ()
20+
21+ if uart_connection and uart_connection .connected :
22+ uart_service = uart_connection [UARTService ]
23+ while uart_connection .connected :
24+ s = input ("Eval: " )
25+ uart_service .write (s .encode ("utf-8" ))
26+ uart_service .write (b'\n ' )
27+ print (uart_service .readline ().decode ("utf-8" ))
Original file line number Diff line number Diff line change 1+ # Provide an "eval()" service over BLE UART.
2+
3+ from adafruit_ble import BLERadio
4+ from adafruit_ble .advertising .standard import ProvideServicesAdvertisement
5+ from adafruit_ble .services .nordic import UARTService
6+
7+ ble = BLERadio ()
8+ uart = UARTService ()
9+ advertisement = ProvideServicesAdvertisement (uart )
10+
11+ while True :
12+ ble .start_advertising (advertisement )
13+ print ("Waiting to connect" )
14+ while not ble .connected :
15+ pass
16+ print ("Connected" )
17+ while ble .connected :
18+ s = uart .readline ()
19+ if s :
20+ try :
21+ result = str (eval (s ))
22+ except Exception as e :
23+ result = repr (e )
24+ uart .write (result .encode ("utf-8" ))
You can’t perform that action at this time.
0 commit comments