Skip to content

Commit

Permalink
Merge pull request #104 from allangood/dev
Browse files Browse the repository at this point in the history
Preparation for version 1.7.0
  • Loading branch information
allangood authored Apr 6, 2022
2 parents e93b7f5 + 548e2fc commit 4059392
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 15 deletions.
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@ This project was created to send readings made by RTLAMR + RTL_TCP to a MQTT bro
My user case is to integrate it with Home Assistant.

### Noteworthy Updates
*2022-04-04*
- New TLS parameters to MQTT connection
- New parameter: USB_RESET to address problem mentioned on #98

*2022-02-11*
- New configuration parameter: `state_class` (thanks to @JeffreyFalgout)
- Automatic MQTT configuration when using the Addon (thanks to @JeffreyFalgout)
- Fixed 255 characters limit for state value #86

*2022-01-11*
- Happy new year! :)
- Added "tickle_rtl_tcp" parameter to enable/disable the feature (explained below)
- Added date/time to the log output
- Added device_class configuration option #66 (thanks to @phidauex)
- Some clean up in the README file!
- Machine Learning to detect leaks still experimental and needs a lot of love to work properly

# Readme starts here

### What do I need?
Expand Down Expand Up @@ -55,6 +51,8 @@ general:
# Enable/disable the tickle_rtl_tcp. This is used to "shake" rtl_tcp to wake it up.
# For me, this started to cause the rtl_tcp to refuse connections and miss the readings.
tickle_rtl_tcp: false
# USB Reset. Use lsusb to get dev and bus number
usb_reset: '005:001'
# MQTT configuration.
mqtt:
Expand All @@ -70,6 +68,12 @@ mqtt:
host: 192.168.1.1
# MQTT port.
port: 1883
# TLS CA certificate
tls_ca: "/etc/ssl/certs/ca-certificates.crt"
# TLS server certificate
tls_cert: "/etc/ssl/my_server_cert.crt"
# TLS self-signed certificate/insecure certificate
tls_insecure: true
# MQTT user name if you have, remove if you don't use authentication
user: mqtt
# MQTT user password if you use one, remove if you don't use authentication
Expand Down
18 changes: 14 additions & 4 deletions rtlamr2mqtt-addon/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rtlamr2mqtt",
"version": "1.6.2",
"version": "1.7.0",
"slug": "rtlamr2mqtt",
"panel_icon": "mdi:gauge",
"description": "RTLAMR to MQTT Bridge",
Expand All @@ -25,11 +25,16 @@
"general": {
"sleep_for": 300,
"verbosity": "debug",
"tickle_rtl_tcp": false
"tickle_rtl_tcp": false,
"usb_reset": "005:002"
},
"mqtt": {
"ha_autodiscovery": true,
"ha_autodiscovery_topic": "homeassistant"
"ha_autodiscovery_topic": "homeassistant",
"tls_ca": "/etc/ssl/certs/ca-certificates.crt",
"tls_cert": "/etc/ssl/my_self_signed_cert.crt",
"tls_keyfile": "/etc/ssl/my_self_signed_cert_key.key",
"tls_insecure": true
},
"custom_parameters": {
"rtltcp": "-s 2048000",
Expand All @@ -51,11 +56,16 @@
"general": {
"sleep_for": "int",
"verbosity": "list(debug|normal)?",
"tickle_rtl_tcp": "bool?"
"tickle_rtl_tcp": "bool?",
"usb_reset": "str?"
},
"mqtt": {
"host": "str?",
"port": "int?",
"tls_ca": "str?",
"tls_cert": "str?",
"tls_keyfile": "str?",
"tls_insecure": "bool?",
"user": "str?",
"password": "str?",
"ha_autodiscovery": "bool?",
Expand Down
18 changes: 15 additions & 3 deletions rtlamr2mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@ def list_intersection(a, b):
return result[0] if result else None

class MqttSender:
def __init__(self, hostname, port, username, password):
def __init__(self, hostname, port, username, password, tls = None):
log_message('Configured MQTT sender:')
self.d = {}
self.d['hostname'] = hostname
self.d['port'] = int(port)
self.d['username'] = username
self.d['password'] = password
self.d['client_id'] = 'rtlamr2mqtt'
self.d['tls'] = tls
self.__log_mqtt_params(**self.d)

def __get_auth(self):
Expand All @@ -88,7 +89,7 @@ def publish(self, **kwargs):
try:
publish.single(
topic=topic, payload=payload, qos=qos, retain=retain, hostname=self.d['hostname'], port=self.d['port'],
client_id=self.d['client_id'], keepalive=60, will=will, auth=self.__get_auth(), tls=None
client_id=self.d['client_id'], keepalive=60, will=will, auth=self.__get_auth(), tls=self.d['tls']
)
except MQTTException as e:
log_message('MQTTException connecting to MQTT broker: {}'.format(e))
Expand Down Expand Up @@ -291,6 +292,17 @@ def sliding_mean(series):
or config['mqtt'].get('password')):
host = config['mqtt'].get('host', 'localhost')
port = config['mqtt'].get('port', 1883)
if 'tls_ca' in config['mqtt']:
tls_ca = config['mqtt'].get('tls_ca', '/etc/ssl/certs/ca-certificates.crt')
tls_cert = config['mqtt'].get('tls_cert', None)
tls_keyfile = config['mqtt'].get('tls_keyfile', None)
# ToDo: Create a easy interface for these parameters
tls_version = config['mqtt'].get('tls_version', None)
tls_ciphers = config['mqtt'].get('tls_ciphers', None)
tls_insecure = config['mqtt'].get('tls_insecure', False)
tls = { 'ca_certs': tls_ca, 'certfile': tls_cert, 'insecure': tls_insecure, 'keyfile': tls_keyfile, 'tls_version': tls_version, 'ciphers': tls_ciphers }
else:
tls = None
user = config['mqtt'].get('user')
password = config['mqtt'].get('password')
else:
Expand All @@ -312,7 +324,7 @@ def sliding_mean(series):
port = 1883
user = None
password = None
mqtt_sender = MqttSender(host, port, user, password)
mqtt_sender = MqttSender(host, port, user, password, tls)

ha_autodiscovery_topic = config['mqtt'].get('ha_autodiscovery_topic', 'homeassistant')
ha_autodiscovery = False
Expand Down
9 changes: 9 additions & 0 deletions rtlamr2mqtt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@ general:
sleep_for: 0
verbosity: debug
tickle_rtl_tcp: false
usb_reset: '005:001'

mqtt:
host: 127.0.0.1
# Path to CA certificate to use. Mandatory
tls_ca: '/etc/ssl/certs/ca-certificates.crt'
# Path to certificate file to use. Optional
tls_cert: '/etc/ssl/my_self_signed_cert.crt'
# TLS insecure: defaults to False
tls_insecure: true
# Certificate key file to use. Optional
tls_keyfile: '/etc/ssl/my_self_signed_cert_key.key'
user: test
password: testpassword
ha_autodiscovery: true
Expand Down

0 comments on commit 4059392

Please sign in to comment.