up device id for BLE device name
This commit is contained in:
parent
65b0f86732
commit
e655a75115
16
main.py
16
main.py
@ -2,7 +2,7 @@
|
||||
# OLT protocol.
|
||||
# Tomas Krejci [Njord]
|
||||
|
||||
import machine, time
|
||||
import machine, time, re
|
||||
from sys import platform
|
||||
|
||||
ESP32 = platform == "esp32"
|
||||
@ -14,10 +14,14 @@ else:
|
||||
from pyb import Pin, LED
|
||||
import uasyncio as asyncio
|
||||
|
||||
device_id = ""
|
||||
#### Device ID ###
|
||||
device_id_str = ""
|
||||
for b in machine.unique_id():
|
||||
device_id += "{:02X}".format(b)
|
||||
# device_id_hex = int(device_id)
|
||||
device_id_str += "{:02X}".format(b)
|
||||
|
||||
device_id_str = device_id_str[-4:] # Keep last 8 char
|
||||
device_id = int(device_id_str, 16) # Convert to int from hex in string
|
||||
# device_id_str = str(device_id, 16) # Convert back to hex print(f"{device_id:0x}")
|
||||
|
||||
#### BLE UART ###
|
||||
import ble_uart
|
||||
@ -30,7 +34,7 @@ def print_handler():
|
||||
|
||||
|
||||
ble = bluetooth.BLE()
|
||||
uart = ble_uart.Ble_uart(ble, on_rx=print_handler, name=print("LaserTag"))
|
||||
uart = ble_uart.Ble_uart(ble, on_rx=print_handler, name="OpenLaserTag " + device_id_str)
|
||||
|
||||
#### OLT IR RX imports ###
|
||||
import ustruct
|
||||
@ -155,7 +159,7 @@ async def cb(byte1, byte2, byte3, packet):
|
||||
async def main(proto):
|
||||
logger.debug("main start")
|
||||
|
||||
print(f"Device ID: {device_id}")
|
||||
print(f"Device ID: {device_id_str}")
|
||||
|
||||
### alive check ###
|
||||
asyncio.create_task(alive_check())
|
||||
|
Loading…
Reference in New Issue
Block a user