Community discussions

MikroTik App
 
User avatar
Andrew162
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Thu Mar 25, 2021 9:40 am

Beep sound wifi device connect/disconnet

Mon Mar 29, 2021 10:47 am

Hello
Is there a way to make mikrotik make a sound/music when wifi device connet and disconnect?
for example i connect phone by wifi to mikrotik and he play beep song
i disconnect and play sad song (mario die)
its will be awesome :)
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Beep sound wifi device connect/disconnet

Mon Mar 29, 2021 12:09 pm

There are not a quick way to do it. You have too look at log and if it see a line some like this, then send a beep.
wireless,info MikroTik: EA:XX:XX:92:EB:0E@wlan: connected, signal strength -80
This need to be scheduled, so it will not be real time.
I will have look at it to see if there are other options. Maybe use a while loop (this may use some cpu)
 
User avatar
Andrew162
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Thu Mar 25, 2021 9:40 am

Re: Beep sound wifi device connect/disconnet

Mon Mar 29, 2021 12:56 pm

im tootaly noob in this

its will look somethink like that??

# Check if log message how this (in this situation ethernet port 5 disconnect)
:local scheduleName "scheduleName"
:local startBuf [:toarray [/log find message~"ether5link up"]]
:local removeThese


# Do this - play song
:if ([:len [/system scheduler find name="$scheduleName"]] = 0) do={
/:beep frequency=660 length=100ms;
:delay 150ms;
:beep frequency=660 length=100ms;
:delay 300ms;
}
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Beep sound wifi device connect/disconnet

Mon Mar 29, 2021 1:45 pm

This should let you go
:global run 
:local loginfo
:local prevlog
:while ($run=1)  do={
	
	:set loginfo [/log find time>([/system clock get time] - 2s) topics~"wireless" message~": connected"]
	if ($loginfo!=$prevlog and [:len $prevlog]=0)  do={
		:beep frequency=10000 length=1s
		}
	:set prevlog $loginfo
	:delay 1
	}
Save the code to a script.
Set run to 1 like this
:global run "1"
Run the script
To stop the script, set run=0
:global run "0"

There are several problems with this script.
1. If there are many changes within 1 second, it will beep only once
2. It uses CPU.
3. Does not restarts itself when reboot
4. Not all routers have speaker.

There may be better way to do it.
 
User avatar
Andrew162
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Thu Mar 25, 2021 9:40 am

Re: Beep sound wifi device connect/disconnet

Mon Mar 29, 2021 2:33 pm

