Community discussions

MikroTik App
 
scampbell
Trainer
Trainer
Topic Author
Posts: 487
Joined: Thu Jun 22, 2006 5:20 am
Location: Wellington, NZ
Contact:

KNOT Bluetooth Dongle and Relay Example

Fri Aug 27, 2021 7:11 am

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.

Image

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).

Image

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
You do not have the required permissions to view the files attached to this post.
 
almeiras
newbie
Posts: 39
Joined: Fri Nov 15, 2019 9:16 pm
Location: Spain

Re: KNOT Bluetooth Dongle and Relay Example

Fri Sep 10, 2021 10:37 am

Loved it. I just found out about the MT Knot. Looks to be a great device for getting started in IoT. Too bad the non-LoRa version does not include mPCIe slot for future upgrades.
 
Verners
just joined
Posts: 1
Joined: Tue Mar 28, 2023 8:06 pm

Re: KNOT Bluetooth Dongle and Relay Example

Tue Mar 28, 2023 9:28 pm

I built the same circuit for testing and was happy that the outputs could be driven from the MK Knot... until I turned off the power to the Knot. The outputs are no longer controlled. They pass current and the relays turn on. Only after the system is fully loaded, the outputs are inactive. In practice, these outputs are uncontrollable and unusable.

Who is online

Users browsing this forum: No registered users and 3 guests