question in python.
I was trying to get data from a BLE device,
The following bytearray was output.
b'\x32\x33\x30\x38\x31\x37\x32\x32\x34\x35'#2308172245
b'\x44\x31\x32\x35\x43\x30\x39\x34\x35' # D125C0945
I want to extract and format it as follows.
23/08/17/22:45
data : 12.5 command 0945
Two bytearrays are output and I want to format each of them.
Can you please tell me how to do this in a smart way?
Any help will be really appreciated.
I have tried to do the following, but I feel there is a bit of wasted movement and would like to know a better way. (Also not a decimal point.)
import datetime
# getdata = above data
data = (list(map(str,getdata.decode('utf-8'))))
if(data[0] == 'C' and len(data) == 9):
print(f"data : {(''.join(data[1:3]))} command {data[5:8]}")
elif(len(data) == 10):
m_time = datetime.datetime.strptime(''.join(data),'%y%m%d%H%M')
print(f"date&time : {m_time}")