こちらで送信する String を Python で受信しました。
ESP32: GATT で String を送信
送信元のアドレスと Characteristic UUID が必要です。
プログラム
get_data.py
#! /usr/bin/python
#
# get_data.py
#
# Oct/02/2024
# ------------------------------------------------------------------
import asyncio
from bleak import BleakClient
DEVICE_ADDRESS = "08:3A:F2:66:04:4A"
CHARACTERISTIC_UUID = "00002a19-0000-1000-8000-00805f9b34fb"
async def read_characteristic(address, char_uuid):
async with BleakClient(address) as client:
data = await client.read_gatt_char(char_uuid)
return data
#
# ------------------------------------------------------------------
async def main():
for it in range(3):
data = await read_characteristic(DEVICE_ADDRESS, CHARACTERISTIC_UUID)
print("Data:", data)
print("Data:", data.decode())
#
# ------------------------------------------------------------------
asyncio.run(main())
# ------------------------------------------------------------------
実行結果
$ ./get_data.py
Data: bytearray(b'Battery: 44475')
Data: Battery: 44475
Data: bytearray(b'Battery: 44900')
Data: Battery: 44900
Data: bytearray(b'Battery: 45375')
Data: Battery: 45375