Page 1 of 1

Mikrotik script for phones/devices presence.

Posted: Thursday 29 March 2018 17:07
by rodaman
Hi,
I have just written script for Mikrotik dhcp server lease which send json/url command to Domoticz . Interested anybody? :?:

Re: Mikrotik script for phones/devices presence.

Posted: Thursday 29 March 2018 17:52
by kniazio
Show this script

Re: Mikrotik script for phones/devices presence.

Posted: Friday 30 March 2018 8:27
by rodaman
Here is the script. I am very new of Mikrotik scripting so it is very simple but working. You have to put the script in DHCP Server/DHCP section in Mikrotik router. Change MAC adresses and Domoticz IP:Port and IDX's of devices. Router send command "Off" after expires time (10 min. default).

Code: Select all

# *. by RouterOS
#
# DHCP Leases to Domoticz
# On-Lease Script
#

# Phones MAC
:global RomekMAC "AA:AA:AA:AA:AA:AA";
:global GosiaMAC "BB:BB:BB:BB:BB:BB";
#
# Globals
#
:global leaseBound
:global leaseServerName
:global leaseActMAC
:global leaseActIP

#
# Script
#
# Insert on Bound

:if ($leaseBound =1) do={
 :if ([$leaseActMAC] = $RomekMAC)  do={
    /tool fetch mode=http url="http://192.168.1.111:8181/json.htm?type=command&param=switchlight&idx=240&switchcmd=On" dst-path=http_response.txt;
    # display the contents of the file with the server's response
    :local httpResponse [/file get http_response.txt contents];
    :log info "HTTP server response: $httpResponse";
    }
 :if ([$leaseActMAC] = $GosiaMAC)  do={
    /tool fetch mode=http url="http://192.168.1.111:8181/json.htm?type=command&param=switchlight&idx=241&switchcmd=On" dst-path=http_response.txt;
    # display the contents of the file with the server's response
    :local httpResponse [/file get http_response.txt contents];
    :log info "HTTP server response: $httpResponse";  
	}
}

:if ($leaseBound =0) do={
 :if ([$leaseActMAC] = $RomekMAC) do={
    /tool fetch mode=http url="http://192.168.1.111:8181/json.htm?type=command&param=switchlight&idx=240&switchcmd=Off" dst-path=http_response.txt;
    # display the contents of the file with the server's response
    :local httpResponse [/file get http_response.txt contents];
    :log info "HTTP server response: $httpResponse";
    }
	
 :if ([$leaseActMAC] = $GosiaMAC) do={
    /tool fetch mode=http url="http://192.168.1.111:8181/json.htm?type=command&param=switchlight&idx=241&switchcmd=Off" dst-path=http_response.txt;
    # display the contents of the file with the server's response
    :local httpResponse [/file get http_response.txt contents];
    :log info "HTTP server response: $httpResponse";
    }	
}

Re: Mikrotik script for phones/devices presence.

Posted: Friday 25 May 2018 9:03
by dio45rus
Thanx! Simple and very useful!

Re: Mikrotik script for phones/devices presence.

Posted: Tuesday 25 September 2018 20:08
by seansco
nice!