Add V2.2 telegram implementation and console read.
This commit is contained in:
parent
6343bce2ee
commit
90eb6fb3fe
35
dsmr_parser/__main__.py
Normal file
35
dsmr_parser/__main__.py
Normal file
@ -0,0 +1,35 @@
|
||||
import argparse
|
||||
from dsmr_parser.serial import SERIAL_SETTINGS_V2_2, SERIAL_SETTINGS_V4, SerialReader
|
||||
from dsmr_parser import telegram_specifications
|
||||
from dsmr_parser.obis_references import P1_MESSAGE_TIMESTAMP
|
||||
|
||||
def console():
|
||||
"""Output DSMR data to console."""
|
||||
|
||||
parser = argparse.ArgumentParser(description=console.__doc__)
|
||||
parser.add_argument('--device', default='/dev/ttyUSB0',
|
||||
help='port to read DSMR data from')
|
||||
parser.add_argument('--version', default='2.2', choices=['2.2', '4'],
|
||||
help='DSMR version (2.2, 4)')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
version = 'V' + args.version.replace('.', '_')
|
||||
|
||||
settings = {
|
||||
'2.2': (SERIAL_SETTINGS_V2_2, telegram_specifications.V2_2),
|
||||
'4': (SERIAL_SETTINGS_V4, telegram_specifications.V4),
|
||||
}
|
||||
|
||||
serial_reader = SerialReader(
|
||||
device=args.device,
|
||||
serial_settings=settings[args.version][0],
|
||||
telegram_specification=settings[args.version][1],
|
||||
)
|
||||
|
||||
for telegram in serial_reader.read():
|
||||
for obiref, obj in telegram.items():
|
||||
if obj:
|
||||
print(obj.value, obj.unit)
|
||||
print()
|
||||
|
@ -27,6 +27,10 @@ INSTANTANEOUS_ACTIVE_POWER_L2_NEGATIVE = r'1-0:42\.7\.0'
|
||||
INSTANTANEOUS_ACTIVE_POWER_L3_NEGATIVE = r'1-0:62\.7\.0'
|
||||
EQUIPMENT_IDENTIFIER_GAS = r'0-\d:96\.1\.0'
|
||||
HOURLY_GAS_METER_READING = r'0-1:24\.2\.1'
|
||||
GAS_METER_READING = r'0-\d:24\.3\.0'
|
||||
ACTUAL_TRESHOLD_ELECTRICITY = r'0-0:17\.0\.0'
|
||||
ACTUAL_SWITCH_POSITION = r'0-0:96\.3\.10'
|
||||
VALVE_POSITION_GAS = r'0-\d:24\.4\.0'
|
||||
|
||||
ELECTRICITY_USED_TARIFF_ALL = (
|
||||
ELECTRICITY_USED_TARIFF_1,
|
||||
|
@ -2,6 +2,16 @@ import serial
|
||||
|
||||
from dsmr_parser.parsers import TelegramParser
|
||||
|
||||
SERIAL_SETTINGS_V2_2 = {
|
||||
'baudrate': 9600,
|
||||
'bytesize': serial.SEVENBITS,
|
||||
'parity': serial.PARITY_NONE,
|
||||
'stopbits': serial.STOPBITS_ONE,
|
||||
'xonxoff': 0,
|
||||
'rtscts': 0,
|
||||
'timeout': 20
|
||||
}
|
||||
|
||||
SERIAL_SETTINGS_V4 = {
|
||||
'baudrate': 115200,
|
||||
'bytesize': serial.SEVENBITS,
|
||||
|
@ -13,6 +13,24 @@ This module contains DSMR telegram specifications. Each specifications describes
|
||||
how the telegram lines are parsed.
|
||||
"""
|
||||
|
||||
V2_2 = {
|
||||
EQUIPMENT_IDENTIFIER: CosemParser(ValueParser(str)),
|
||||
ELECTRICITY_USED_TARIFF_1: CosemParser(ValueParser(Decimal)),
|
||||
ELECTRICITY_USED_TARIFF_2: CosemParser(ValueParser(Decimal)),
|
||||
ELECTRICITY_DELIVERED_TARIFF_1: CosemParser(ValueParser(Decimal)),
|
||||
ELECTRICITY_DELIVERED_TARIFF_2: CosemParser(ValueParser(Decimal)),
|
||||
ELECTRICITY_ACTIVE_TARIFF: CosemParser(ValueParser(str)),
|
||||
CURRENT_ELECTRICITY_USAGE: CosemParser(ValueParser(Decimal)),
|
||||
CURRENT_ELECTRICITY_DELIVERY: CosemParser(ValueParser(Decimal)),
|
||||
ACTUAL_TRESHOLD_ELECTRICITY: CosemParser(ValueParser(Decimal)),
|
||||
ACTUAL_SWITCH_POSITION: CosemParser(ValueParser(str)),
|
||||
TEXT_MESSAGE_CODE: CosemParser(ValueParser(int)),
|
||||
TEXT_MESSAGE: CosemParser(ValueParser(str)),
|
||||
EQUIPMENT_IDENTIFIER_GAS: CosemParser(ValueParser(str)),
|
||||
DEVICE_TYPE: CosemParser(ValueParser(str)),
|
||||
VALVE_POSITION_GAS: CosemParser(ValueParser(str)),
|
||||
}
|
||||
|
||||
V4 = {
|
||||
P1_MESSAGE_HEADER: CosemParser(ValueParser(str)),
|
||||
P1_MESSAGE_TIMESTAMP: CosemParser(ValueParser(timestamp)),
|
||||
|
Loading…
Reference in New Issue
Block a user