Community discussions

MikroTik App
 
misko67
just joined
Topic Author
Posts: 3
Joined: Fri Aug 27, 2021 12:01 pm

IoT MQTT Bluetooth Script by MikroTik

Sun Nov 28, 2021 1:14 am

Dear MikroTik friends,
have any of you looked into the KNOT's bluetooth scanner in conjunction with the TG-BT5-IN or TG-BT5-OUT?
As far as I understood the instructions and the script (https://help.mikrotik.com/docs/pages/vi ... ptscenario), the KNOT should send the scanned Bluetooth information via MQTT. Something is also sent via MQTT but there is no data of the detected Bluetooth devices included.
Here an example:
{"clientId":"KNOT-01","t":0,"v":1,"OldestAdvertisementTimestamp":0,"locs":[{"id":"2CC81B84xxx","tags":[],"ed":{"model":"RB924i-2nD-BT5&BG77","sn":"E0FD0E56xxx","ros":"6.49","cpu":28,"umem":23117824,"fmem":43991040,"psu":0,"temp":0}}]}

I would have expected the script to also send information of the scanned Bluetooth devices via MQTT, which unfortunately is not the case. Since MQTT data is sent, the script also seems to work in principle. I did not change anything in the script itself, except that I have changed the name of the MQTT server (:local broker "Demo Device") to mine.

I first thought that there might be too many Bluetooth devices that are seen and therefore none are sent via MQTT and have set up a whitelist in which two devices are included. But that didn't help either.

Are you aware of a problem or bug? The software I use is the 6.49 version.
Further I would be interested if someone knows what the HEX data of the TG-BT5-IN / OUT tags mean. I would have expected that these are documented somewhere and that they can be evaluated for example in Node-Red. I would be happy if someone could help me and the colleagues from MikroTik improve the documentation a bit.

Best Regards,
Ivan

Meanwhile I tried to interpret the script. Currently I would say that in the MQTT output no parameters from the Bluetooth part are. I´ve attached the MQTT Part and hope somebody can find the bug.

#################################### MQTT #####################################
:local message \
"{\
\"clientId\":\"$[/iot mqtt brokers get value-name=client-id \
[/iot mqtt brokers find name=$broker]]\",\
\"t\":0,\
\"v\":1,\
\"OldestAdvertisementTimestamp\":$btOldestAdvertisementTimestamp,\
\"locs\":[{\
\"id\":\"$[$minimizeMac address=$ifaceMac]\",\
\"tags\":[$advJson],\
\"ed\":{\
\"model\":\"$model\",\
\"sn\":\"$serialNumber\",\
\"ros\":\"$rosVersion\",\
\"cpu\":$cpuLoad,\
\"umem\":$usedMemory,\
\"fmem\":$freeMemory,\
\"psu\":$supplyVoltage,\
\"temp\":$boardTemp\
}\
}]\
}"
:log info "$message";
:put ("[*] Total message size: $[:len $message] bytes")
:put ("[*] Sending message to MQTT broker...")
/iot mqtt publish broker=$broker topic=$topic message=$message
:put ("[*] Done")

You can find the coplete script here:
https://help.mikrotik.com/docs/pages/vi ... ptscenario
 
denissMT
MikroTik Support
MikroTik Support
Posts: 49
Joined: Wed May 26, 2021 12:00 pm

Re: IoT MQTT Bluetooth Script by MikroTik

Mon Dec 20, 2021 1:56 pm

Try applying filters to the script:
# POSIX regex for filtering advertisement Bluetooth addresses. E.g. "^BC:33:AC"
# would only include addresses which start with those 3 octets.
# To disable this filter, set it to ""
:local addressRegex ""

# Signal strength filter. E.g. -40 would only include Bluetooth advertisements
# whose signal strength is stronger than -40dBm.
# To disable this filter, set it to ""
:local rssiThreshold "-40"

Try using RSSI or/and MAC address filters.

If it brings no results, please create a support ticket in our system:
https://mikrotik.com/support

HEX payload of the tag is explained in the guide over at:
https://help.mikrotik.com/docs/display/ ... nt+formats

Who is online

Users browsing this forum: druidgtx and 15 guests