Hello,
I’m creating a new topic because I was not able to find anything related using the search function. Apologize me if I missed it.
I’m trying to configure the Mikrotik binding to connect to my cAP ax. The RouterOS version installed is 7.11.2 and it is configured as a simple access point.
I created a “read only” user in RouterOS an allowed the service API as prescribed in the binding manual.
I’m currently using OpenHAB 4.0.3 installed on Ubuntu 22.04 and I’m using OpenJDK Zulu17.46+19-CA (build 17.0.9+8-LTS).
When I try to configure the binding bridge, the connection is created but every 10 seconds it flips to OFFLINE (communication error) and then back to ONLINE.
The logs are showing this:
2023-10-30 11:17:00.930 [ERROR] [andler.MikrotikRouterosBridgeHandler] - RouterOS cache refresh failed in mikrotik:routeros:0989559e1e 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:539) ~[?:?]
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:1136) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
at java.lang.Thread.run(Thread.java:840) ~[?:?]
Caused by: me.legrange.mikrotik.impl.ApiCommandException: no such command prefix
at me.legrange.mikrotik.impl.ApiConnectionImpl$Processor.run(ApiConnectionImpl.java:270) ~[?:?]
I don’t know where to look to understand how to fix that error. Could you please help me giving some directions?
I am having the same issue. I have just replaced my mikrotik, the old one ran 6.8 routerOS, the new one is 7.8. Probably some API implementation changed, I try to look deeper into that.
Hello,
I found a workaround leveraging the REST API of the MikroTik to identify who is connected to the network.
I created some items for each device that I want to track using the “expire” feature to automatically command the items OFF after 3 minutes of absence:
Group:Switch:OR(ON, OFF) gPresenceWiFi "Presenza [MAP(unifi.map):%s]" <parents_3_3> (Debug) ["internal"]
Switch User1_home_T "User1 on Tik is [MAP(unifi.map):%s] on Tik" <boy_3> (gPresenceWiFi) ["internal"] {expire="3m, command=OFF"}
Switch User2_home_T "User2 on Tik is [MAP(unifi.map):%s]" <girl_3> (gPresenceWiFi) ["internal"] {expire="3m, command=OFF"}
Switch User3_home_T "User3 on Tik is [MAP(unifi.map):%s]" <woman_3> (gPresenceWiFi) ["internal"] {expire="3m, command=OFF"}
Switch User4_home_T "User4 on Tik is [MAP(unifi.map):%s]" <man_3> (gPresenceWiFi) ["internal"] {expire="3m, command=OFF"}
Then I wrote a rule to monitor in the registration table of the MikroTik AP gathering the data in JSON and then using the transformation to extract each single MAC address:
rule "mikrotik_presence"
when
Time cron "0 0/1 * * * ? *" //Every minute
then
// Variables
val String CAPsMAN_address = "https://user:password@192.168.XXX.XXX/rest/interface/wifi/registration-table?.proplist=mac-address"
val String response_tik_JSON = sendHttpGetRequest(CAPsMAN_address, 15000)
val Number num_registered = Integer::parseInt(transform("JSONPATH", "$.length()", response_tik_JSON))
var Number i = 0
var String mac_registered
// logInfo("MikroTik Presence", "String JSON: " + response_tik_JSON)
// logInfo("MikroTik Presence", "Number of registered MACs: " + num_registered)
for (i = 0; i < num_registered; i = i + 1 ) {
mac_registered = transform("JSONPATH", "$.[" + i + "][\"mac-address\"]", response_tik_JSON)
// logInfo("MikroTik Presence", "id: " + i + " MAC: " + mac_registered)
if (mac_registered.equalsIgnoreCase("XX:XX:XX:XX:XX:XX")) User1_home_T.sendCommand(ON)
if (mac_registered.equalsIgnoreCase("XX:XX:XX:XX:XX:XX")) User2_home_T.sendCommand(ON)
if (mac_registered.equalsIgnoreCase("XX:XX:XX:XX:XX:XX")) User3_home_T.sendCommand(ON)
if (mac_registered.equalsIgnoreCase("XX:XX:XX:XX:XX:XX")) User4_home_T.sendCommand(ON)
}
end
Maybe this is not the best or the most optimized way to solve the exercise, but it works and I’m happy to share.