我知道对蓝牙的支持还在开发中,但目前它似乎涵盖了我需要的一切,所以我决定试一试。
我只想模拟从数据源( EKG机器)读取数据,所以我想出了这个代码:
from ubluetooth import BLE
from ubluetooth import FLAG_READ, FLAG_NOTIFY, FLAG_WRITE
import time
ekg_data = [-305,-431,-131,440 ,1158,1424,1445,1623,1500,1018,142 ,-384,-324,-414,-77 ,334 ,-372,-154,366 ,7613,1461,1403,6133,-179,-381,-224,-135,-168,-208,-187,-181,-180,-160,-160,-151,-150,-151,-138,-141,-128,-118,-106,-798,-677,-430,-253,-122,98 ,133 ,281 ,354 ,390 ,519 ,475 ,558 ,565 ,533 ,593 ,458 ,377 ,107 ,-335,-719,-116,-129,-132,-131,-119,-122,-111,-106,-105,-935,-971,-877,-841,-841,-725,-757,-660,-641,-660,-554,-592,-496,-473,-486,-387,-431,-350,-364,-347,-208,-365,-362]
bt = BLE()
bt.active(True)
print('----')
print(bt.config('mac'))
print(bt.config('gap_name'))
HR_UUID = bluetooth.UUID(0x180D)
HR_CHAR = (bluetooth.UUID(0x2A37), bluetooth.FLAG_READ | bluetooth.FLAG_NOTIFY,)
HR_SERVICE = (HR_UUID, (HR_CHAR,),)
SERVICES = (HR_SERVICE,)
((ekg,),) = bt.gatts_register_services(SERVICES)
# bt.gap_advertise(100, 'MicroPython EKG')
count = 0
while True:
if count >= len(ekg_data):
count = 0
bt.gatts_write(ekg, ekg_data[count].to_bytes(2, 'big'))
print(ekg_data[count])
time.sleep_ms(1000)
count += 1现在代码编译并运行(我可以在控制台上看到输出),但我在蓝牙应用程序中找不到设备(我使用的是北欧应用程序)
在这方面有更多知识的人能告诉我我是否忽略了什么吗?我试图时断时续地去掉广告,因为我认为我可能会用它覆盖一些东西,但这也没有帮助……
https://stackoverflow.com/questions/62444152
复制相似问题