...
Try sending a test email to make sure that it is set up correctly.
System>Scripts
Monitoring a single trigger
Navigate to System>Scripts menu and add a new script there.
...
The rest of the script does not need to be changed.
Name the script however you like, for example, triggernotification. Click on Apply and OK.
Info | ||
---|---|---|
| ||
In this example, we are specifically showcasing an e-mail notification scenario. But! in case you want to use other methods for sending a notification, you can just alter the line below:
You can change the "do={/tool e-mail..." part of the line to, for example, "do={/tool fetch..." or "do={/iot mqtt publish...". That way, you can send out an HTTP post or MQTT publish message instead. If you would like to get a phone notification when the trigger is detected, you can also utilize IFTTT services (HTTP post to IFTTT webhook) as described in our other guide over here. |
...
You can run the script manually via the command "/system script run name_of_the_scripttriggernotification" or by clicking on the "Run Script" button under the Script List section.
You should make sure that the e-mail notification was received after manually initiating the script.
System>Scheduler
Multiple triggers script:
Monitoring multiple triggers
#User configuration:
#input the tag's mac address that you wish to monitor within the ""
:local addressRegex "2C:C8:1B:4B:BC:4E"
#enter trigger value, for example "04" for freefalling trigger and "02" for tilt trigger detection
:local triggervalueA "04"
:local triggervalueB "02"#name the trigger accordingly
:local triggernameA "freefalling"
:local triggernameB "tilt"#enter the message for the email body that you wish to receive within the ""
:local emailmessageA "Our tag fell down!"
:local emailmessageB "Our tag tilted!"#enter the subject for the email within the ""
:local emailsubject "RouterOS report!"#enter the email address wthin the ""
:local emailaddress "denisstestacc@gmailYOUR_EMAIL@gmail.com"###Bluetooth scanner
:local triggerA
:local triggerB
:put ("[*] Gathering Bluetooth info...")
:global btOldestAdvertisementTimestamp
:if ([:typeof $btOldestAdvertisementTimestamp] = "nothing") do={:set $btOldestAdvertisementTimestamp 0}
:local btProcessingStart [/system clock get time]
:local advertisements [/iot bluetooth scanners advertisements print detail \
as-value where \
epoch > $btOldestAdvertisementTimestamp and \
address ~ $addressRegex]
:local advCount 0
:local lastAdvTimestamp 0:foreach adv in=$advertisements do={
:local address ($adv->"address")
:local ad ($adv->"data")
:local ts ($adv->"epoch")
:local trig [:pick ($adv->"data") 40 42]
:set $advCount ($advCount + 1)
:set $lastAdvTimestamp $ts
:if ($trig="$triggervalueA") do={:set triggerA "$triggernameA"}
:if ($trig="$triggervalueB") do={:set triggerB "$triggernameB"}
:if ($advCount > 0) do={:set $btOldestAdvertisementTimestamp $lastAdvTimestamp}}:put ("[*] Found $advCount new advertisements \
(processing time: $[([/system clock get time] - $btProcessingStart)])")###Result
:if ($triggerA="$triggernameA") do={/tool e-mail send to=$emailaddress subject="$emailsubject" body="$emailmessageA"}
:if ($triggerB="$triggernameB") do={/tool e-mail send to=$emailaddress subject="$emailsubject" body="$emailmessageB"}
Use the script above as a reference. The script above scans for "tilt" and "freefall" triggers.
System>Scheduler
To automate the process add a new scheduler under the System>Scheduler tab:
Type in "/system script run triggernotification" under the "On Event:" field and set up an interval with which you wish to run the script to check/scan advertising reports (to, for example, 10 seconds).
Result verification
a) Confirm that the tag broadcasts advertising reports and that the tag's triggers get detected:
b) Confirm that your email server is set up correctly and that you are able to send emails from the KNOT (RouterOS).
c) After you manually run the script or apply a scheduler to the script, an email notification should go through, like so: