android 下需先安裝 BLE Scanner app,觀看時請按 notify 才會及時更新數值
# 範例十八:
# 用手機 BLE Scanner app 來觀看 ESP32 溫度
# 手機需安裝 BLE Scanner app
# 需要的 module : ble_uart,tools,const
# FB : https://www.facebook.com/mason.chen.1420
import ubluetooth as bt
from ble_uart import BLEUART
from tools import BLETools
from const import BLEConst
from machine import Pin
import esp32
from time import sleep
def rx_callback(data):
print((data))
if (data) == (b'on'):
Pin(12, Pin.OUT).value(1)
if (data) == (b'off'):
Pin(12, Pin.OUT).value(0)
ble = bt.BLE(); uart = BLEUART(ble, rx_callback,name="esp32_sender")
while True:
uart.send((str((((esp32.hall_sensor()-32.0)/1.8))))+'')
sleep(1)