micropython / micropython/micropython-lib

"Why am I unable to read the keyboard input?"

Open
#984 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.9k
Forks
1.1k
Avg merge
7d 6h
Merged PRs (30d)
3

Description

import aioble
import asyncio
import bluetooth

async def scan_bluetooth():
print("Starting BLE scan...")
async with aioble.scan(
duration_ms=10000, # 扫描 10 秒
interval_us=300000, # 间隔 300 毫秒
window_us=300000, # 窗口 300 毫秒
active=True # 主动请求额外数据
) as scanner:
async for result in scanner:
name = result.name() or "Unknown"
addr = result.device.addr_hex()
rssi = result.rssi
services = result.services()

        if "0d:f9:6d:6a:75:c9" in addr:
            print("找到此设备")
            print(result.services)
            return result.device
return None

async def main():
device = await scan_bluetooth()
if not device:
print("未找到设备")
return

try:
    print(f"正在连接 {device.addr_hex()}...")
    connection = await device.connect(timeout_ms=2000)  # 设置连接超时
    print("连接成功",connection)


except asyncio.TimeoutError:
    print("连接超时")
except Exception as e:
    print(f"连接失败: {e}")
async with connection:
    try:
        hid_service=0x1812
        key_input=0x2A4D
        mouse_input=0x2A33
        
        ser=bluetooth.UUID(hid_service)
        char=bluetooth.UUID(key_input)
        hid_service = await connection.service(ser)
        print(hid_service)
        hid_characteristic = await hid_service.characteristic(char)
        print(hid_characteristic)
    except asyncio.TimeoutError:
        print("Timeout discovering services/characteristics")
        return
    while True:
            # 尝试读取特征的值
        data = await hid_characteristic.read()
        print("Received key input data:", data)

运行主程序

asyncio.run(main())

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the pasted asyncio.run(main()) entry point and reproduce the connection and read loop. Inspect the BLE HID service and characteristic identifiers shown in the example; done means the reason keyboard input cannot be read is established and a verified correction is identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.