Skip to content

Commit

Permalink
Merge pull request #20 from mdegat01/use-built-in-id-filter
Browse files Browse the repository at this point in the history
Use `rtlamr`'s built-in ID filter
  • Loading branch information
mdegat01 authored Nov 18, 2021
2 parents ef1de21 + d32f8c1 commit 0f73c90
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
12 changes: 7 additions & 5 deletions amr2mqtt/rootfs/amr2mqtt/amr2mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,14 @@ def send_mqtt(
time.sleep(10)

# start the rtlamr program.
rtlamr_cmd = [settings.RTLAMR, f"-msgtype={settings.MESSAGE_TYPES}", "-format=csv"]

# Add ID filter if we have a list of IDs to watch
if settings.WATCHED_METERS:
rtlamr_cmd += [f"-filterid={settings.WATCHED_METERS}"]

rtlamr = subprocess.Popen(
[settings.RTLAMR, f"-msgtype={settings.MESSAGE_TYPES}", "-format=csv"],
rtlamr_cmd,
stdout=subprocess.PIPE,
universal_newlines=True,
)
Expand Down Expand Up @@ -118,10 +124,6 @@ def send_mqtt(
else:
continue

# make sure the meter id is one we want
if settings.WATCHED_METERS and meter_id not in settings.WATCHED_METERS:
continue

# Process interval if message type supports it (IDM)
if interval_cur:
# skip if interval is the same as last time we sent to MQTT
Expand Down
9 changes: 4 additions & 5 deletions amr2mqtt/rootfs/amr2mqtt/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import logging

# List of the Meter IDs to watch
# Use empty brackets to read all meters - []
# List may contain only one entry - [12345678]
# or multiple entries - [12345678, 98765432, 12340123]
power_meters = os.environ["WATCHED_METERS"].split(",")
WATCHED_METERS = [int(meter_id) for meter_id in power_meters if meter_id]
# Use empty string to read all meters
# List may contain only one entry - "12345678"
# or multiple entries - "12345678,98765432,12340123"
WATCHED_METERS = os.environ["WATCHED_METERS"]

# List of message types to watch for
# Must be provided as only specific types are supported right now
Expand Down

0 comments on commit 0f73c90

Please sign in to comment.