Mikrotik RouterOS Binding arrived

Hello everyone!

Mikrotik equipment is pretty popular in many countries afaik, and I saw some interest on integrating those devices with OpenHAB around the internet. So when I felt the need for it myself, I’ve decided to develop this binding.

It would be great if someone can test it and provide some feedback. While it works fine on my setup, I just could miss something…


OpenHAB v2.x (unsupported)

Full readme: https://github.com/duhast/openhab-addons/blob/mikrotik2/bundles/org.openhab.binding.mikrotik/README.md

Pull Request: https://github.com/openhab/openhab-addons/pull/9934

Last v2.x pre-built JAR is availble on Github: https://github.com/duhast/openhab-addons/releases/tag/mikrotik-v2


OpenHAB 3.x

Full readme: https://github.com/duhast/openhab-addons/blob/main/bundles/org.openhab.binding.mikrotik/README.md

Pull Request: https://github.com/openhab/openhab-addons/pull/10014 MERGED!
Release is scheduled for v3.2 milestone that should go out at the very end of the year 2021.

Intermediate JARs are availble on Github: https://github.com/duhast/openhab-addons/releases

6 Likes

Oh hell yeah. I don’t have one but definitely looking to get one eventually. Could I get you interested into looking at switchos as well? Please?

I don’t think so. I’ve thought about SwOS previously but currently I don’t think it makes sense for the binding. Here’s why:

  1. SwOS doesn’t have any API, which means it’s required to emulate browser actions to get data and control SwOS. And this approach is not the preferred one, as everything will break as soon as the web UI will be updated.
  2. Switch is much simpler that router and I believe all important metrics can be grabbed via SNMP protocol using SNMP Binding.
1 Like

Perfect response :slight_smile: cheers, make sure you get the binding into openHAB 3 oficial store so that we all benefit from it :slight_smile: now I need to get my RB4011iGS+RM ASAP.

Sure, I hope I’ll create a pull request against OH3 codebase in next couple weeks.

Ahh, that’s a sweet one :star_struck:
I own RB3011 for three years so far and it went beyond all of my expectations TBH. Great product, given that your network setup is kinda “advanced” :yum:

1 Like

Happy to help…either coding or testing. Was going to do this myself, but glad someone else gets to do the heavy lifting.

I am currently rung 3.0, so I can help with conversion as well.

1 Like

@dfad1469 I’ve just completed the OH3 port and you can grab a JAR on my github to play around.

1 Like

I’ll jump on this soon, all my network equipment is mikrotik so this is great :+1:

So I just added a HAP AC2 plus a client (my iphone) without specifying the SSID, and a VPN connection.
Dont seem to get any values back on the VPN, iphone not all, HAP AC2 not all…
Set poll to 60 secs, been up for 5 mins now.


Left the things in place, removed and re-added the jar. Channels all got updated. So maybe the scheduled task not fetching all channels. Only cpu and last seen for the iphone seem to be getting updated in the logs

Thanks for this!
Just installed this on my OH3 using a recent snapshot.
I have 2 AC2 routers, and can confirm the binding is working as expected.
One question I have, are there any plans to include commands towards the device? Eg turning on/off wlan would be useful.

Hello,

Hard to say without seeing the debug logs. If you still have issues, try increasing the log level for this binding by issuing the following command to the Karaf console:
log:set DEBUG org.openhab.binding.mikrotik.*

(switch back to normal by same command, but INFO instead of DEBUG)

Yeah, I was thinking about that for a while and added to the to-do list eventually.

@duHast
Continuing here from Github.
I have an RB4011 and sometimes the Router and the interfaces (wireless and all others) get into an errored state.
The interfaces show ERROR:BRIDGE and the Router shows Communication error.
When enabling the debug log (and the things are still online), I can see this:

 Refreshing all mikrotik:wifiRegistration:9e5f605af7:cee8238202 channels
