diff --git a/docker-compose.yml b/docker-compose.yml index 81a05ea..b723a39 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 @@ -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! diff --git a/src/Xiaomi_Scale.py b/src/Xiaomi_Scale.py index 16c8092..55d12a7 100644 --- a/src/Xiaomi_Scale.py +++ b/src/Xiaomi_Scale.py @@ -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... @@ -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 += '}' @@ -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() \ No newline at end of file