-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from falcovd/develop
Version 1.0
- Loading branch information
Showing
5 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
def extract_input(inp): | ||
try: | ||
splitted = inp.split(":") | ||
key_value = splitted[1].split("(") | ||
|
||
key = key_value[0] | ||
|
||
if key == "24.2.1": | ||
v = key_value[2] | ||
else: | ||
v = key_value[1] | ||
|
||
value = v.split(")")[0] | ||
|
||
return [key, value] | ||
except: | ||
return False | ||
|
||
def accepted_codes(): | ||
return ["1.8.1", "1.8.2", "2.8.1", "2.8.2", "1.7.0", "2.7.0", "21.7.0", "22.7.0", "24.2.1"] | ||
|
||
def get_floated_value(inp): | ||
val = inp.split("*") | ||
return float(val[0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from influxdb_client import InfluxDBClient, Point, Dialect | ||
from influxdb_client.client.write_api import SYNCHRONOUS | ||
|
||
def write(key, value): | ||
client = InfluxDBClient(url="http://localhost:8086", org="MyOrg") | ||
write_api = client.write_api(write_options=SYNCHRONOUS) | ||
point = Point("meterstanden").tag("Code", key).field("Value", value) | ||
write_api.write(bucket="smartmeter", record=[point]) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import serial | ||
import sys | ||
from Parser import DsmrParser, Influx | ||
|
||
############################################################################## | ||
# CONFIGS | ||
############################################################################## | ||
|
||
# DSMR Version 2 or 4. Check: http://domoticx.com/p1-poort-slimme-meter-hardware/ | ||
dsmr_version = 4 | ||
|
||
############################################################################## | ||
# Main program | ||
############################################################################## | ||
print("Smartmeter reader is starting...") | ||
|
||
# Set COM port config | ||
ser = serial.Serial() | ||
|
||
if dsmr_version == 2: | ||
ser.baudrate = 9600 | ||
ser.bytesize = serial.SEVENBITS | ||
ser.parity = serial.PARITY_EVEN | ||
ser.stopbits = serial.STOPBITS_ONE | ||
else : | ||
if dsmr_version == 4: | ||
ser.baudrate = 115200 | ||
ser.bytesize = serial.EIGHTBITS | ||
ser.parity = serial.PARITY_NONE | ||
ser.stopbits = serial.STOPBITS_ONE | ||
else : | ||
sys.exit("Invalid DSMR Version") | ||
|
||
ser.xonxoff = 0 | ||
ser.rtscts = 0 | ||
ser.timeout = 30 | ||
|
||
ser.port = "/dev/ttyUSB0" | ||
|
||
# Open COM port | ||
try: | ||
ser.open() | ||
print("Connected...") | ||
except: | ||
sys.exit("Fout bij het openen van %s." % ser.name) | ||
|
||
while True: | ||
raw = ser.readline().decode('ascii') | ||
raw_as_string = str(raw) | ||
line = raw_as_string.strip() | ||
extracted = DsmrParser.extract_input(line) | ||
|
||
if extracted: | ||
if extracted[0] in DsmrParser.accepted_codes(): | ||
Influx.write(extracted[0], DsmrParser.get_floated_value(extracted[1])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pyserial | ||
influxdb_client |