Mikrotik RouterOS Binding arrived

What do you mean by “on the fly”?
As per my knowledge OpenHAB does not have functionality for such complex operations. You can control whatever is already configured in the 3rd-party system, but you cannot manage external nodes/entities/wahtever.

For discussion purposes: “on-the-fly” would best be translated “live” or “in real-time” without a restart/reboot. For example, if you were an IT manager who managed multiple restaurants (or other public venues) and installed Mikrotik routers and Philips Hue in each of them, you could do remote admin from one control panel instead of logging into the router and/or having to deal with NAT. If you wanted to change the name or password of a guest wifi network, you could do it from OH while you were monitoring their energy consumption from their devices. You can go the long way round of course, but it would be great to bring the Wifi and IoT world together to make it easier.

First of all: Thanks for the binding!

I tried it out today on 3.2.0 M3 with a hAP ac² and wanted to obtain the connected status of a wifi device.
The config if the bridge seems to be okay, no errors shown in the logs. If a configured device is connected, the status is correctly displayed.
If a device is however not connected, the openhab logs are spammed with the following logs:

==> /logs/openhab.log <==
2021-10-13 19:33:02.781 [WARN ] [r.MikrotikWirelessClientThingHandler] - wifiReg is null in refreshChannel(mikrotik:wifiRegistration:rb1:item:macAddress)
2021-10-13 19:33:02.781 [WARN ] [r.MikrotikWirelessClientThingHandler] - wifiReg is null in refreshChannel(mikrotik:wifiRegistration:rb1:item:comment)
2021-10-13 19:33:02.781 [WARN ] [r.MikrotikWirelessClientThingHandler] - wifiReg is null in refreshChannel(mikrotik:wifiRegistration:rb1:item:connected)
2021-10-13 19:33:02.781 [WARN ] [r.MikrotikWirelessClientThingHandler] - wifiReg is null in refreshChannel(mikrotik:wifiRegistration:rb1:item:continuous)
2021-10-13 19:33:02.782 [WARN ] [r.MikrotikWirelessClientThingHandler] - wifiReg is null in refreshChannel(mikrotik:wifiRegistration:rb1:item:ssid)
2021-10-13 19:33:02.782 [WARN ] [r.MikrotikWirelessClientThingHandler] - wifiReg is null in refreshChannel(mikrotik:wifiRegistration:rb1:item:interface)
2021-10-13 19:33:02.782 [WARN ] [r.MikrotikWirelessClientThingHandler] - wifiReg is null in refreshChannel(mikrotik:wifiRegistration:rb1:item:signal)
2021-10-13 19:33:02.782 [WARN ] [r.MikrotikWirelessClientThingHandler] - wifiReg is null in refreshChannel(mikrotik:wifiRegistration:rb1:item:upSince)
2021-10-13 19:33:02.782 [WARN ] [r.MikrotikWirelessClientThingHandler] - wifiReg is null in refreshChannel(mikrotik:wifiRegistration:rb1:item:lastSeen)
2021-10-13 19:33:02.782 [WARN ] [r.MikrotikWirelessClientThingHandler] - wifiReg is null in refreshChannel(mikrotik:wifiRegistration:rb1:item:txRate)
2021-10-13 19:33:02.782 [WARN ] [r.MikrotikWirelessClientThingHandler] - wifiReg is null in refreshChannel(mikrotik:wifiRegistration:rb1:item:rxRate)
2021-10-13 19:33:02.783 [WARN ] [r.MikrotikWirelessClientThingHandler] - wifiReg is null in refreshChannel(mikrotik:wifiRegistration:rb1:item:txPacketRate)
2021-10-13 19:33:02.783 [WARN ] [r.MikrotikWirelessClientThingHandler] - wifiReg is null in refreshChannel(mikrotik:wifiRegistration:rb1:item:rxPacketRate)
2021-10-13 19:33:02.783 [WARN ] [r.MikrotikWirelessClientThingHandler] - wifiReg is null in refreshChannel(mikrotik:wifiRegistration:rb1:item:txBytes)
2021-10-13 19:33:02.783 [WARN ] [r.MikrotikWirelessClientThingHandler] - wifiReg is null in refreshChannel(mikrotik:wifiRegistration:rb1:item:rxBytes)
2021-10-13 19:33:02.783 [WARN ] [r.MikrotikWirelessClientThingHandler] - wifiReg is null in refreshChannel(mikrotik:wifiRegistration:rb1:item:txPackets)
2021-10-13 19:33:02.783 [WARN ] [r.MikrotikWirelessClientThingHandler] - wifiReg is null in refreshChannel(mikrotik:wifiRegistration:rb1:item:rxPackets)

Noteworthy:

  • The logs are written more often than defined in the refresh interval of the bridge: refresh=10, logs every 5-6s.
  • I did only configure an item for the connected channel, nothing else. The logs are about all available channels.

Yeah, I’m experiencing the same since I’ve updgraded to OH3 a week ago. The fix is already submitted. Before the next release you can use latest manual build: org.openhab.binding.mikrotik-3.2.0-SNAPSHOT_20211017.jar

Awesome, thanks a lot!

PPP/LTE is coming

1 Like

Thx for update

Installed the binding… things seem fine, but in the log I get following error:

