I need to obtain a timestamp for every scan data with the current date and time. However, I am facing some issues with getting the correct time and date values.
I have made changes to the current time in sopas engineering tool, the obtained data still shows the wrong time and date.
I suspect that there might be an error in how I am converting the timestamp. Could someone please guide me on the correct way to obtain and convert the timestamp for accurate time and date representation?
This is the data that i get from the lms111 sensor
sRA LMDscandata 1 1 1195F7E 0 0 5DD8 5DDB BB7E993F BB7EF691 0 0 FF 7 0 1388 168 0 1 DIST1 3F800000 00000000 AAE60 1388 51 515 502 4FC 501 50F 4F0 4F7 501 4E1 4EA 4EC 4F3 4D2 4D7 4E4 4D2 4CD 4CF 4E1 4C5 4D4 4D7 4D5 4D9 4D0 4CD 4D3 4D3 4C8 4C5 4C8 4D5 4D3 4C6 4C6 4C0 4C8 4C1 4CD 4CE 4C9 4CA 4D4 4C8 4C8 4D4 4CE 4C4 4D1 4CA 4C4 4C3 4CF 4DC 4D8 4C3 4D2 4C5 4C8 4D3 4CD 4CB 4CE 4DB 4E8 4E8 4DB 4EB 4EE 4EC 4F4 4E3 4EF 4F1 4F6 510 4FD 4FE 503 508 508 0 0 1 3 SL2 0 1 7B2 1 1 0 34 19 6AB08 0
The bold numbers that i convert into timestamp
def hex_to_date(hex_value):
try:
hex_value = hex_value.replace("0x", "")
decimal_value = int(hex_value, 16)
timestamp = datetime.datetime.fromtimestamp(decimal_value)
return timestamp.strftime("%Y-%m-%d %H:%M:%S")
except ValueError:
return "Invalid hexadecimal value"
hex_value = "BB7EF691"
date = hex_to_date(hex_value)
print(date)```
This is the answer that i got 2069-09-06 02:27:29.
But expected answer is the current date and time.
Any help or suggestions would be greatly appreciated. Thank you!