From d57263f643f63b1540dfd16ff764d02f7709960e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cnjord=E2=80=9D?= <“git@tomaskrejci.com”> Date: Wed, 15 May 2024 00:48:24 +0200 Subject: [PATCH] BLE remote.py running --- ble_main.py | 68 +++++++++++++ ble_main_2.py | 80 +++++++++++++++ main.py | 271 +++++++++++++++++++++++++++++++++++++++++--------- remote.py | 247 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 620 insertions(+), 46 deletions(-) create mode 100644 ble_main.py create mode 100644 ble_main_2.py create mode 100644 remote.py diff --git a/ble_main.py b/ble_main.py new file mode 100644 index 0000000..6608db2 --- /dev/null +++ b/ble_main.py @@ -0,0 +1,68 @@ +import sys + +sys.path.append("") + +from micropython import const + +import uasyncio as asyncio +import aioble +import bluetooth + +import random +import struct + +# org.bluetooth.service.environmental_sensing +_ENV_SENSE_UUID = bluetooth.UUID(0x181A) +# org.bluetooth.characteristic.temperature +_ENV_SENSE_TEMP_UUID = bluetooth.UUID(0x2A6E) +# org.bluetooth.characteristic.gap.appearance.xml +_ADV_APPEARANCE_GENERIC_THERMOMETER = const(768) + +# How frequently to send advertising beacons. +_ADV_INTERVAL_MS = 250_000 + + +# Register GATT server. +temp_service = aioble.Service(_ENV_SENSE_UUID) +temp_characteristic = aioble.Characteristic( + temp_service, _ENV_SENSE_TEMP_UUID, read=True, notify=True +) +aioble.register_services(temp_service) + + +# Helper to encode the temperature characteristic encoding (sint16, hundredths of a degree). +def _encode_temperature(temp_deg_c): + return struct.pack("