Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use rtlamr's built-in ID filter #20

Merged
merged 1 commit into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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