acording to your script
(becaouse im in job right now (have only eth with beeper)- dont have here mikrotik with wifi and beeper
in home i got audience = got speaker

:global run
:local loginfo
:local prevlog
:while ($run=1) do={

:set loginfo [/log find time>([/system clock get time] - 2s) topics~"interface, info" message~": down"]
if ($loginfo!=$prevlog and [:len $prevlog]=0) do={
:beep frequency=600 length=1s
}
:set prevlog $loginfo
:delay 1
}

is that should work for "unplug" the eth5?
in log its Topics : interface, info message : ether5 link down
if yes
that dont work :/

Paste the script to scheduler or scripts?
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Beep sound wifi device connect/disconnet

Mon Mar 29, 2021 3:11 pm

Do you need a script for connecting ethernet ports or wifi connecting devices?
 
User avatar
Andrew162
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Thu Mar 25, 2021 9:40 am

Re: Beep sound wifi device connect/disconnet

Mon Mar 29, 2021 3:21 pm

for Wifi
but i was think it will work also for ethernet
Will be also cool if some device disconnect ( ethernet)
will beep (ether1 ) 1 ( ether2 down ) beep twice /or difrent music

but most important is Wifi connect sound / dissconnect sound
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Beep sound wifi device connect/disconnet

Mon Mar 29, 2021 3:25 pm

It will work for all.
Just look in the log how it looks like while connecing/disconnecing wifi/ethernet. Change script to look for data in that line.
 
User avatar
Andrew162
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Thu Mar 25, 2021 9:40 am

Re: Beep sound wifi device connect/disconnet

Mon Mar 29, 2021 3:31 pm

dont work for now.
System-> Scripting + then
https://prnt.sc/10yzk2o
Its look like this

then i press Run Script
then in terminal
:global run "1" (enter)

i unplug cable eth4
in log show ether4 link down
but no sound
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Beep sound wifi device connect/disconnet

Mon Mar 29, 2021 7:00 pm

You have modified the script look for eth down?
Script I made only search for Wifi connected. (1 of 4 option in connecting/disconnecting wifi/eth)
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Beep sound wifi device connect/disconnet

Mon Mar 29, 2021 9:36 pm

Updated version that should not miss any message, since it test number of message and then compare 1 and 1.
But not 100% sure what happens when log reaches 999 entry.
You can add as many test as you like, since it reads all log entry 1 by one.


:global run 
:local LogInfo
:local LogLength
:local LogTopic
:local LogMessage
:local PrevLogLength 99999
:while ($run=1)  do={
	:set LogInfo [:toarray [:log find ]]
	:set LogLength ([:len $LogInfo]-1)
	if ($PrevLogLength<$LogLength) do={
		:for Loop from ($PrevLogLength+1) to $LogLength do={
			:set LogTopic [:log get [:pick $LogInfo $Loop] topics]
			:set LogMessage [:log get [:pick $LogInfo $Loop] message]
			
			# Test section
			# ------------
			
			# Test if Wifi going up
			:if ($LogTopic~"wireless" and $LogMessage~": connected") do={
				:put "wifi connected"
				}
			
			# Test if Wifi going down
			:if ($LogTopic~"wireless" and $LogMessage~": disconnected") do={
				:put "wifi disconnected"
				}
			
			# Test if eth going up
			:if ($LogTopic~"interface" and $LogMessage~"up") do={
				:put "ethernet up"
				}
			
			# Test if eth going down
			:if ($LogTopic~"interface" and $LogMessage~"down") do={
				:put "ethernet down"
				}
				
			# ----------------
			# End Test section
			}
		}
	:set PrevLogLength $LogLength
	:delay 1s
	}
 
User avatar
Andrew162
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Thu Mar 25, 2021 9:40 am

Re: Beep sound wifi device connect/disconnet

Tue Mar 30, 2021 8:11 am

its seems to not working i think
CPU 0%
no beep sound ( in code i also not recognise any beep sound )
the script counter dont "count" also

but i COUNT on you to make it done to work flewless :)
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Beep sound wifi device connect/disconnet

Tue Mar 30, 2021 12:59 pm

Script is just a proof of concept. It does print message to terminal, no beep. (do not have beep on my router)
You need to change the lines :put "wifi connected" to some with beeps within them.

You also need to set
:global run 1
To make it run.

Add { } around the whole script and copy past terminal and it should run fine from there.
 
freemannnn
Forum Veteran
Forum Veteran
Posts: 700
Joined: Sun Oct 13, 2013 7:29 pm

Re: Beep sound wifi device connect/disconnet

Tue Mar 30, 2021 1:23 pm

FYI At DHCP SERVER there is an option to run a script when a new device gets an IP. this will work for connection but not for disconnection of device
 
User avatar
Andrew162
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Thu Mar 25, 2021 9:40 am

Re: Beep sound wifi device connect/disconnet

Tue Mar 30, 2021 1:32 pm

{:global run 
:local LogInfo
:local LogLength
:local LogTopic
:local LogMessage
:local PrevLogLength 99999
:while ($run=1)  do={
	:set LogInfo [:toarray [:log find ]]
	:set LogLength ([:len $LogInfo]-1)
	if ($PrevLogLength<$LogLength) do={
		:for Loop from ($PrevLogLength+1) to $LogLength do={
			:set LogTopic [:log get [:pick $LogInfo $Loop] topics]
			:set LogMessage [:log get [:pick $LogInfo $Loop] message]
			
			# Test section
			# ------------
			
			# Test if Wifi going up
			:if ($LogTopic~"wireless" and $LogMessage~": connected") do={
				:put "wifi connected"
				}
			
			# Test if Wifi going down
			:if ($LogTopic~"wireless" and $LogMessage~": disconnected") do={
				:put "wifi disconnected"
				}
			
			# Test if eth going up
			:if ($LogTopic~"interface" and $LogMessage~"up") do={
				:put "ethernet up"
:beep frequency=770 length=100ms;
:delay 550ms;
:beep frequency=380 length=100ms;
:delay 575ms;
				}
			
			# Test if eth going down
			:if ($LogTopic~"interface" and $LogMessage~"down") do={
				:put "ethernet down"
:beep frequency=660 length=100ms;
:delay 150ms;
				}
				
			# ----------------
			# End Test section
			}
		}
	:set PrevLogLength $LogLength
	:delay 1s
	}}
Work GREAT for Ethernet ON and OFF :)
Need arround 5 sec wait until "next" thing happen but i guess nobody will connect in same second
# Test if eth going down
			:if ($LogTopic~"interface" and $LogMessage~"down") do={
				:put "ethernet down"
:beep frequency=660 length=100ms;
:delay 150ms;
can i edit this somethink like ethernet 2 down" or ethernet 3 down difrent command line
so difrent "beep" ?

Also CPU is great usage 0-1%
 
User avatar
Andrew162
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Thu Mar 25, 2021 9:40 am

Re: Beep sound wifi device connect/disconnet

Tue Mar 30, 2021 1:37 pm

freemannnn

But its work for new device i guess?
I need for every device difrent sound
 
User avatar
Andrew162
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Thu Mar 25, 2021 9:40 am

Re: Beep sound wifi device connect/disconnet

Tue Mar 30, 2021 3:00 pm

{:global run 
:local LogInfo
:local LogLength
:local LogTopic
:local LogMessage
:local PrevLogLength 99999
:while ($run=1)  do={
	:set LogInfo [:toarray [:log find ]]
	:set LogLength ([:len $LogInfo]-1)
	if ($PrevLogLength<$LogLength) do={
		:for Loop from ($PrevLogLength+1) to $LogLength do={
			:set LogTopic [:log get [:pick $LogInfo $Loop] topics]
			:set LogMessage [:log get [:pick $LogInfo $Loop] message]
			
			# Test section
			# ------------

			
			# Test if Wifi going up
			:if ($LogTopic~"wireless" and $LogMessage~": connected") do={
				:put "wifi connected"
:beep frequency=660 length=100ms;
:delay 150ms;
:beep frequency=960 length=100ms;
:delay 300ms;
				}
			
			# Test if Wifi going down
			:if ($LogTopic~"wireless" and $LogMessage~": disconnected") do={
				:put "wifi disconnected"
:beep frequency=960 length=100ms;
:delay 150ms;
:beep frequency=660 length=100ms;
:delay 300ms;
				}
			
			# Test if eth going up
			:if ($LogTopic~"interface" and $LogMessage~"up") do={
				:put "ethernet up"
:beep frequency=260 length=100ms;
:delay 150ms;
:beep frequency=660 length=100ms;
:delay 300ms;
				}
			
			# Test if eth going down
			:if ($LogTopic~"interface" and $LogMessage~"down") do={
				:put "ethernet down"
:beep frequency=660 length=100ms;
:delay 150ms;
:beep frequency=260 length=100ms;
:delay 300ms;
				}
				
			# ----------------
			# End Test section
			}
		}
	:set PrevLogLength $LogLength
	:delay 1ms
	}}
After some tweaks i fnish with that with basic sound of connect and disconnect
also change the :delay 1s to 1ms = react faster almost instant
And work great

Now i will try add mario dead sound for wifi disconnect
some sound of finish bos in game boy when wifi connect

Then some adds like for eth1 eth2 etc difrent sounds for each one
... Work in progress
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Beep sound wifi device connect/disconnet

Tue Mar 30, 2021 11:38 pm

Warning!!!

Try paste this command line:
:delay 1ms
You will get a warning like this:
Warning: value of delay-time was rounded down to 0s
And this is not a good thing. Look at CPU load. My router goes from 0-1% to 25% CPU usage.
 
User avatar
Andrew162
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 64
Joined: Thu Mar 25, 2021 9:40 am

Re: Beep sound wifi device connect/disconnet

Wed Mar 31, 2021 8:01 am

Warning!!!

Try paste this command line:
:delay 1ms
You will get a warning like this:
Warning: value of delay-time was rounded down to 0s
And this is not a good thing. Look at CPU load. My router goes from 0-1% to 25% CPU usage.
16 devices connected - so its have some "load"
and 0% .. rare 2% usage with RB3011UiAS (arm) mikrotik

DO not press Run Script
Just apply
After press Run script its go 25% :) just in terminal :global run "1" and work also without 25% cpu

Who is online

Users browsing this forum: No registered users and 14 guests