Skip to content

Instantly share code, notes, and snippets.

@roaldnefs
Created July 18, 2019 19:21
Show Gist options
  • Save roaldnefs/ecc3adbdcca9930d7fcea32718b3a8f2 to your computer and use it in GitHub Desktop.
Save roaldnefs/ecc3adbdcca9930d7fcea32718b3a8f2 to your computer and use it in GitHub Desktop.
DSMR Emulator (Python)
#!/usr/bin/env python
# socat -d -d pty,raw,echo=0 pty,raw,echo=0
import serial
import time
import argparse
TELEGRAM1 = """/ISK5\2M550T-1012
1-3:0.2.8(50)
0-0:1.0.0(190718204947S)
0-0:96.1.1(4530303434303037333238393733373139)
1-0:1.8.1(000166.123*kWh)
1-0:1.8.2(000154.007*kWh)
1-0:2.8.1(000000.000*kWh)
1-0:2.8.2(000000.000*kWh)
0-0:96.14.0(0002)
1-0:1.7.0(00.254*kW)
1-0:2.7.0(00.000*kW)
0-0:96.7.21(00006)
0-0:96.7.9(00002)
1-0:99.97.0()
1-0:32.32.0(00002)
1-0:52.32.0(00002)
1-0:72.32.0(00002)
1-0:32.36.0(00001)
1-0:52.36.0(00001)
1-0:72.36.0(00001)
0-0:96.13.0()
1-0:32.7.0(234.5*V)
1-0:52.7.0(234.6*V)
1-0:72.7.0(234.7*V)
1-0:31.7.0(000*A)
1-0:51.7.0(001*A)
1-0:71.7.0(002*A)
1-0:21.7.0(00.093*kW)
1-0:41.7.0(00.004*kW)
1-0:61.7.0(00.155*kW)
1-0:22.7.0(00.000*kW)
1-0:42.7.0(00.000*kW)
1-0:62.7.0(00.000*kW)
0-1:24.1.0(003)
0-1:96.1.0(4730303332353635353737383036333138)
0-1:24.2.1(190718204507S)(00021.302*m3)
!4324
"""
TELEGRAM2 = """/ISK5\2M550T-1012
1-3:0.2.8(50)
0-0:1.0.0(190718204948S)
0-0:96.1.1(4530303434303037333238393733373139)
1-0:1.8.1(000166.123*kWh)
1-0:1.8.2(000154.007*kWh)
1-0:2.8.1(000000.000*kWh)
1-0:2.8.2(000000.000*kWh)
0-0:96.14.0(0002)
1-0:1.7.0(00.256*kW)
1-0:2.7.0(00.000*kW)
0-0:96.7.21(00006)
0-0:96.7.9(00002)
1-0:99.97.0()
1-0:32.32.0(00002)
1-0:52.32.0(00002)
1-0:72.32.0(00002)
1-0:32.36.0(00001)
1-0:52.36.0(00001)
1-0:72.36.0(00001)
0-0:96.13.0()
1-0:32.7.0(234.6*V)
1-0:52.7.0(234.6*V)
1-0:72.7.0(234.7*V)
1-0:31.7.0(001*A)
1-0:51.7.0(002*A)
1-0:71.7.0(003*A)
1-0:21.7.0(00.093*kW)
1-0:41.7.0(00.005*kW)
1-0:61.7.0(00.155*kW)
1-0:22.7.0(00.000*kW)
1-0:42.7.0(00.000*kW)
1-0:62.7.0(00.000*kW)
0-1:24.1.0(003)
0-1:96.1.0(4730303332353635353737383036333138)
0-1:24.2.1(190718204507S)(00021.302*m3)
!85B2
"""
TELEGRAM3 = """/ISK5\2M550T-1012
1-3:0.2.8(50)
0-0:1.0.0(190718204949S)
0-0:96.1.1(4530303434303037333238393733373139)
1-0:1.8.1(000166.123*kWh)
1-0:1.8.2(000154.007*kWh)
1-0:2.8.1(000000.000*kWh)
1-0:2.8.2(000000.000*kWh)
0-0:96.14.0(0002)
1-0:1.7.0(00.259*kW)
1-0:2.7.0(00.000*kW)
0-0:96.7.21(00006)
0-0:96.7.9(00002)
1-0:99.97.0()
1-0:32.32.0(00002)
1-0:52.32.0(00002)
1-0:72.32.0(00002)
1-0:32.36.0(00001)
1-0:52.36.0(00001)
1-0:72.36.0(00001)
0-0:96.13.0()
1-0:32.7.0(234.6*V)
1-0:52.7.0(234.5*V)
1-0:72.7.0(234.7*V)
1-0:31.7.0(002*A)
1-0:51.7.0(003*A)
1-0:71.7.0(004*A)
1-0:21.7.0(00.093*kW)
1-0:41.7.0(00.004*kW)
1-0:61.7.0(00.157*kW)
1-0:22.7.0(00.000*kW)
1-0:42.7.0(00.000*kW)
1-0:62.7.0(00.000*kW)
0-1:24.1.0(003)
0-1:96.1.0(4730303332353635353737383036333138)
0-1:24.2.1(190718204507S)(00021.302*m3)
!8BB8
"""
TELEGRAMS = [TELEGRAM1, TELEGRAM2, TELEGRAM3]
def create_parser():
parser = argparse.ArgumentParser(
description='Dutch Smart Meter Requirements Emulator'
)
parser.add_argument(
'port', metavar='port', type=str,
help='Serial port'
)
return parser
def main():
parser = create_parser()
args = parser.parse_args()
try:
serial_port = serial.Serial(args.port, 115200, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=1)
except serial.SerialException as e:
print(e)
else:
print("Opened: %s" % serial_port.name)
idx = 0
while True:
serial_port.write(TELEGRAMS[idx])
idx += 1
# Reset
if idx == len(TELEGRAMS):
idx = 0
time.sleep(1)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment