Router Mikrotik controls radio broadcast and voices Smart Home

Recently, I accidentally got acquainted with the RadioBoss program of the DJSoft.Net company www.radioboss.ru and was just delighted with the design and capabilities of this radio broadcast automation software station. Of course, I am not a professional and not a sophisticated music lover user, but nevertheless, the well-thought-out interface, full support of the Russian language, the richest playback and broadcast scheduling controls, as well as the low price, pleasantly surprise. The free full version is designed for 150 runs of 5 hours of work, which is more than enough to master the program's capabilities. More details about RadioBoss can be found on the official website and forum .







I was more seduced by the fact that the program supports API control, which allows you to remotely fully control the playback of music on a computer with RadioBoss installed. I have long had a dream to be able to play media remotely without connecting to the desktop of a remote PC and without a computer at all. Let it do it for me, for example, ... my router Mikrotik!



As you know, Router OS Mikrotik has a built-in powerful scripting language that allows you to write any scripts and programs to automate the operation of the router. But not just a router! Script command / tool fetchallows you to organize external GET and POST requests to the specified URL and thus access any hardware or programs with open APIs. For example, scripts and libraries of commands for controlling Internet relay modules from Mikrotik and monitoring the environment ( can be viewed and downloaded here ), obtaining information about the weather , notifications about events in Telegram and controlling the router via Telegram , determining the time of sunrise / sunset with the organization of astronomical relay etc ...



Why have we got it? Using the guide to the RadioBoss API, we write a few simple functions for Router OS Mikrotik, which will allow the router to perform actions on the RadioBoss to perform any events on the router:



#---------------------------------------------------------#
#   RadioBoss                                
#          by Sertik 18/12/2020                                       
#---------------------------------------------------------#

# - FuncRadioBossInit
#   ,      RadioBoss    
#     

:global FuncRadioBossInit do={
:if ([:len $0]!=0) do={
:if ([:len $1]!=0) do={
:if ([:len $2]!=0) do={
:if ([:len $3]!=0) do={
:global FuncPing
:if ([$FuncPing PingAdr=$1]="OK") do={
:global RBaddr $1
:global RBport $2
:global RBpass $3
:return "OK";
             } else={:return "ERROR PC RadioBoss not responded"}
          } else={:return "ERROR parametr password"}
     } else={:return "ERROR parametr port"}
   } else={:return "ERROR parametr address"}
  }
}


# - FuncRadioBossPlay
#     ,   ,    
#   "next"/"prev"   / 

:global FuncRadioBossPlay do={
:if ([:len $0]!=0) do={
:global RBaddr
:global RBport
:global RBpass
:if (([:len $RBaddr]!=0) and ([:len $RBport]!=0) and ([:len $RBpass]!=0)) do={
:local StrFetchRB;
:if (($1="next") or ($1="prev")) do={:set StrFetchRB ("http://"."$RBaddr".":"."$RBport"."/\?pass="."$RBpass"."&cmd="."$1");} else={ 
:set StrFetchRB ("http://"."$RBaddr".":"."$RBport"."/\?pass="."$RBpass"."&cmd=play%20"."$1");} 
do {
:global RBanswer [/tool fetch url=$StrFetchRB mode=http as-value output=user];
} on-error={:return "ERROR"}
:global RBanswer; 
:if (($RBanswer->"status")!="finished") do={:return "ERROR"}
:return ($RBanswer->"data");
   } else={:return "ERROR no define address, port or password"}
 }
}

# - FuncRadioBossStop
#  

:global FuncRadioBossStop do={
:if ([:len $0]!=0) do={
:global RBaddr
:global RBport
:global RBpass
:if (([:len $RBaddr]!=0) and ([:len $RBport]!=0) and ([:len $RBpass]!=0)) do={
:local StrFetchRB; :set StrFetchRB ("http://"."$RBaddr".":"."$RBport"."/\?pass="."$RBpass"."&cmd=stop"); 
do {
:global RBanswer [/tool fetch url=$StrFetchRB mode=http as-value output=user];
} on-error={:return "ERROR"}
:global RBanswer; 
:if (($RBanswer->"status")!="finished") do={:return "ERROR"}
:return ($RBanswer->"data");
   } else={:return "ERROR no define address, port or password"}
 }
}


