Skip to content

Commit

Permalink
Merge pull request #146 from allangood/dev
Browse files Browse the repository at this point in the history
Fix for #141
  • Loading branch information
allangood authored Jun 14, 2022
2 parents 903337b + c7f848f commit b40b499
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion rtlamr2mqtt-addon/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: rtlamr2mqtt
version: 2.2.0
version: 2.2.1
slug: rtlamr2mqtt
panel_icon: mdi:gauge
description: RTLAMR to MQTT Bridge
Expand Down
16 changes: 11 additions & 5 deletions rtlamr2mqtt-addon/rtlamr2mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import signal
import subprocess
import socket
import ssl
import warnings
from datetime import datetime
from json import dumps, loads
Expand Down Expand Up @@ -103,11 +104,11 @@ def __init__(self, mqtt_config):
tls_enabled = mqtt_config.get('tls_enabled', False)
tls_ca = mqtt_config.get('tls_ca', '/etc/ssl/certs/ca-certificates.crt')
tls_cert = mqtt_config.get('tls_cert', None)
tls_insecure = mqtt_config.get('tls_insecure', True)
cert_reqs = ssl.CERT_NONE if mqtt_config.get('tls_insecure', True) else ssl.CERT_REQUIRED
tls_keyfile = mqtt_config.get('tls_keyfile', None)
self.d['tls'] = None
if tls_enabled:
self.d['tls'] = { 'ca_certs': tls_ca, 'certfile': tls_cert, 'keyfile': tls_keyfile, 'tls_insecure': tls_insecure }
self.d['tls'] = { 'ca_certs': tls_ca, 'certfile': tls_cert, 'keyfile': tls_keyfile, 'cert_reqs': cert_reqs }
self.__log_mqtt_params(**self.d)

def __get_auth(self):
Expand Down Expand Up @@ -148,7 +149,7 @@ def shutdown(signum, frame):
log_message('Kill process called.')
else:
log_message('Shutdown detected, killing process.')
if 'rtltcp' in locals() and rtltcp.returncode is None:
if not external_rtl_tcp and rtltcp.returncode is None:
log_message('Killing RTL_TCP...')
rtltcp.terminate()
try:
Expand Down Expand Up @@ -441,9 +442,7 @@ def listen_mode():

availability_topic = '{}/status'.format(config['mqtt']['base_topic'])


meter_readings = {}

# Build dict of meter configs
meters = {}
meter_names = set()
Expand Down Expand Up @@ -524,6 +523,13 @@ def listen_mode():
# This is a counter to count the number of duplicate error messages
error_count = 0
for amrline in rtlamr.stdout:
if not external_rtl_tcp and ('rtltcp' not in locals() or rtltcp.poll() is not None):
try:
outs, errs = rtltcp.communicate(timeout=5)
except subprocess.TimeoutExpired:
outs = None
if outs is not None:
log_message('RTL_TCP: {}'.format(outs))
if is_an_error_message(amrline):
if error_count < 1:
log_message('Error reading samples from RTL_TCP.')
Expand Down

0 comments on commit b40b499

Please sign in to comment.