*/
package org.openhab.binding.mikrotik.internal.handler;
-import static org.openhab.core.thing.ThingStatus.OFFLINE;
-import static org.openhab.core.thing.ThingStatus.ONLINE;
+import static org.openhab.core.thing.ThingStatus.*;
import static org.openhab.core.thing.ThingStatusDetail.GONE;
import java.math.BigDecimal;
import org.openhab.binding.mikrotik.internal.model.RouterosLTEInterface;
import org.openhab.binding.mikrotik.internal.model.RouterosPPPCliInterface;
import org.openhab.binding.mikrotik.internal.model.RouterosPPPoECliInterface;
+import org.openhab.binding.mikrotik.internal.model.RouterosWifiInterface;
import org.openhab.binding.mikrotik.internal.model.RouterosWlanInterface;
import org.openhab.binding.mikrotik.internal.util.RateCalculator;
import org.openhab.binding.mikrotik.internal.util.StateUtil;
newState = getEtherIterfaceChannelState(channelID);
} else if (iface instanceof RouterosCapInterface) {
newState = getCapIterfaceChannelState(channelID);
+ } else if (iface instanceof RouterosWifiInterface) {
+ newState = getWifiIterfaceChannelState(channelID);
} else if (iface instanceof RouterosWlanInterface) {
newState = getWlanIterfaceChannelState(channelID);
} else if (iface instanceof RouterosPPPCliInterface) {
}
}
+ protected State getWifiIterfaceChannelState(String channelID) {
+ RouterosWifiInterface wlIface = (RouterosWifiInterface) this.iface;
+ if (wlIface == null) {
+ return UnDefType.UNDEF;
+ }
+
+ switch (channelID) {
+ case MikrotikBindingConstants.CHANNEL_STATE:
+ return StateUtil.stringOrNull(wlIface.getCurrentState());
+ case MikrotikBindingConstants.CHANNEL_RATE:
+ return StateUtil.stringOrNull(wlIface.getRate());
+ case MikrotikBindingConstants.CHANNEL_REGISTERED_CLIENTS:
+ return StateUtil.intOrNull(wlIface.getRegisteredClients());
+ case MikrotikBindingConstants.CHANNEL_AUTHORIZED_CLIENTS:
+ return StateUtil.intOrNull(wlIface.getAuthorizedClients());
+ default:
+ return UnDefType.UNDEF;
+ }
+ }
+
protected State getPPPoECliChannelState(String channelID) {
RouterosPPPoECliInterface pppCli = (RouterosPPPoECliInterface) this.iface;
if (pppCli == null) {
public static final String PROP_TYPE_KEY = "type";
public static final String PROP_NAME_KEY = "name";
public static final String PROP_SSID_KEY = "ssid";
-
+ public static final String PROP_CONFIG_SSID_KEY = "configuration.ssid";
private static final String CMD_PRINT_IFACES = "/interface/print";
private static final String CMD_PRINT_IFACE_TYPE_TPL = "/interface/%s/print";
private static final String CMD_MONTOR_IFACE_MONITOR_TPL = "/interface/%s/monitor numbers=%s once";
private static final String CMD_PRINT_CAPS_IFACES = "/caps-man/interface/print";
private static final String CMD_PRINT_CAPSMAN_REGS = "/caps-man/registration-table/print";
+ private static final String CMD_PRINT_WIFI_REGS = "/interface/wifi/registration-table/print";
private static final String CMD_PRINT_WIRELESS_REGS = "/interface/wireless/registration-table/print";
private static final String CMD_PRINT_RESOURCE = "/system/resource/print";
private static final String CMD_PRINT_RB_INFO = "/system/routerboard/print";
return Optional.of(new RouterosCapInterface(interfaceProps));
case WLAN:
return Optional.of(new RouterosWlanInterface(interfaceProps));
+ case WIFI:
+ return Optional.of(new RouterosWifiInterface(interfaceProps));
case PPPOE_CLIENT:
return Optional.of(new RouterosPPPoECliInterface(interfaceProps));
case PPP_CLIENT:
public void start() throws MikrotikApiException {
login();
updateRouterboardInfo();
+ if (rbInfo != null) {
+ logger.debug("RouterOS Version = {}", rbInfo.getFirmwareVersion());
+ }
}
public void stop() {
synchronized (this) {
updateResources();
updateInterfaceData();
- updateCapsmanRegistrations();
- updateWirelessRegistrations();
+ try {
+ updateCapsmanRegistrations();
+ } catch (MikrotikApiException e) {
+ logger.debug(
+ "MikrotikApiException: Device may have the CAPsMAN feature for wireless management disabled.");
+ }
+ wirelessRegistrationCache.clear();
+ try {
+ updateWirelessRegistrations();
+ } catch (MikrotikApiException e) {
+ logger.debug(
+ "MikrotikApiException: Device does not appear to have any built in CAPsMAN wireless devices.");
+ }
+ try {
+ updateWifiRegistrations();
+ } catch (MikrotikApiException e) {
+ logger.debug("MikrotikApiException: Device does not appear to have any built in wifi.");
+ }
+ logger.trace("There are {} wirelessRegistration's registered in cache.", wirelessRegistrationCache.size());
}
}
this.wlanSsid.clear();
this.interfaceCache.clear();
ifaceResponse.forEach(props -> {
+ logger.trace("Interface Details:{}", props.toString());
Optional<RouterosInterfaceBase> ifaceOpt = createTypedInterface(props);
if (ifaceOpt.isPresent()) {
RouterosInterfaceBase iface = ifaceOpt.get();
}
});
+ // Checks if any new interfaces have been setup since last check
Map<String, Map<String, String>> typedIfaceResponse = new HashMap<>();
for (String ifaceApiType : interfaceTypesToPoll) {
String cmd = String.format(CMD_PRINT_IFACE_TYPE_TPL, ifaceApiType);
if (ifaceApiType.compareTo("cap") == 0) {
cmd = CMD_PRINT_CAPS_IFACES;
}
+ logger.debug("Command used for updating the interfaces is:{}", cmd);
connection.execute(cmd).forEach(propMap -> {
String ifaceName = propMap.get(PROP_NAME_KEY);
if (ifaceName != null) {
for (RouterosInterfaceBase ifaceModel : interfaceCache) {
// Enrich with detailed data
-
Map<String, String> additionalIfaceProps = typedIfaceResponse.get(ifaceModel.getName());
if (additionalIfaceProps != null) {
ifaceModel.mergeProps(additionalIfaceProps);
}
- // Get monitor data
+ // Get monitor data, runs if you have added an interface thing.
if (ifaceModel.hasMonitor() && monitoredInterfaces.contains(ifaceModel.getName())) {
String cmd = String.format(CMD_MONTOR_IFACE_MONITOR_TPL, ifaceModel.getApiType(), ifaceModel.getName());
+ if (logger.isDebugEnabled()) {
+ logger.debug("Getting detailed data for Interface:{}, with command:{}", ifaceModel.getName(), cmd);
+ }
List<Map<String, String>> monitorProps = connection.execute(cmd);
ifaceModel.mergeProps(monitorProps.get(0));
}
// Note SSIDs for non-CAPsMAN wireless clients
String ifaceName = ifaceModel.getName();
- String ifaceSsid = ifaceModel.getProperty(PROP_SSID_KEY);
+ String ifaceSsid;
+ switch (ifaceModel.getApiType()) {
+ case "wifi":
+ ifaceSsid = ifaceModel.getProperty(PROP_CONFIG_SSID_KEY);
+ break;
+ case "caps":
+ case "wireless":
+ default:
+ ifaceSsid = ifaceModel.getProperty(PROP_SSID_KEY);
+ }
if (ifaceName != null && ifaceSsid != null && !ifaceName.isBlank() && !ifaceSsid.isBlank()) {
this.wlanSsid.put(ifaceName, ifaceSsid);
}
}
+ logger.debug("Found the following SSID's:{}", wlanSsid.toString());
}
private void updateCapsmanRegistrations() throws MikrotikApiException {
return;
}
List<Map<String, String>> response = conn.execute(CMD_PRINT_WIRELESS_REGS);
- wirelessRegistrationCache.clear();
response.forEach(props -> {
String wlanIfaceName = props.get("interface");
String wlanSsidName = wlanSsid.get(wlanIfaceName);
});
}
+ private void updateWifiRegistrations() throws MikrotikApiException {
+ ApiConnection conn = this.connection;
+ if (conn == null) {
+ return;
+ }
+ List<Map<String, String>> response = conn.execute(CMD_PRINT_WIFI_REGS);
+ response.forEach(props -> {
+ String wlanIfaceName = props.get("interface");
+ String wlanSsidName = wlanSsid.get(wlanIfaceName);
+
+ if (wlanSsidName != null && wlanIfaceName != null && !wlanIfaceName.isBlank() && !wlanSsidName.isBlank()) {
+ props.put("configuration.ssid", wlanSsidName);
+ }
+ wirelessRegistrationCache.add(new RouterosWirelessRegistration(props));
+ });
+ }
+
private void updateResources() throws MikrotikApiException {
ApiConnection conn = this.connection;
if (conn == null) {
--- /dev/null
+/**
+ * Copyright (c) 2010-2024 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.mikrotik.internal.model;
+
+import java.util.Map;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+/**
+ * The {@link RouterosWifiInterface} is a model class for `wifi` interface models having casting accessors for
+ * data that is specific to this network interface kind. Is a subclass of {@link RouterosInterfaceBase}.
+ *
+ * @author Matthew Skinner - Initial contribution
+ */
+@NonNullByDefault
+public class RouterosWifiInterface extends RouterosWlanInterface {
+
+ public RouterosWifiInterface(Map<String, String> props) {
+ super(props);
+ }
+
+ @Override
+ public RouterosInterfaceType getDesignedType() {
+ return RouterosInterfaceType.WIFI;
+ }
+
+ @Override
+ public String getApiType() {
+ return "wifi";
+ }
+
+ @Override
+ public int getRegisteredClients() {
+ Integer registeredClients = getIntProp("registered-peers");
+ return registeredClients == null ? 0 : registeredClients;
+ }
+
+ @Override
+ public int getAuthorizedClients() {
+ Integer authedClients = getIntProp("authorized-peers");
+ return authedClients == null ? 0 : authedClients;
+ }
+}