# - FuncRadioBossBreak
#      

:global FuncRadioBossBreak do={
:if ([:len $0]!=0) do={
:global RBaddr
:global RBport
:global RBpass
:if (([:len $RBaddr]!=0) and ([:len $RBport]!=0) and ([:len $RBpass]!=0)) do={
:local StrFetchRB; :set StrFetchRB ("http://"."$RBaddr".":"."$RBport"."/\?pass="."$RBpass"."&cmd=set%20break");
do {
:global RBanswer [/tool fetch url=$StrFetchRB mode=http as-value output=user];
} on-error={:return "ERROR"}
:global RBanswer; 
:if (($RBanswer->"status")!="finished") do={:return "ERROR"}
:return ($RBanswer->"data");
   } else={:return "ERROR no define address, port or password"}
 }
}


# - FuncRadioBossVolume
#   0-100

:global FuncRadioBossVolume do={
:if ([:len $0]!=0) do={
:global RBaddr
:global RBport
:global RBpass
:if (([:len $RBaddr]!=0) and ([:len $RBport]!=0) and ([:len $RBpass]!=0)) do={
:local StrFetchRB; :set StrFetchRB ("http://"."$RBaddr".":"."$RBport"."/\?pass="."$RBpass"."&cmd=setvol%20"."$1"); 
do {
:global RBanswer [/tool fetch url=$StrFetchRB mode=http as-value output=user];
} on-error={:return "ERROR"}
:global RBanswer; 
:if (($RBanswer->"status")!="finished") do={:return "ERROR"}
:return ($RBanswer->"data");
   } else={:return "ERROR no define address, port or password"}
 }
}

# - FuncRadioBossShuffle
# /  
#  [$FuncRadioBossShuffle "on/off"]


:global FuncRadioBossShuffle do={
:if ([:len $0]!=0) do={
:global RBaddr
:global RBport
:global RBpass
:if (([:len $RBaddr]!=0) and ([:len $RBport]!=0) and ([:len $RBpass]!=0)) do={
:local StrFetchRB; :set StrFetchRB ("http://"."$RBaddr".":"."$RBport"."/\?pass="."$RBpass"."&cmd=set%20shuffle%20"."$1"); 
do {
:global RBanswer [/tool fetch url=$StrFetchRB mode=http as-value output=user];
} on-error={:return "ERROR"}
:global RBanswer; 
:if (($RBanswer->"status")!="finished") do={:return "ERROR"}
:return ($RBanswer->"data");
   } else={:return "ERROR no define address, port or password"}
 }
}


# - FuncRadioBossReset
#      

:global FuncRadioBossReset do={
:if ([:len $0]!=0) do={
:global RBaddr
:global RBport
:global RBpass
:if (([:len $RBaddr]!=0) and ([:len $RBport]!=0) and ([:len $RBpass]!=0)) do={
:local StrFetchRB; :set StrFetchRB ("http://"."$RBaddr".":"."$RBport"."/\?pass="."$RBpass"."&cmd=resetplayedstate"); 
do {
:global RBanswer [/tool fetch url=$StrFetchRB mode=http as-value output=user];
} on-error={:return "ERROR"}
:global RBanswer; 
:if (($RBanswer->"status")!="finished") do={:return "ERROR"}
:return ($RBanswer->"data");
   } else={:return "ERROR no define address, port or password"}
 }
}

:global FuncPing do={
:local PingCount 3; #  ;
:local Hadr;
:if ([:find $PingAdr ":"]>0) do={:set Hadr [:pick $PingAdr 0 [:find $PingAdr ":"]];} else={
:set Hadr $PingAdr}
:local Result [/ping $Hadr count=$PingCount];
:local PingAnswer "";
:local MainIfInetOk false;
:set MainIfInetOk ((3*$Result) >= (2 * $PingCount))
:put "MainIfInetOk=$MainIfInetOk"
if (!$MainIfInetOk) do={
:set PingAnswer "ERROR"
}
if ($MainIfInetOk) do={
:set PingAnswer "OK"
}
:return $PingAnswer;
}
      
      







