With 5 minutes on hand I have setup a quick example application for a KNOT with DC Relay's attached to work as an access control system using Bluetooth Dongles w/button.
The dongle is a generic one from Ali Express with button push feature.
The objective was to be able to toggle the relay with a push of the Dongle Button - purely for fun although there will be some serious use for this down the line.......
The dongle has a unique MAC address on the back and this is entered into the KNOT so it is aware of the dongle:not Config:
/iot bluetooth whitelist
add address=C5:xx:xx:xx:xx:Bx address-type=random device=bt1
add address=F1:xx:xx:xx:xx:Dx address-type=random device=bt1
/iot bluetooth scanners
set filter-policy=whitelist
filter-duplicates=keep-newest
The above restricts the Blutooth to accept input only from these known Bluetooth dongles - otherwise every Bluetooth device in my lab was coming through on the Data Screen including phones. Instead of the dongle I suspect an APP on the phone should also be suitable.
The other setting only keeps the newest entry in the data list. This can be disabled during initial testing if required.
Next I had to identify the data coming from the dongle and see what changed when I pushed the button......
/iot bluetooth scanner advertisement print
In my case both devices sent data ending in 640000 which changed to 640001 when the button was pushed. Other devices may behave differently.
The relay was connected to the GPIO pin4 and was an OMRON DC24V relay. Note Mikroitk KNOT switches to ground so apply +24V to the relay and then the negative of the relay to pin4 and power negative to GPIO pin 1. +(DC)----relay---GPIO4-----Gnd (- DC).
The script below detects when the data changes and toggles the relay on and off - it needs work to "debounce" it as sometimes the diongle sends data through repetitively.
Remember this is only a proof of concept test
:global loop "loop"
:do {
:global button [/iot bluetooth scanners advertisement find data~"640001"];
:if ($button != "") do={
:if ( [/system gpio get pin4 output] =0 ) do={ [/system gpio set pin4 output=1]; :delay 4 } else={ [/system gpio set pin4 output=0]; :delay 4 };
};
/iot bluetooth scanners advertisement clear
} while ($loop ="loop");
Things to do:
1. Find a decent GPIO 6 Pin breakout lead - mine was a hacked lead from an Arduino.
2. Improve script for more functionality and edgecase scenario's