2021-06-06 22:02:47.698 [DEBUG] [nal.handler.MikrotikBaseThingHandler] - Refreshing all mikrotik:wifiRegistration:3d424a0694 channels
2021-06-06 22:02:47.712 [DEBUG] [nal.handler.MikrotikBaseThingHandler] - Refreshing all mikrotik:interface:9e5f605af7:6637a8dcce channels
2021-06-06 22:02:53.900 [DEBUG] [andler.MikrotikRouterosBridgeHandler] - Refreshing RouterOS caches for mikrotik:routeros:9e5f605af7

But when it gets into an errored state, only this debug message can be seen:

2021-06-06 22:02:53.900 [DEBUG] [andler.MikrotikRouterosBridgeHandler] - Refreshing RouterOS caches for mikrotik:routeros:9e5f605af7

And it seems right. Even though the router is in an errored state uptime and things like this gets updated. However interfaces not.
I think maybe somewhere the scheduled refresh job gets interrupted (unhandled Exception maybe?) and that throws the things into an errored state but it never recovers because the scheduled job is not running anymore.

UPDATE:
Found the error:

2021-06-06 21:13:54.316 [ERROR] [andler.MikrotikRouterosBridgeHandler] - Unhandled exception while refreshing the mikrotik:routeros:9e5f605af7 RouterOS model
java.lang.NullPointerException: null
	at org.openhab.binding.mikrotik.internal.handler.MikrotikWirelessClientThingHandler.fetchModels(MikrotikWirelessClientThingHandler.java:72) ~[bundleFile:?]
	at org.openhab.binding.mikrotik.internal.handler.MikrotikWirelessClientThingHandler.refreshModels(MikrotikWirelessClientThingHandler.java:88) ~[bundleFile:?]
	at org.openhab.binding.mikrotik.internal.handler.MikrotikBaseThingHandler.throttledRefreshModels(MikrotikBaseThingHandler.java:207) ~[bundleFile:?]
	at org.openhab.binding.mikrotik.internal.handler.MikrotikBaseThingHandler.refresh(MikrotikBaseThingHandler.java:189) ~[bundleFile:?]
	at org.openhab.binding.mikrotik.internal.handler.MikrotikRouterosBridgeHandler.lambda$1(MikrotikRouterosBridgeHandler.java:192) ~[bundleFile:?]
	at java.util.ArrayList.forEach(ArrayList.java:1541) ~[?:?]
	at java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1085) ~[?:?]
	at org.openhab.binding.mikrotik.internal.handler.MikrotikRouterosBridgeHandler.performRefresh(MikrotikRouterosBridgeHandler.java:189) [bundleFile:?]
	at org.openhab.binding.mikrotik.internal.handler.MikrotikRouterosBridgeHandler.scheduledRun(MikrotikRouterosBridgeHandler.java:172) [bundleFile:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
	at java.lang.Thread.run(Thread.java:834) [?:?]

It seems to happen when the wireless client disconnects from the network…

1 Like

That’s a very useful finding, thanks! I’ll try to get that fixed.

Hello Oleg,

Do you plan to support LTE interfaces? Please advice. Thanks

Slawek

Since I have one modem lying around, why not? :slight_smile: Though, I have no idea when this may happen. Anyway, I’ve added this to feature TODO list.

I believe this is now fixed. Check the latest build here.

Yes, I have already tested it, it seems to work fine now! Thanks!

1 Like

Hrm I have one of these at work… I never thought this binding would exist… I might have to look into this one. Honestly I am using this more for the 8 10-gig SPF+ ports, and found the router part a bit over complicated and has an underdeveloped UI, so we have not actually used the routing features as of yet. Maybe with this binding it will prod me to try this again. Since our current VPN router is quite dated.
Our Mikrotik device appears to be running “RouterOS v6.46.1” on CRS309-1G8S+IN
Thanks A Lot!

1 Like

Latest build available here: JFrog

@duHast You are a legend. Does it support add/removing wifi networks on the fly? If so, i will love you forever and buy you cookies

1 Like