I have just written script for Mikrotik dhcp server lease which send json/url command to Domoticz . Interested anybody?
Mikrotik script for phones/devices presence.
Moderator: leecollings
Mikrotik script for phones/devices presence.
Hi,
I have just written script for Mikrotik dhcp server lease which send json/url command to Domoticz . Interested anybody?
I have just written script for Mikrotik dhcp server lease which send json/url command to Domoticz . Interested anybody?
-
kniazio
- Posts: 202
- Joined: Thursday 06 October 2016 8:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.7243
- Contact:
Re: Mikrotik script for phones/devices presence.
Show this script
Re: Mikrotik script for phones/devices presence.
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¶m=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¶m=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¶m=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¶m=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";
}
}-
dio45rus
- Posts: 2
- Joined: Thursday 24 May 2018 15:53
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Mikrotik script for phones/devices presence.
Thanx! Simple and very useful!
Who is online
Users browsing this forum: No registered users and 1 guest