Code Monkey home page Code Monkey logo

mikrotik-presence-control's Introduction

mikrotik-presence-control

Mikrotik router script for reliable detection of WiFi client and sending HTTP requests when devices are registered or unregistered from the network. This approach works very reliably with Apple iPhone, iPad and other devices that are not reachable with TCP or UDP, but are still registered in the network.

How it Works

Mikrotik scheduler calls presence control script with specified interval to check if desired devices are registered in WiFi network. When script detects device state change in the network, it will send HTTP request to a desired server to report that device is registered, same when device is no longer present in the WiFi network. To improve reliability with multiple access point setup, when device is registered script will send up to arriveSendTimes requests to the server, as it may happen that access point where device was unregistered sends leave event to the server after device is registered on another access point happened, resulting in device being treated as not present by the server.

Tested on RouterOS v6.45.1 (stable)

Installation and Configuration

Configuration

Variables

  • arriveSendTimes - number of times to send requests to a server when device is registered within WiFi network
  • subjects - array of subjects to check presence of, each entry contains name, mac and state
    • name - name of person who owns particular device, is optinal and is only used in when sending HTTP requests
    • mac - MAC adress of wathced device, should be in uppercase
    • state - internal state variable used for detecting state changes, should be set to 0

In-script Modification

Modify following lines based on your requirements, in current example it was used for reporting state to homebridge-people-x via webhooks:

:tool fetch mode=http http-method=post http-data="" url="http://homebridge:51828/?sensor=$name&state=false"
...
:tool fetch mode=http http-method=post http-data="" url="http://homebridge:51828/?sensor=$name&state=true"

Installation

From Mikrotik WebFig IDE:

  • Create new script System -> Scripts -> Scripts tab -> Add New
  • Set Name to presence_control
  • Paste presence-control.script content into Source
  • Withing script:
    • Modify subjects array
    • Adjust values of url and http-data
  • Leave other options as-is
  • Click Apply
  • Create new scheduler System -> Schedulers -> Add New
  • Tick Enabled
  • Set Name to presence_control
  • Set Interval to 00:00:05
  • Set On Event to presence_control
  • Click Apply

mikrotik-presence-control's People

Contributors

mradugin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.