0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Python3: GATT のデータを受信

Posted at

こちらで送信する 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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?