I have this hex code F0C2CA89012A04008C0000000000000000000000 from the device. This hex code shows the value of the water drops.
In my python code
msg = F0C2CA89012A04008C0000000000000000000000
msg_counters = bytes.fromhex(msg)[5:20]
# output: b'*x04x00x8cx00x00x00x00x00x00x00x00x00x00x00'
msg_counters_int = int.from_bytes(msg_counters)
# output: 218157641024778742068286256301735936
bin_string = '{:0120b}'.format(msg_counters_int)
print(bin_string)
this print the value of bits. These bits shows the value of water
001010100000010000000000100011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00101 = 5
01000 = 8
00010 = 2
I’m trying to convert the code to PHP and I’m stuck in int.from_bytes
from python. I don’t know how to convert the value.
In my PHP code
$a = hex2bin("F0C2CA89012A04008C0000000000000000000000");
$b = substr($a, 5, 20);
// output: b"*x04x00Œx00x00x00x00x00x00x00x00x00x00x00"
I tried to use unpack
functionality but it doesn’t show the correct value