Okay, well good news is you're getting the data from the advertisements. And the "hexstring" is 36, so as bytes it's 18 - which matches the C code.
:put [:len [:convert from=hex to=raw "0dff5900035e42000024684e29e80302e5fe"]]
18
To access the raw bytes, it not so simple in RouterOS script. Since you're starting with hexstring (e.g. base-16 bytes encoded as ASCII chars), you'd need to convert it to an array of ints to make it easy. Something like this function may help to convert the hex values to an array of type int.
Since that will get you an array, you can access the bytes and do any math like the C code. For example, the accelleration X/Y and temp using bit-wise operators from C (and the the slightly different index accessor ->)
So from your data it looks like 66º.
Some values might need more complex math tricks since there are NOT floating point values in script.
:put [:len [:convert from=hex to=raw "0dff5900035e42000024684e29e80302e5fe"]]
18
And, the decode-ad only support some known data structures mention in docs. Your device apparently isn't one, or close enough.[admin@MikroTik] > /iot bluetooth decode-ad data=0dff5900035e42000024684e29e80302e5fe
failure: No viable ad structure in raw data
this is what comes up when i do the decode data
To access the raw bytes, it not so simple in RouterOS script. Since you're starting with hexstring (e.g. base-16 bytes encoded as ASCII chars), you'd need to convert it to an array of ints to make it easy. Something like this function may help to convert the hex values to an array of type int.
Code:
:global hex2ints do={ :local hexdata $1 :local intarray [:toarray ""] :for i from=0 to=[:len $hexdata] step=2 do={ :set ($intarray->($i / 2)) [:tonum "0x$[:pick $hexdata $i ($i +2) ]"] } :return $intarray}
Since that will get you an array, you can access the bytes and do any math like the C code. For example, the accelleration X/Y and temp using bit-wise operators from C (and the the slightly different index accessor ->)
Code:
{:global hex2ints:local adhex "0dff5900035e42000024684e29e80302e5fe":local bytes [$hex2ints $adhex]:put $bytes:local temp (($bytes->6) & 0x7f):put "y=$($bytes->13) x=$($bytes->14) temp=$temp" }
13;255;89;0;3;94;66;0;0;36;104;78;41;232;3;2;229;254;
y=232 x=3 temp=66
So from your data it looks like 66º.
Some values might need more complex math tricks since there are NOT floating point values in script.
Statistics: Posted by Amm0 — Thu Apr 04, 2024 7:58 pm