Mikrotik Binding idea


(Neil Du Toit) #1

I was thinking of making a Mikrotik Router Binding, which would be able to use the Mikrotik API to interact with the router, one use case I can think of is similar to the Network binding, to use the DHCP server on the Mikrotik to check if a device is online, as well as maybe pull some stats from the Mikrotik like throughput so one can put internet upload/download or number of devices on the network etc on the OH dashboard.

These are just a few of the ideas I have, would be nice to know if there are other people who would like to interact with their Mikrotik routers and what functionality would be expected with the binding.


(Christoph Wempe) #2

I would welcome a mikrotik binding.
But I don know if I really need one. :laughing:

Some features I could think of:

  • en/disable interfaces (especially for PoE devices)
  • status of interfaces like EoIP, L2TP, etc.
  • temperature?
  • count of wifi clients
  • signal strenght (per client?)

You might find more ideas in the topic:


(Wolfgang Rosenauer) #3

So I gather there is no Mikrotik binding yet?

I was looking for some binding being able to use their API mainly for presence detection based on mobile devices and MAC registrations.

Home Assistant has it out of the box apparently:


I’m just a user of the openhab platform but currently have no idea how to implement a binding to achieve this.
As a workaround I was thinking if the generic http binding would be usable but not sure.


(Sasha) #4

I would love to have a mikrotik binding!
But I’m pretty useless in coding.
I’ve got many of them, one being a main router, two separate access points + remote sites + spare ones.

If needed I can provide access to the API on one of them… Just as a though.


(Wolfgang Rosenauer) #5

Here is example API code for Java:

https://wiki.mikrotik.com/wiki/API_in_Java

This might help.


(Wolfgang Rosenauer) #6

I solved my presence usecase now with a push from RouterOS via the openHAB REST API.


(Sasha) #7

@Wolfgang_Rosenauer Can you please share your script?


(Wolfgang Rosenauer) #8

I’m using CAPsMAN. In case of local wifi interface the command differs.
I found an example for non capsman like this:
/int wire reg find mac-address=“78:02:F8:7E:96:01”

name=“Presence” owner=“admin” policy=read,write,policy,test dont-require-permissions=no last-started=nov/19/2018 08:37:09 run-count=1487
source=
:global WolfgangON

  {
    :local exists [/caps-man reg find mac-address="08:C5:E1:BF:D6:DD"];
    :if ($exists!="") do={
       :if ($WolfgangON != 1) do={
          /tool fetch url="http://192.168.250.12:8080/rest/items/SensorPhoneWolfgang" http-content-type="text/plain" http-data="ON" ascii=yes http-method=post;
         :set WolfgangON 1
       }
    }  else={
       :if ($WolfgangON != 0) do={
          /tool fetch url="http://192.168.250.12:8080/rest/items/SensorPhoneWolfgang" http-content-type="text/plain" http-data="OFF" ascii=yes http-method=post;
          :set WolfgangON 0
       }
    }
  }

(Sasha) #9

cool! thanks for that!


(Stefan) #10

Unfortunately in V6.44 of RouterOS Mikrotik removed the option “http-content-type”. Meanwhile they at least updated the documentation accordingly, pointing to the option “http-header-field” as a replacement. I tried to rewrite my script, but whatever I send as header field results in a “bad request” response. Multiple “http-header-field” entries are not permitted, the parameters need to be listed, comma seperated.
Does anyone have the same issue, or even has a solution for that? I would be very grateful for every hint how to solve this.


(Stefan) #11

Issue solved: Multiple header fields are not needed. As @Tema pointed out here (Mikrotik RouterOS HTTP request to OH) a few hours ago, the string defining the media type needs to be in lower case entirely.

/tool fetch url="http://<myserver>/rest/items/<myitem>/state" http-header-field="content-type: text/plain" http-data="CLOSED" ascii=yes

works with RouterOS v6.44, but

/tool fetch url="http://<myserver>/rest/items/<myitem>/state" http-header-field="Content-Type: text/plain" http-data="CLOSED" ascii=yes

results in a “400 Bad Request” message.
I changed my scripts on the Mikrotik router accordingly and now my presence detection works again.
Thanks, Tema!