Skip to content

Commit

Permalink
TIME_INTERVAL Addition
Browse files Browse the repository at this point in the history
  • Loading branch information
lolouk44 committed May 21, 2020
1 parent 422b6ed commit 42f3aa4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
6 changes: 4 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ version: '3'
services:

mi-scale:
image: lolouk44/xiaomi-mi-scale:latest
build: .
#image: lolouk44/xiaomi-mi-scale:latest
container_name: mi-scale
restart: always

Expand All @@ -12,11 +13,12 @@ services:
environment:
- MISCALE_MAC=d4:00:00:00:00:00 # Mac address of your scale
- MQTT_HOST=127.0.0.1 # MQTT Server (defaults to 127.0.0.1)
- MQTT_PREFIX=miScale
- MQTT_PREFIX=miscale # MQTT Prefix, defaults to miscale
- MQTT_USERNAME= # Username for MQTT server (comment out if not required)
- MQTT_PASSWORD= # Password for MQTT (comment out if not required)
- MQTT_PORT=1883 # Defaults to 1883
- MQTT_TIMEOUT=60 # Defaults to 60
- TIME_INTERVAL=30 # Time in sec between each query to the scale, to allow other applications to use the Bluetooth module. Defaults to 30

# Auto-gender selection/config -- This is used to create the calculations such as BMI, Water/Bone Mass etc...
# Up to 3 users possible as long as weights do not overlap!
Expand Down
17 changes: 10 additions & 7 deletions src/Xiaomi_Scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
MQTT_HOST = os.getenv('MQTT_HOST', '127.0.0.1')
MQTT_PORT = int(os.getenv('MQTT_PORT', 1883))
MQTT_TIMEOUT = int(os.getenv('MQTT_TIMEOUT', 60))
MQTT_PREFIX = os.getenv('MQTT_PREFIX', '')
MQTT_PREFIX = os.getenv('MQTT_PREFIX', 'miscale')
TIME_INTERVAL = os.getenv('TIME_INTERVAL, '30')
OLD_MEASURE = ''

# User Variables...
Expand Down Expand Up @@ -156,6 +157,8 @@ def _publish(self, weight, unit, mitdatetime, hasImpedance, miimpedance):
message += ',"Bone Mass":"' + "{:.2f}".format(lib.getBoneMass()) + '"'
message += ',"Muscle Mass":"' + "{:.2f}".format(lib.getMuscleMass()) + '"'
message += ',"Protein":"' + "{:.2f}".format(lib.getProteinPercentage()) + '"'
#message += ',"Body Type":"' + str(lib.getBodyTypeScale(getBodyType())) + '"'
#message += ',"Metabolic Age":"' + str(lib.getMetabolicAge()) + '"'

message += ',"TimeStamp":"' + mitdatetime + '"'
message += '}'
Expand All @@ -169,12 +172,12 @@ def main():
sys.stdout.write('Starting Xiaomi mi Scale...\n')
scanner = btle.Scanner().withDelegate(ScanProcessor())
while True:
# try:
scanner.scan(5)
# except:
# sys.stderr.write("Error while running the script, continuing. If you see this message too often/constantly there is probably a real issue...\n")
# pass
time.sleep(1)
try:
scanner.scan(5, passive=True) # Adding passive=True to try and fix issues on RPi devices
except:
sys.stderr.write("Error while running the script, continuing. If you see this message too often/constantly there is probably a real issue...\n")
pass
time.sleep(TIME_INTERVAL)

if __name__ == "__main__":
main()

0 comments on commit 42f3aa4

Please sign in to comment.