{"id":1757,"date":"2025-06-29T20:53:18","date_gmt":"2025-06-29T17:53:18","guid":{"rendered":"https:\/\/datadigging.ru\/?p=1757"},"modified":"2025-07-02T22:04:42","modified_gmt":"2025-07-02T19:04:42","slug":"%d1%81%d0%ba%d1%80%d0%b8%d0%bf%d1%82-%d0%b4%d0%bb%d1%8f-%d0%bf%d0%be%d0%b4%d0%ba%d0%bb%d1%8e%d1%87%d0%b5%d0%bd%d0%b8%d1%8f-%d0%ba-%d0%b2%d0%b5%d1%81%d0%b0%d0%bc-xiaomi-miscale-2-%d0%b8-%d0%bf%d0%b0","status":"publish","type":"post","link":"https:\/\/datadigging.ru\/?p=1757","title":{"rendered":"\u0421\u043a\u0440\u0438\u043f\u0442 \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0432\u0435\u0441\u0430\u043c Xiaomi MiScale 2 \u0438 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u0434\u0430\u043d\u043d\u044b\u0445"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u0414\u0430\u0432\u043d\u043e \u0445\u043e\u0442\u0435\u043b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a \u0432\u0435\u0441\u0430\u043c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c  \u043d\u043e\u0432\u043e\u0441\u0442\u0438 \u043e \u0441\u0432\u043e\u0435\u043c \u043f\u043e\u0445\u0443\u0434\u0435\u043d\u0438\u0438 \u043c\u0438\u043d\u0443\u044f  \u0436\u0430\u0434\u043d\u044b\u0445 \u0434\u043e \u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u0441\u044f\u043e\u043c\u0446\u0435\u0432<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u041d\u0430\u043c\u0435\u0434\u043d\u0438, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0414\u0438\u043f\u0441\u0438\u043a\u0430 (\u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0435\u043c\u0443 \u043f\u043e\u043c\u043e\u0447\u044c, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0432  \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u0442\u0432\u0435\u0442\u0435 \u0432\u0435\u0441\u043e\u0432) \u0437\u0430 15 \u043c\u0438\u043d\u0443\u0442 \u043d\u0430\u043a\u0430\u0440\u044f\u0431\u0430\u043b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import asyncio\nfrom bleak import BleakClient, BleakScanner\nfrom bleak.exc import BleakError\n\nSCALE_MAC = \"00:00:00:00:00:00\" # MAC \u0430\u0434\u0440\u0435\u0441 \u0432\u0435\u0441\u043e\u0432 \u0438\u0437 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f Zepp Life\n\nSERVICE_UUID = \"0000181b-0000-1000-8000-00805f9b34fb\" # \u041e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u043a \u0435\u0441\u0442\u044c\nCHARACTERISTIC_UUID = \"00002a9c-0000-1000-8000-00805f9b34fb\" # \u041e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u043a \u0435\u0441\u0442\u044c\n\ndef parse_scale_data(data):\n\n    if len(data) &lt; 13:\n        return None\n    \n    status_byte = data&#91;1]\n    is_fixed = status_byte &amp; 0x02\n    has_impedance = status_byte &amp; 0x04\n    \n    raw_weight = int.from_bytes(data&#91;11:13], byteorder='little')\n    weight_kg = raw_weight * 0.005\n    \n    return {\n        'weight': weight_kg,\n        'is_final': is_fixed,\n        'is_stabilized': is_fixed,\n        'raw_weight': raw_weight,\n        'has_impedance': has_impedance,\n        'impedance': int.from_bytes(data&#91;9:11], byteorder='little') if has_impedance else None\n    }\n\ndef notification_handler(sender, data):\n    \"\"\"\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439\"\"\"\n    if len(data) &lt; 13 or data&#91;0] != 0x02:\n        return\n    \n    parsed = parse_scale_data(data)\n    if not parsed:\n        return\n    \n    if parsed&#91;'is_final']:\n        print(f\"\\n\u0424\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0435\u0441: {parsed&#91;'weight']:.2f} \u043a\u0433\")\n        if parsed&#91;'has_impedance']:\n            print(f\"\u0418\u043c\u043f\u0435\u0434\u0430\u043d\u0441: {parsed&#91;'impedance']} \u041e\u043c\")\n    else:\n        print(f\"\u0418\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0435: {parsed&#91;'weight']:.2f} \u043a\u0433\", end='\\r')\n\nasync def monitor_scale():\n    \"\"\"\u041f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u044b\u0439 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0432\u0435\u0441\u043e\u0432\"\"\"\n    while True:\n        print(\"\\n--- \u041d\u0430\u0447\u0438\u043d\u0430\u044e \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 ---\")\n        try:\n            # \u0421\u043a\u0430\u043d\u0438\u0440\u0443\u0435\u043c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e\n            device = await BleakScanner.find_device_by_address(SCALE_MAC, timeout=10)\n            if not device:\n                print(\"\u0412\u0435\u0441\u044b \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u044b, \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e \u0447\u0435\u0440\u0435\u0437 5 \u0441\u0435\u043a\u0443\u043d\u0434...\")\n                await asyncio.sleep(5)\n                continue\n\n            print(f\"\u041d\u0430\u0439\u0434\u0435\u043d\u044b \u0432\u0435\u0441\u044b {device.name}, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u044e\u0441\u044c...\")\n            \n            async with BleakClient(device) as client:\n                print(\"\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043e. \u0412\u0441\u0442\u0430\u043d\u044c\u0442\u0435 \u043d\u0430 \u0432\u0435\u0441\u044b...\")\n                await client.start_notify(CHARACTERISTIC_UUID, notification_handler)\n                \n                # \u0416\u0434\u0435\u043c \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438\u043b\u0438 5 \u043c\u0438\u043d\u0443\u0442 \u0431\u0435\u0437\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\n                try:\n                    while True:\n                        await asyncio.sleep(1)\n                        if not client.is_connected:\n                            print(\"\\n\u0421\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u0442\u0435\u0440\u044f\u043d\u043e\")\n                            break\n                except Exception as e:\n                    print(f\"\\n\u041e\u0448\u0438\u0431\u043a\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f: {e}\")\n                finally:\n                    try:\n                        await client.stop_notify(CHARACTERISTIC_UUID)\n                    except:\n      0                  pass\n                    print(\"\u041e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u043e\")\n                    \n        except Exception as e:\n            print(f\"\\n\u041e\u0448\u0438\u0431\u043a\u0430: {e}\")\n            await asyncio.sleep(5)\n\n# \u0414\u043b\u044f Jupyter Notebook\ntry:\n    await monitor_scale()\nexcept KeyboardInterrupt:\n    print(\"\\n\u041c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\")\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u041a\u043e\u0434 \u0440\u0430\u0431\u043e\u0447\u0438\u0439, \u0441 \u0447\u0435\u043c \u0441\u0435\u0431\u044f \u0438 \u043f\u043e\u0437\u0434\u0440\u0430\u0432\u043b\u044f\u044e.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u041e\u0447\u0435\u043d\u044c \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u0434\u043e\u0431\u044b\u0447\u0435\u0439 \u0432\u0441\u0435\u0445 \u0434\u0430\u043d\u043d\u044b\u0445  \u0438\u0437 Zepp Life, \u043d\u043e \u0441 \u044d\u0442\u0438\u043c \u043f\u043e\u043a\u0430 \u043d\u0435\u043f\u0440\u043e\u0441\u0442\u043e.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0414\u0430\u0432\u043d\u043e \u0445\u043e\u0442\u0435\u043b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a \u0432\u0435\u0441\u0430\u043c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u043e\u0441\u0442\u0438 \u043e \u0441\u0432\u043e\u0435\u043c \u043f\u043e\u0445\u0443\u0434\u0435\u043d\u0438\u0438 \u043c\u0438\u043d\u0443\u044f \u0436\u0430\u0434\u043d\u044b\u0445 \u0434\u043e \u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u0441\u044f\u043e\u043c\u0446\u0435\u0432 \u041d\u0430\u043c\u0435\u0434\u043d\u0438, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0414\u0438\u043f\u0441\u0438\u043a\u0430 (\u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0435\u043c\u0443 \u043f\u043e\u043c\u043e\u0447\u044c, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0432 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u0442\u0432\u0435\u0442\u0435 \u0432\u0435\u0441\u043e\u0432) \u0437\u0430 15 \u043c\u0438\u043d\u0443\u0442 \u043d\u0430\u043a\u0430\u0440\u044f\u0431\u0430\u043b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435: \u041a\u043e\u0434 &hellip; <a href=\"https:\/\/datadigging.ru\/?p=1757\">\u0427\u0438\u0442\u0430\u0442\u044c \u0434\u0430\u043b\u0435\u0435 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"footnotes":""},"categories":[129,116],"tags":[9,16,8,22],"class_list":["post-1757","post","type-post","status-publish","format-standard","hentry","category-blog","category-116","tag-python","tag-16","tag-8","tag-22"],"_links":{"self":[{"href":"https:\/\/datadigging.ru\/index.php?rest_route=\/wp\/v2\/posts\/1757","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/datadigging.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/datadigging.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/datadigging.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/datadigging.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1757"}],"version-history":[{"count":3,"href":"https:\/\/datadigging.ru\/index.php?rest_route=\/wp\/v2\/posts\/1757\/revisions"}],"predecessor-version":[{"id":1762,"href":"https:\/\/datadigging.ru\/index.php?rest_route=\/wp\/v2\/posts\/1757\/revisions\/1762"}],"wp:attachment":[{"href":"https:\/\/datadigging.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1757"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/datadigging.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1757"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/datadigging.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1757"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}