We insert the script code given above into the router repository, do not forget to call it at the start of the piece of iron (or when necessary) to "define" the written functions in the environment of variables. Then the RadioBoss control functions will be available from all your scripts, you can call them, for example:



#  ():
:global FuncRadioBossInit; :global FuncRadioBossVolume; :global FuncRadioBossPlay;
:global FuncRadioBossReset; :global FuncRadioBossShuffle; :global FuncRadioBossBreak;
#      RadioBoss
[$FuncRadioBossInit "192.168.0.2" "9001" "your password"]
#  
[$FuncRadioBossVolume "30"]
#    
[$FuncRadioBossReset]
#     
[$FuncRadioBossShuffle "on"]
#   
:log info [$FuncRadioBossPlay "next"]
#     
[$FuncRadioBossBreak]
      
      





The minimum set of functions provided in the script allows you to start playback of the specified track from the main playlist, play tracks in random order, stop playback, play the next, previous tracks, set the playback volume. The RadioBoss API is much more extensive and allows you to manage almost all the program's functions, including adding, removing tracks and streams to the playlist, inserting jingles, etc.



Naturally, I was not going to open my own Internet radio station, but using the program for utilitarian purposes was even more attractive to me. In particular, the capabilities of Mikrotik routers for sounding scripts through the built-in speaker are very modest. And then it becomes possible to record voice messages, insert them into the playlist instead of tracks and launch them from the Microtic OS Router as needed, and this is done not by me, but by the router itself!



On the PC with RadioBoss installed, enable remote access and configure the port and access password for it:







Home when the PC, rolled to tray windose RadioBoss program now tells me the voice of the required events in the local area network (connecting households on wifi, son excesses traffic limit, the availability of a new version of the software, attempts to gain unauthorized access to the router, etc ...)



In the country , with which a multichannel MESH VPN network has naturally been organized for a long time, it is possible, for example, when detecting movement with a video camera, automatically through an amplifier and street speakers to warn hooligans and thieves that they are seen, recorded and soon pounded on the neck.



The system administrator has the opportunity to install RadioBoss on office PCs and automatically warn violators of discipline by voice that it is necessary to work at work, and not surf the Internet or play "tanks", etc. ... It is also now possible to run radio broadcasting systems without purchasing expensive hardware systems. messages about meetings, conferences, etc. ...



This is how, for example, you can greet the boss (and at the same time warn employees!) when he appears in the office in the morning (add the MAC address of the boss's smartphone to the MAC variable (the idea is taken from here ).



:local MAC CC:CC:CC:CC:CC:CC;
:local MACdetect [interface wireless registration-table find mac-address=$MAC];
:if ([:len $MACdetect]>0) do {:do {:local nameADR [/ip firewall address-list get value-name=list [find address=123.123.123.123]];
:global FuncRadioBossInit; :[$FuncRadioBossInit «192.168.0.3» «9001» «PASSWORD»]
:global FuncRadioBossPlay
[$FuncRadioBossPlay «1»]
} on-error={/ip firewall address-list add dynamic=yes address=123.123.123.123 list=timer timeout=23:59:59; }}
      
      





We put the script execution in Mikrotika's Scheduler with execution, say, once every 15 seconds.



When the boss appears in the office (it is the first appearance of the day that is tracked) on the PC with the address passed in the $ FuncRadioInit function, the first track from the program's Playlist will be launched.



Of course, there are many other broadcasting automation programs, for example, RadioPlayerPro by RadioSoft , DJin Lite by Trakt and TraktSoft, etc., but given the capabilities of RadioBoss and its price, the program has practically no competitors.



Perhaps the API can be used to control the usual Windows Media Player, but I have not found anywhere instructions for controlling the Media Player via http requests.



By the way, the RadioBoss API allows you to run any bat files and Windows applications, as well as restart and shut down your computer. Thus, if the network card of your personal computer or laptop is equipped with the Wake on Lan function, Mikrotik can start the PC with RadioBoss, and that, in turn, after working out the required time, turn off the computer.



Enjoy your experiments!



All Articles