Skip to content

Commit

Permalink
MQTT Retain Option
Browse files Browse the repository at this point in the history
  • Loading branch information
lolouk44 committed Mar 8, 2021
1 parent 1cf407f commit 929b9c4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [0.1.15] - 2021-03-08
### Changed
- Added MQTT Retain Option ([fixes #44](https://github.com/lolouk44/xiaomi_mi_scale/issues/44))
- Added MQTT TLS Option ([PR 43](https://github.com/lolouk44/xiaomi_mi_scale/pull/43))

## [0.1.14] - 2020-11-26
### Changed
- Reduced docker image size
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ services:
- MQTT_USERNAME= # Username for MQTT server (comment out if not required)
- MQTT_PASSWORD= # Password for MQTT (comment out if not required)
- MQTT_PORT= # Defaults to 1883
- MQTT_RETAIN=true # MQTT Retain Option, defaults to true
- MQTT_TLS_CACERTS= # MQTT TLS connection: directory with CA certificate(s) that signed MQTT Server's TLS certificate, defaults to None (= no TLS connection)
- MQTT_TLS_INSECURE= # MQTT TLS connection: don't verify hostname in TLS certificate, defaults to None (= always check hostname)
- TIME_INTERVAL=30 # Time in sec between each query to the scale, to allow other applications to use the Bluetooth module. Defaults to 30
Expand Down
12 changes: 11 additions & 1 deletion src/Xiaomi_Scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
except:
sys.stderr.write(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - MQTT Host not provided...\n")
raise
try:
MQTT_RETAIN = data["MQTT_RETAIN"]
except:
MQTT_RETAIN = True
pass
try:
MQTT_PORT = int(data["MQTT_PORT"])
except:
Expand Down Expand Up @@ -168,6 +173,11 @@
MQTT_USERNAME = os.getenv('MQTT_USERNAME', 'username')
MQTT_PASSWORD = os.getenv('MQTT_PASSWORD', None)
MQTT_HOST = os.getenv('MQTT_HOST', '127.0.0.1')
MQTT_RETAIN = os.getenv('MQTT_RETAIN', True)
if MQTT_RETAIN.lower() in ['true', '1', 'y', 'yes']:
MQTT_RETAIN = True
else:
MQTT_RETAIN = False
MQTT_PORT = int(os.getenv('MQTT_PORT', 1883))
MQTT_TLS_CACERTS = os.getenv('MQTT_TLS_CACERTS', None)
MQTT_TLS_INSECURE = os.getenv('MQTT_TLS_INSECURE', None)
Expand Down Expand Up @@ -318,7 +328,7 @@ def _publish(self, weight, unit, mitdatetime, hasImpedance, miimpedance):
MQTT_PREFIX + '/' + user + '/weight',
message,
# qos=1, #Removed qos=1 as incorrect connection details will result in the client waiting for ack from broker
retain=True,
retain=MQTT_RETAIN,
hostname=MQTT_HOST,
port=MQTT_PORT,
auth={'username':MQTT_USERNAME, 'password':MQTT_PASSWORD},
Expand Down

0 comments on commit 929b9c4

Please sign in to comment.