|---------------------|-------------------------------------------------------------------------------------------------------------|
| serialPort | The serial port where the P1-port is connected to (e.g. Linux: `/dev/ttyUSB1`, Windows: `COM2`) (mandatory) |
| decryptionKey | The meter specific decryption key (mandatory) |
+| additionalKey | Additional key for meters that require a secondary key. Some meters in Austria require this |
| receivedTimeout | The time out period in which messages are expected to arrive, default is 120 seconds |
public static final String CONFIGURATION_DECRYPTION_KEY = "decryptionKey";
public static final String CONFIGURATION_DECRYPTION_KEY_EMPTY = "";
+ public static final String CONFIGURATION_ADDITIONAL_KEY = "additionalKey";
+ public static final String ADDITIONAL_KEY_DEFAULT = "3000112233445566778899AABBCCDDEEFF";
private DSMRBindingConstants() {
// Constants class
*/
package org.openhab.binding.dsmr.internal.device;
+import org.openhab.binding.dsmr.internal.DSMRBindingConstants;
+
/**
* Class describing the DSMR bridge user configuration
*
* @author Hilbrand Bouwkamp - added receivedTimeout configuration
*/
public class DSMRDeviceConfiguration {
+
/**
* Serial port name
*/
public String stopbits;
/**
- * The Luxembourgish smart meter decryption key
+ * The Luxembourgish/Austria smart meter decryption key
*/
public String decryptionKey;
+ /**
+ * Austria smart meter additional decryption key
+ */
+ public String additionalKey = DSMRBindingConstants.ADDITIONAL_KEY_DEFAULT;
+
/**
* When no message was received after the configured number of seconds action will be taken.
*/
public String toString() {
return "DSMRDeviceConfiguration [serialPort=" + serialPort + ", Baudrate=" + baudrate + ", Databits=" + databits
+ ", Parity=" + parity + ", Stopbits=" + stopbits + ", decryptionKey=" + decryptionKey
- + ", receivedTimeout=" + receivedTimeout + "]";
+ + ", additionalKey=" + additionalKey + ", receivedTimeout=" + receivedTimeout + "]";
}
}
* Constructs {@link DSMRTelegramListener} with a Smarty decryptor to first decrypt incoming messages.
*
* @param decryptionKey Smarty decryption key
+ * @param additionalKey Additional optional descryption key
*/
- public DSMRTelegramListener(String decryptionKey) {
- parser = new SmartyDecrypter(new P1TelegramParser(this), this, decryptionKey);
+ public DSMRTelegramListener(final String decryptionKey, final String additionalKey) {
+ parser = new SmartyDecrypter(new P1TelegramParser(this), this, decryptionKey, additionalKey);
}
/**
*
* @param eventListener the listener to set
*/
- public void setDsmrEventListener(DSMREventListener eventListener) {
+ public void setDsmrEventListener(final DSMREventListener eventListener) {
this.dsmrEventListener = eventListener;
}
@Override
- public void handleData(byte[] data, int length) {
+ public void handleData(final byte[] data, final int length) {
parser.parse(data, length);
}
@Override
- public void handleErrorEvent(DSMRConnectorErrorEvent portEvent) {
+ public void handleErrorEvent(final DSMRConnectorErrorEvent portEvent) {
dsmrEventListener.handleErrorEvent(portEvent);
parser.reset();
}
* @param telegram the received telegram.
*/
@Override
- public void telegramReceived(P1Telegram telegram) {
+ public void telegramReceived(final P1Telegram telegram) {
final TelegramState telegramState = telegram.getTelegramState();
final List<CosemObject> cosemObjects = telegram.getCosemObjects();
/**
* @param lenientMode the lenientMode to set
*/
- public void setLenientMode(boolean lenientMode) {
+ public void setLenientMode(final boolean lenientMode) {
parser.setLenientMode(lenientMode);
}
}
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.binding.dsmr.internal.DSMRBindingConstants;
import org.openhab.binding.dsmr.internal.device.p1telegram.P1Telegram;
import org.openhab.binding.dsmr.internal.device.p1telegram.P1Telegram.TelegramState;
import org.openhab.binding.dsmr.internal.device.p1telegram.P1TelegramListener;
private static final byte SEPARATOR_82 = (byte) 0x82;
private static final byte SEPARATOR_30 = 0x30;
private static final int ADD_LENGTH = 17;
- private static final String ADD = "3000112233445566778899AABBCCDDEEFF";
- private static final byte[] ADD_DECODED = HexUtils.hexToBytes(ADD);
private static final int IV_BUFFER_LENGTH = 40;
private static final int GCM_TAG_LENGTH = 12;
private static final int GCM_BITS = GCM_TAG_LENGTH * Byte.SIZE;
private static final int MESSAGES_BUFFER_SIZE = 4096;
+ private static final String ADDITIONAL_ADD_PREFIX = "30";
private final Logger logger = LoggerFactory.getLogger(SmartyDecrypter.class);
private final ByteBuffer iv = ByteBuffer.allocate(IV_BUFFER_LENGTH);
private int dataLength;
private boolean lenientMode;
private final P1TelegramListener telegramListener;
+ private final byte[] addKey;
/**
* Constructor.
* @param parser parser of the Cosem messages
* @param telegramListener
* @param decryptionKey The key to decrypt the messages
+ * @param additionalKey Additional optional key to decrypt the message
*/
public SmartyDecrypter(final TelegramParser parser, final P1TelegramListener telegramListener,
- final String decryptionKey) {
+ final String decryptionKey, final String additionalKey) {
this.parser = parser;
this.telegramListener = telegramListener;
secretKeySpec = decryptionKey.isEmpty() ? null : new SecretKeySpec(HexUtils.hexToBytes(decryptionKey), "AES");
+ addKey = HexUtils.hexToBytes(additionalKey.isBlank() ? DSMRBindingConstants.ADDITIONAL_KEY_DEFAULT
+ : ((additionalKey.length() == 32 ? (ADDITIONAL_ADD_PREFIX) : "") + additionalKey));
}
@Override
final Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec,
new GCMParameterSpec(GCM_BITS, iv.array(), 0, ivLength));
- cipher.updateAAD(ADD_DECODED);
+ cipher.updateAAD(addKey);
return cipher.doFinal(cipherText.array(), 0, cipherText.position());
}
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException
*/
package org.openhab.binding.dsmr.internal.discovery;
-import static org.openhab.binding.dsmr.internal.DSMRBindingConstants.*;
+import static org.openhab.binding.dsmr.internal.DSMRBindingConstants.CONFIGURATION_ADDITIONAL_KEY;
+import static org.openhab.binding.dsmr.internal.DSMRBindingConstants.CONFIGURATION_DECRYPTION_KEY;
+import static org.openhab.binding.dsmr.internal.DSMRBindingConstants.CONFIGURATION_DECRYPTION_KEY_EMPTY;
+import static org.openhab.binding.dsmr.internal.DSMRBindingConstants.CONFIGURATION_SERIAL_PORT;
+import static org.openhab.binding.dsmr.internal.DSMRBindingConstants.DSMR_PORT_NAME;
+import static org.openhab.binding.dsmr.internal.DSMRBindingConstants.THING_TYPE_DSMR_BRIDGE;
+import static org.openhab.binding.dsmr.internal.DSMRBindingConstants.THING_TYPE_SMARTY_BRIDGE;
import java.util.HashMap;
import java.util.List;
protected void startScan() {
logger.debug("Started DSMR discovery scan");
scanning = true;
- Stream<SerialPortIdentifier> portEnum = serialPortManager.getIdentifiers();
+ final Stream<SerialPortIdentifier> portEnum = serialPortManager.getIdentifiers();
// Traverse each available serial port
portEnum.forEach(portIdentifier -> {
} else {
logger.debug("Start discovery on serial port: {}", currentScannedPortName);
//
- final DSMRTelegramListener telegramListener = new DSMRTelegramListener("");
+ final DSMRTelegramListener telegramListener = new DSMRTelegramListener("",
+ CONFIGURATION_ADDITIONAL_KEY);
final DSMRSerialAutoDevice device = new DSMRSerialAutoDevice(serialPortManager,
portIdentifier.getName(), this, telegramListener, scheduler,
BAUDRATE_SWITCH_TIMEOUT_SECONDS);
* @param telegram the received telegram
*/
@Override
- public void handleTelegramReceived(P1Telegram telegram) {
- List<CosemObject> cosemObjects = telegram.getCosemObjects();
+ public void handleTelegramReceived(final P1Telegram telegram) {
+ final List<CosemObject> cosemObjects = telegram.getCosemObjects();
if (logger.isDebugEnabled()) {
logger.debug("[{}] Received {} cosemObjects", currentScannedPortName, cosemObjects.size());
bridgeDiscovered(THING_TYPE_SMARTY_BRIDGE);
stopSerialPortScan();
} else if (!cosemObjects.isEmpty()) {
- ThingUID bridgeThingUID = bridgeDiscovered(THING_TYPE_DSMR_BRIDGE);
+ final ThingUID bridgeThingUID = bridgeDiscovered(THING_TYPE_DSMR_BRIDGE);
meterDetector.detectMeters(telegram).getKey().forEach(m -> meterDiscovered(m, bridgeThingUID));
stopSerialPortScan();
}
*
* @return The {@link ThingUID} of the newly created bridge
*/
- private ThingUID bridgeDiscovered(ThingTypeUID bridgeThingTypeUID) {
- ThingUID thingUID = new ThingUID(bridgeThingTypeUID, Integer.toHexString(currentScannedPortName.hashCode()));
+ private ThingUID bridgeDiscovered(final ThingTypeUID bridgeThingTypeUID) {
+ final ThingUID thingUID = new ThingUID(bridgeThingTypeUID,
+ Integer.toHexString(currentScannedPortName.hashCode()));
final boolean smarty = THING_TYPE_SMARTY_BRIDGE.equals(bridgeThingTypeUID);
final String label = String.format("@text/thing-type.dsmr.%s.label", smarty ? "smartyBridge" : "dsmrBridge");
// Construct the configuration for this meter
- Map<String, Object> properties = new HashMap<>();
+ final Map<String, Object> properties = new HashMap<>();
properties.put(CONFIGURATION_SERIAL_PORT, currentScannedPortName);
if (smarty) {
properties.put(CONFIGURATION_DECRYPTION_KEY, CONFIGURATION_DECRYPTION_KEY_EMPTY);
+ properties.put(CONFIGURATION_ADDITIONAL_KEY, CONFIGURATION_ADDITIONAL_KEY);
}
- DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withThingType(bridgeThingTypeUID)
- .withProperties(properties).withLabel(label).build();
+ final DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID)
+ .withThingType(bridgeThingTypeUID).withProperties(properties).withLabel(label).build();
logger.debug("[{}] discovery result:{}", currentScannedPortName, discoveryResult);
}
@Override
- public void handleErrorEvent(DSMRConnectorErrorEvent portEvent) {
+ public void handleErrorEvent(final DSMRConnectorErrorEvent portEvent) {
logger.debug("[{}] Error on port during discovery: {}", currentScannedPortName, portEvent);
stopSerialPortScan();
}
* @param bridge the Bridge ThingType
* @param serialPortManager The Serial port manager
*/
- public DSMRBridgeHandler(Bridge bridge, SerialPortManager serialPortManager) {
+ public DSMRBridgeHandler(final Bridge bridge, final SerialPortManager serialPortManager) {
super(bridge);
this.serialPortManager = serialPortManager;
smartyMeter = THING_TYPE_SMARTY_BRIDGE.equals(bridge.getThingTypeUID());
* @param command the {@link Command}
*/
@Override
- public void handleCommand(ChannelUID channelUID, Command command) {
+ public void handleCommand(final ChannelUID channelUID, final Command command) {
// DSMRBridgeHandler does not support commands
}
* @param deviceConfig device configuration
* @return Specific {@link DSMRDevice} instance
*/
- private DSMRDevice createDevice(DSMRDeviceConfiguration deviceConfig) {
+ private DSMRDevice createDevice(final DSMRDeviceConfiguration deviceConfig) {
final DSMRDevice dsmrDevice;
if (smartyMeter) {
dsmrDevice = new DSMRFixedConfigDevice(serialPortManager, deviceConfig.serialPort,
- DSMRSerialSettings.HIGH_SPEED_SETTINGS, this, new DSMRTelegramListener(deviceConfig.decryptionKey));
+ DSMRSerialSettings.HIGH_SPEED_SETTINGS, this,
+ new DSMRTelegramListener(deviceConfig.decryptionKey, deviceConfig.additionalKey));
} else {
final DSMRTelegramListener telegramListener = new DSMRTelegramListener();
* @param meterListener the meter discovery listener to add
* @return true if listener is added, false otherwise
*/
- public boolean registerDSMRMeterListener(P1TelegramListener meterListener) {
+ public boolean registerDSMRMeterListener(final P1TelegramListener meterListener) {
logger.trace("Register DSMRMeterListener");
return meterListeners.add(meterListener);
}
* @param meterListener the meter discovery listener to remove
* @return true is listener is removed, false otherwise
*/
- public boolean unregisterDSMRMeterListener(P1TelegramListener meterListener) {
+ public boolean unregisterDSMRMeterListener(final P1TelegramListener meterListener) {
logger.trace("Unregister DSMRMeterListener");
return meterListeners.remove(meterListener);
}
}
@Override
- public synchronized void handleTelegramReceived(P1Telegram telegram) {
+ public synchronized void handleTelegramReceived(final P1Telegram telegram) {
if (telegram.getCosemObjects().isEmpty()) {
logger.debug("Parsing worked but something went wrong, so there were no CosemObjects:{}",
telegram.getTelegramState().stateDetails);
}
@Override
- public void handleErrorEvent(DSMRConnectorErrorEvent portEvent) {
+ public void handleErrorEvent(final DSMRConnectorErrorEvent portEvent) {
if (portEvent != DSMRConnectorErrorEvent.READ_ERROR) {
deviceOffline(ThingStatusDetail.CONFIGURATION_ERROR, portEvent.getEventDetails());
}
*
* @param telegram received meter values.
*/
- private void meterValueReceived(P1Telegram telegram) {
+ private void meterValueReceived(final P1Telegram telegram) {
if (isInitialized() && getThing().getStatus() != ThingStatus.ONLINE) {
updateStatus(ThingStatus.ONLINE);
}
/**
* @param lenientMode the lenientMode to set
*/
- public void setLenientMode(boolean lenientMode) {
+ public void setLenientMode(final boolean lenientMode) {
logger.trace("SetLenientMode: {}", lenientMode);
if (dsmrDevice != null) {
dsmrDevice.setLenientMode(lenientMode);
* @param status off line status
* @param details off line detailed message
*/
- private void deviceOffline(ThingStatusDetail status, String details) {
+ private void deviceOffline(final ThingStatusDetail status, final String details) {
updateStatus(ThingStatus.OFFLINE, status, details);
}
}
</parameter>
<parameter name="decryptionKey" type="text" required="true">
<label>Decryption Key</label>
- <description>The Luxembourgian Smart meter decryption key. Ask for your energy grid operator for your Smart meter P1
- key.</description>
+ <description>Smart meter decryption key. Ask your energy grid operator for your smart meter P1 key.</description>
+ </parameter>
+ <parameter name="additionalKey" type="text">
+ <label>Additional Decryption Key</label>
+ <description>Additional decryption key. Ask your energy grid operator for your smart meter P1 key.</description>
+ <default>3000112233445566778899AABBCCDDEEFF</default>
</parameter>
<parameter name="receivedTimeout" type="integer" min="1" unit="s">
<default>30</default>
thing-type.config.dsmr.meterdescriptor.channel.description = The DSMR-device channel for this meter (M-Bus channel). The binding will auto detect this value. In normal situations it is not necessary to adapt this value. If the auto detection failed or if physical changes are made to the meter setup (changed water, gas, heating) meters it can be necessary to update the M-Bus channel.
thing-type.config.dsmr.meterdescriptor.refresh.label = Refresh
thing-type.config.dsmr.meterdescriptor.refresh.description = The time interval the data is refreshed in seconds
+thing-type.config.dsmr.smartybridgesettings.additionalKey.label = Additional Decryption Key
+thing-type.config.dsmr.smartybridgesettings.additionalKey.description = Additional decryption key. Ask your energy grid operator for your smart meter P1 key.
thing-type.config.dsmr.smartybridgesettings.decryptionKey.label = Decryption Key
-thing-type.config.dsmr.smartybridgesettings.decryptionKey.description = The Luxembourgian Smart meter decryption key. Ask for your energy grid operator for your Smart meter P1 key.
+thing-type.config.dsmr.smartybridgesettings.decryptionKey.description = Smart meter decryption key. Ask your energy grid operator for your smart meter P1 key.
thing-type.config.dsmr.smartybridgesettings.receivedTimeout.label = Received Timeout
thing-type.config.dsmr.smartybridgesettings.receivedTimeout.description = The time period within results are expected in seconds
thing-type.config.dsmr.smartybridgesettings.serialPort.label = Serial Port
final AtomicReference<String> telegramResult = new AtomicReference<>("");
final P1TelegramListener telegramListener = telegram -> telegramResult.set(telegram.getRawTelegram());
final SmartyDecrypter decoder = new SmartyDecrypter(new P1TelegramParser(telegramListener),
- new DSMRTelegramListener(KEY), KEY);
+ new DSMRTelegramListener(KEY, ""), KEY, "");
decoder.setLenientMode(true);
final byte[] data = new byte[TELEGRAM.length];