2021-10-26 14:01:28.384 [ERROR] [andler.MikrotikRouterosBridgeHandler] - RouterOS cache refresh failed in mikrotik:routeros:cb3ac9d5d4 due to Mikrotik API error
me.legrange.mikrotik.MikrotikApiException: no such command prefix
	at me.legrange.mikrotik.impl.ApiConnectionImpl$SyncListener.getResults(ApiConnectionImpl.java:482) ~[?:?]
	at me.legrange.mikrotik.impl.ApiConnectionImpl$SyncListener.access$100(ApiConnectionImpl.java:436) ~[?:?]
	at me.legrange.mikrotik.impl.ApiConnectionImpl.execute(ApiConnectionImpl.java:117) ~[?:?]
	at me.legrange.mikrotik.impl.ApiConnectionImpl.execute(ApiConnectionImpl.java:75) ~[?:?]
	at org.openhab.binding.mikrotik.internal.model.RouterosDevice.updateCapsmanRegistrations(RouterosDevice.java:259) ~[?:?]
	at org.openhab.binding.mikrotik.internal.model.RouterosDevice.refresh(RouterosDevice.java:159) ~[?:?]
	at org.openhab.binding.mikrotik.internal.handler.MikrotikRouterosBridgeHandler.performRefresh(MikrotikRouterosBridgeHandler.java:202) ~[?:?]
	at org.openhab.binding.mikrotik.internal.handler.MikrotikRouterosBridgeHandler.scheduledRun(MikrotikRouterosBridgeHandler.java:190) ~[?:?]
	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) [?:?]
Caused by: me.legrange.mikrotik.impl.ApiCommandException: no such command prefix
	at me.legrange.mikrotik.impl.ApiConnectionImpl$Processor.run(ApiConnectionImpl.java:270) ~[?:?]

Any ideas?

Which RouterOS version do you have?
What happens when you execute caps-man registration-table print in RouterOS terminal?

I have version 6.28

I don’t have a command caps-man in terminal.

I’ll try to upgrade to 6.49 today and report back.

Yeah… seems like my RouterOS version was way too old :smiley:

Running 6.49 now and the error seems to be gone…

Thanks for the reminder to check the version :wink:

@duHast would it be possible to implement monitoring system health values?

Like temperature and voltage.

I’m using a script for this now:

{
    :local temp [/system health get temperature]

    /tool fetch url="http://10.0.1.4:8080/rest/items/Router_Temp" http-header-field="content-type: text/plain" http-data=$temp http-method=post as-value output=user;
}

Also the same would be really great for /interface detect-internet.
That way you could use this in openhab to notify when internet is down.

Thanks!

Yeah, getting health values should be pretty easy. “Detect internet” should be feasible too once I’ll figure out how it works :slight_smile:

Hello i have an error no such command prefix when getting data from the router:

022-02-22 11:36:53.298 [ERROR] [andler.MikrotikRouterosBridgeHandler] - RouterOS cache refresh failed in mikrotik:routeros:157afe5d46 due to Mikrotik API error
me.legrange.mikrotik.MikrotikApiException: no such command prefix
	at me.legrange.mikrotik.impl.ApiConnectionImpl$SyncListener.getResults(ApiConnectionImpl.java:482) ~[?:?]
	at me.legrange.mikrotik.impl.ApiConnectionImpl$SyncListener.access$100(ApiConnectionImpl.java:436) ~[?:?]
	at me.legrange.mikrotik.impl.ApiConnectionImpl.execute(ApiConnectionImpl.java:117) ~[?:?]
	at me.legrange.mikrotik.impl.ApiConnectionImpl.execute(ApiConnectionImpl.java:75) ~[?:?]
	at org.openhab.binding.mikrotik.internal.model.RouterosDevice.updateCapsmanRegistrations(RouterosDevice.java:263) ~[?:?]
	at org.openhab.binding.mikrotik.internal.model.RouterosDevice.refresh(RouterosDevice.java:163) ~[?:?]
	at org.openhab.binding.mikrotik.internal.handler.MikrotikRouterosBridgeHandler.performRefresh(MikrotikRouterosBridgeHandler.java:202) ~[?:?]
	at org.openhab.binding.mikrotik.internal.handler.MikrotikRouterosBridgeHandler.scheduledRun(MikrotikRouterosBridgeHandler.java:190) ~[?:?]
	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:829) [?:?]
Caused by: me.legrange.mikrotik.impl.ApiCommandException: no such command prefix
	at me.legrange.mikrotik.impl.ApiConnectionImpl$Processor.run(ApiConnectionImpl.java:270) ~[?:?]

My router is hEX S(RB760iGS), version 6.49.
Tried to execute caps-man registration-table print but i dont have such command on the router. Otherwise the binding is successfully connecting to it and getting its modelId/serial/etc

Well some routers dont have Wifi so updateCapsmanRegistrations should not be mandatory

I have tried to execute this on my hex S and I got a response (not an error).

Thats true, but any router can be a capsman controller, no wifi is required for this. So this error should only happen if your RouterOS version is older.

/caps-man registration-table print 
 # INTERFACE        SSID        MAC-ADDRESS       UPTIME                RX-SIGNAL

Sorry but thats not true:
image

caps-man doesnt exist as command on my router

You are half-right.

Caps-man is included in the wireless package, which is installed (bundled) by default.
You have disabled that one, that’s why that command is not available.

Anyway you are right, that command should not be mandatory, as this command is only used for checking wifi registration table if you use wifi presence.

You are right, i might turn the Wifi module ON for workaround.

Guys, just letting you know:
I won’t be able to work on this while Putin is committing genocide in my homeland, Ukraine.