...
Monitoring multiple triggers
(a) For monitoring freefalling and tilt triggers, use the script:
#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 "YOUR_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"}
(b) For monitoring all possible triggers (those are freefalling, tilt, and movement against X, Y, Z, XY, XZ, XYZ, and YZ axis), use the script:
#User configuration:
#input the tag's mac address that you wish to monitor within the ""
:local addressRegex "2C:C8:1B:4B:BB:0A"
#enter trigger value, for example "04" for freefalling trigger and "02" for tilt trigger detection
:local triggervalueF "04"
:local triggervalueT "02"
:local triggervalueX "08"
:local triggervalueXY "18"
:local triggervalueXZ "28"
:local triggervalueXYZ "38"
:local triggervalueY "10"
:local triggervalueYZ "30"
:local triggervalueZ "20"
#name the trigger accordingly
:local triggernameF "freefalling"
:local triggernameT "tilt"
:local triggernameX "Xmovement"
:local triggernameXY "XYmovement"
:local triggernameXZ "XZmovement"
:local triggernameXYZ "XYZmovement"
:local triggernameY "Ymovement"
:local triggernameYZ "YZmovement"
:local triggernameZ "Zmovement"
#enter the message for the email body that you wish to receive within the ""
:local emailmessageF "Our tag fell down!"
:local emailmessageT "Our tag tilted!"
:local emailmessageX "Our tag moved against X axis!"
:local emailmessageXY "Our tag moved against X and Y axis!"
:local emailmessageXZ "Our tag moved against X and Z axis!"
:local emailmessageXYZ "Our tag moved against X,Y and Z axis!"
:local emailmessageY "Our tag moved against Y axis!"
:local emailmessageYZ "Our tag moved against Y and Z axis!"
:local emailmessageZ "Our tag moved against Z axis!"#enter the subject for the email within the ""
:local emailsubject "RouterOS report!"#enter the email address wthin the ""
:local emailaddress "YOUR_EMAIL@gmail.com"###Bluetooth scanner
:local triggerF
:local triggerT
:local triggerX
:local triggerXY
:local triggerXZ
:local triggerXYZ
:local triggerY
:local triggerYZ
:local triggerZ: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="$triggervalueF") do={:set triggerF "$triggernameF"}
:if ($trig="$triggervalueT") do={:set triggerT "$triggernameT"}
:if ($trig="$triggervalueX") do={:set triggerX "$triggernameX"}
:if ($trig="$triggervalueXY") do={:set triggerXY "$triggernameXY"}
:if ($trig="$triggervalueXZ") do={:set triggerXZ "$triggernameXZ"}
:if ($trig="$triggervalueXYZ") do={:set triggerXYZ "$triggernameXYZ"}
:if ($trig="$triggervalueY") do={:set triggerY "$triggernameY"}
:if ($trig="$triggervalueYZ") do={:set triggerYZ "$triggernameYZ"}
:if ($trig="$triggervalueZ") do={:set triggerZ "$triggernameZ"}:if ($advCount > 0) do={:set $btOldestAdvertisementTimestamp $lastAdvTimestamp}}
:put ("[*] Found $advCount new advertisements \
(processing time: $[([/system clock get time] - $btProcessingStart)])")###Result
:if ($triggerF="$triggernameF") do={/tool e-mail send to=$emailaddress subject="$emailsubject" body="$emailmessageF"}
:if ($triggerT="$triggernameT") do={/tool e-mail send to=$emailaddress subject="$emailsubject" body="$emailmessageT"}
:if ($triggerX="$triggernameX") do={/tool e-mail send to=$emailaddress subject="$emailsubject" body="$emailmessageX"}
:if ($triggerXY="$triggernameXY") do={/tool e-mail send to=$emailaddress subject="$emailsubject" body="$emailmessageXY"}
:if ($triggerXZ="$triggernameXZ") do={/tool e-mail send to=$emailaddress subject="$emailsubject" body="$emailmessageXZ"}
:if ($triggerXYZ="$triggernameXYZ") do={/tool e-mail send to=$emailaddress subject="$emailsubject" body="$emailmessageXYZ"}
:if ($triggerY="$triggernameY") do={/tool e-mail send to=$emailaddress subject="$emailsubject" body="$emailmessageY"}
:if ($triggerYZ="$triggernameYZ") do={/tool e-mail send to=$emailaddress subject="$emailsubject" body="$emailmessageYZ"}
:if ($triggerZ="$triggernameZ") do={/tool e-mail send to=$emailaddress subject="$emailsubject" body="$emailmessageZ"}
You can just use a script (b )that detects all possible Use the script above as a reference. The script above scans for "tilt" and "freefall" triggers.
System>Scheduler
...