Polar devices Python API and CLI.

Overview

loophole - Polar devices API

PyPI Join the chat at https://gitter.im/rsc-dev/loophole

About

Python API for Polar devices. Command line interface included.

Tested with:

  • A360
  • Loop
  • M400

Installation

pip install loophole

or

python setup.py install

Usage

CLI

Invoke CLI:

python __main__.py

Type '?' or 'help' to see available commands.

 _|                                _|                  _|
 _|    _|_|      _|_|    _|_|_|    _|_|_|      _|_|    _|    _|_|
 _|  _|    _|  _|    _|  _|    _|  _|    _|  _|    _|  _|  _|_|_|_|
 _|  _|    _|  _|    _|  _|    _|  _|    _|  _|    _|  _|  _|
 _|    _|_|      _|_|    _|_|_|    _|    _|    _|_|    _|    _|_|_|
                         _|
                         _|
                                                           ver. 0.3

loophole(no device)>?

Documented commands (type help <topic>):
========================================
connect  disconnect  exit  help  info  list  walk
Command Description
connect <dev_no> Connect Polar device. Run 'list' to see available devices.
disconnect Disconnect Polar device.
dump <dest> Dump device memory.
get <src> <dest> Read file from device.
exit Quit.
help List available commands with "help" or detailed help with "help cmd".
info Print connected device info.
list List available Polar devices.
walk [path] Walk file system. Default path is root path (\).

permissions

Note: You need the right permission to access the USB device. Otherwise you will get the error: The device has no langid

e.g.: run as root via sudo:

sudo python __main__.py

Or create udev role.

cat - > /etc/udev/rules.d/40-Polar_A360.rules << EOF
#Polar A360 permissions granted to users group
SUBSYSTEM=="usb", ATTRS{idProduct}=="0008", ATTRS{idVendor}=="0da4", MODE="0660", GROUP="plugdev"
SUBSYSTEMS=="usb-serial", MODE="0660", GROUP="plugdev"
EOF

udevadm control --reload-rules && udevadm trigger

Dependencies

for debian/ubuntu:

sudo apt install python-protobuf python-usb

Changelog

Here.

License

Code is released under MIT license © Radoslaw '[rsc]' Matusiak.

Comments
  • Device 'reset'

    Device 'reset'

    What files do I have to delete from the device to get it working again? I deleted every file with date on it but it still says "please sync".

    I would like to use only this software to get it working because I only have linux and I don't want it to connect to Internet. My computer should be enough.

    opened by haivala 6
  • ValueError: The device has no langid

    ValueError: The device has no langid

    I have a Polar A360, Firmware v1.2.60, HW-Model 00756861.01

    Traceback (most recent call last):
      File "__main__.py", line 285, in <module>
        main()
      File "__main__.py", line 278, in main
        cli.cmdloop(__INTRO.format(__version__))
      File "/usr/lib/python2.7/cmd.py", line 142, in cmdloop
        stop = self.onecmd(line)
      File "/usr/lib/python2.7/cmd.py", line 221, in onecmd
        return func(arg)
      File "__main__.py", line 75, in do_list
        info = Device.get_info(dev)
      File "/media/servershare/repos/polar_venv/src/loophole/loophole/polar/__init__.py", line 660, in get_info
        return usb.get_info(usb_device)
      File "/media/servershare/repos/polar_venv/src/loophole/loophole/polar/__init__.py", line 578, in get_info
        return self.usb.get_info(usb_device)
      File "/media/servershare/repos/polar_venv/src/loophole/loophole/polar/__init__.py", line 476, in get_info
        info['manufacturer'] = self.usb.util.get_string(usb_device, usb_device.iManufacturer)
      File "/media/servershare/repos/polar_venv/src/pyusb/usb/util.py", line 314, in get_string
        raise ValueError("The device has no langid")
    ValueError: The device has no langid
    
    $ lsusb 
    ...
    Bus 001 Device 004: ID 0da4:0008 Polar Electro Oy Loop
    ...
    

    the print output of Device.list() entry is:

    0 DEVICE ID 0da4:0008 on Bus 001 Address 004 =================
     bLength                :   0x12 (18 bytes)
     bDescriptorType        :    0x1 Device
     bcdUSB                 :  0x200 USB 2.0
     bDeviceClass           :    0x0 Specified at interface
     bDeviceSubClass        :    0x0
     bDeviceProtocol        :    0x0
     bMaxPacketSize0        :   0x40 (64 bytes)
     idVendor               : 0x0da4
     idProduct              : 0x0008
     bcdDevice              :  0x100 Device 1.0
     iManufacturer          :    0x1 Error Accessing String
     iProduct               :    0x2 Error Accessing String
     iSerialNumber          :    0x3 Error Accessing String
     bNumConfigurations     :    0x1
      CONFIGURATION 1: 350 mA ==================================
       bLength              :    0x9 (9 bytes)
       bDescriptorType      :    0x2 Configuration
       wTotalLength         :   0x29 (41 bytes)
       bNumInterfaces       :    0x1
       bConfigurationValue  :    0x1
       iConfiguration       :    0x4 Error Accessing String
       bmAttributes         :   0x80 Bus Powered
       bMaxPower            :   0xaf (350 mA)
        INTERFACE 0: Human Interface Device ====================
         bLength            :    0x9 (9 bytes)
         bDescriptorType    :    0x4 Interface
         bInterfaceNumber   :    0x0
         bAlternateSetting  :    0x0
         bNumEndpoints      :    0x2
         bInterfaceClass    :    0x3 Human Interface Device
         bInterfaceSubClass :    0x0
         bInterfaceProtocol :    0x0
         iInterface         :    0x5 Error Accessing String
          ENDPOINT 0x81: Interrupt IN ==========================
           bLength          :    0x7 (7 bytes)
           bDescriptorType  :    0x5 Endpoint
           bEndpointAddress :   0x81 IN
           bmAttributes     :    0x3 Interrupt
           wMaxPacketSize   :   0x40 (64 bytes)
           bInterval        :    0x1
          ENDPOINT 0x1: Interrupt OUT ==========================
           bLength          :    0x7 (7 bytes)
           bDescriptorType  :    0x5 Endpoint
           bEndpointAddress :    0x1 OUT
           bmAttributes     :    0x3 Interrupt
           wMaxPacketSize   :   0x40 (64 bytes)
           bInterval        :    0x1
    
    

    virtualenv info:

    $ pip freeze
    appdirs==1.4.3
    packaging==16.8
    pkg-resources==0.0.0
    protobuf==3.2.0
    pyparsing==2.2.0
    -e git+https://github.com/walac/pyusb.git@1f66ccd5d252e969b1de9bf91bf24e5c64294b8d#egg=pyusb
    six==1.10.0
    
    opened by jedie 5
  • convert  polar byte array into txt files

    convert polar byte array into txt files

    We want to use a polar A360 in our hospital. And as you can imaging we are not happy (and allowed to) to send de data of our patients into the Polar cloud. So I was very happy to find your software. I installed the software onto a windows system en was able to connect en read/dump the files from the connected device. I nerver used python before so as far I can understand you use the protocol buffers to decode the files when they are read from the device but how can I convert the files into a readable format ( e.g text ) so we can use then in excel ? Regards Bart Nienhuis

    opened by smkresearch 3
  • Display example udev rule...

    Display example udev rule...

    ...and how can it looks like?!?

    Maybe display a example udev rule, if the current user can't access, as here #8

    Maybe something like this:

    SUBSYSTEMS=="usb", ATTRS{idVendor}=="0da4", ATTRS{idProduct}=="0008", OWNER="<username>"

    Fill ids and username automaticlly. (I don't test this rule and don't know if it`s a good idea and a common rule...)

    opened by jedie 2
  • loophole exits exceptionaly with:

    loophole exits exceptionaly with: "The device has no langid"

    I have m400 connected to usb and when trying to list devices using loophole I get this:

    loophole(no device)>list
    Traceback (most recent call last):
      File "__main__.py", line 241, in <module>
        main()
      File "__main__.py", line 234, in main
        cli.cmdloop(__INTRO.format(__version__))
      File "/usr/lib/python2.7/cmd.py", line 142, in cmdloop
        stop = self.onecmd(line)
      File "/usr/lib/python2.7/cmd.py", line 221, in onecmd
        return func(arg)
      File "__main__.py", line 74, in do_list
        info = Device.get_info(dev)
      File "/home/lklich/Projects/loophole/loophole/polar/__init__.py", line 549, in get_info
        return usb.get_info(usb_device)
      File "/home/lklich/Projects/loophole/loophole/polar/__init__.py", line 472, in get_info
        return self.usb.get_info(usb_device)
      File "/home/lklich/Projects/loophole/loophole/polar/__init__.py", line 370, in get_info
        info['manufacturer'] = self.usb.util.get_string(usb_device, usb_device.iManufacturer)
      File "/usr/local/lib/python2.7/dist-packages/usb/util.py", line 314, in get_string
        raise ValueError("The device has no langid")
    ValueError: The device has no langid
    

    My lsusb (if needed):

    ➜  loophole git:(master) lsusb                                                                                                                                                                git:(master|) 
    Bus 001 Device 004: ID 0a5c:5800 Broadcom Corp. BCM5880 Secure Applications Processor
    Bus 001 Device 003: ID 8087:07dc Intel Corp. 
    Bus 001 Device 002: ID 8087:8000 Intel Corp. 
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    Bus 002 Device 002: ID 1bcf:2985 Sunplus Innovation Technology Inc. Laptop Integrated Webcam HD
    Bus 002 Device 003: ID 0da4:0008 Polar Electro Oy Loop
    Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    

    I'm using ubuntu 16.04 with kernel 4.4

    opened by kleewho 2
  • What types of data can be downloaded?

    What types of data can be downloaded?

    I am really interested in accessing detailed sleep and heart rate data. What types of data can be downloaded with this library? Is there any sample data available for a demo?

    opened by brylie 1
  • dump will not end

    dump will not end

    The "dump" will save many files, but it will not end and "hang"...

    Strg-C will raise this:

      File "src/loophole/loophole/__main__.py", line 185, in do_dump
        data = self.device.read_file('{}{}'.format(directory, file.name))
      File "/home/jens/workspace/polar_venv/src/loophole/loophole/polar/__init__.py", line 728, in read_file
        resp = self.usb.send(request=req)
      File "/home/jens/workspace/polar_venv/src/loophole/loophole/polar/__init__.py", line 606, in send
        resp = self.usb.send(request, timeout)
      File "/home/jens/workspace/polar_venv/src/loophole/loophole/polar/__init__.py", line 542, in send
        data = self.__send_wait(ack, timeout)
      File "/home/jens/workspace/polar_venv/src/loophole/loophole/polar/__init__.py", line 436, in __send_wait
        response = self.ep_in_0.read(64, timeout)
      File "/home/jens/workspace/polar_venv/src/pyusb/usb/core.py", line 402, in read
        return self.device.read(self, size_or_buffer, timeout)
      File "/home/jens/workspace/polar_venv/src/pyusb/usb/core.py", line 988, in read
        self.__get_timeout(timeout))
      File "/home/jens/workspace/polar_venv/src/pyusb/usb/backend/libusb1.py", line 851, in intr_read
        timeout)
      File "/home/jens/workspace/polar_venv/src/pyusb/usb/backend/libusb1.py", line 933, in __read
        timeout)
    KeyboardInterrupt
    

    Maybe the default timeout=2000 is a little bit to long?!?

    EDIT: I not see that the last file is: /SYS/FONT/JA.SIF (3135521 bytes) maybe it needs more time, because it`s a big file?!? Is it possible to display some status information?!?

    opened by jedie 1
  • Windows 10 - permission problem finding and configuring USB device

    Windows 10 - permission problem finding and configuring USB device

    I am trying to diagnose a Windows permission problem using pyusb.

    It shows up with the typical errors "The device has no langid (permission issue, no string descriptors supported or device error)" and "The device has no langid (permission issue, no string descriptors supported or device error)"

    Test code is simple, just find and print the dev to see if strings have been fetched and try to do a set configuration.

    This works correctly on Linux and several of my Windows test systems (both Windows 10 and 11.)

    But it is failing consistently on one Windows 10 system.

    The device in question is a Garmin Ant+ (aka Dynastream) dongle. It can be accessed by other software correctly on that system. I have tried several different ones, as well as a Cycplus Ant+ dongle. None can be accessed.

    I have also tried running the test program from a command prompt started as system administrator. No differences.

    I am testing this with a pyinstaller created exe that bundles in the libusb-1.0.dll, and verified that works correctly on my other Windows systems.

    Also tried libusb0.dll. Again works correctly elsewhere, but fails on the one Windows 10 system in an identical fashion

    Suggestions would be welcome!

    Thanks!

    `is_ant_device: dev: 0x1009 testpyusb: dev: DEVICE ID 0fcf:1009 on Bus 003 Address 017 ================= bLength : 0x12 (18 bytes) bDescriptorType : 0x1 Device bcdUSB : 0x200 USB 2.0 bDeviceClass : 0x0 Specified at interface bDeviceSubClass : 0x0 bDeviceProtocol : 0x0 bMaxPacketSize0 : 0x20 (32 bytes) idVendor : 0x0fcf idProduct : 0x1009 bcdDevice : 0x100 Device 1.0 iManufacturer : 0x1 Error Accessing String iProduct : 0x2 Error Accessing String iSerialNumber : 0x3 Error Accessing String bNumConfigurations : 0x1

    testpyusb: fetching string descriptors testpyusb: dev.manufacturer e: The device has no langid (permission issue, no string descriptors supported or device error) testpyusb: dev.product e: The device has no langid (permission issue, no string descriptors supported or device error) testpyusb: dev.idVendor 0x0fcf testpyusb: dev.idProduct 0x1009 testpyusb: set_configuration testpyusb: set configuration failed e: [Errno 13] Access denied (insufficient permissions)

    '

    GARM.txt testpyusb.py.txt

    opened by stuartlynne 0
  • Add a Gitter chat badge to README.md

    Add a Gitter chat badge to README.md

    rsc-dev/loophole now has a Chat Room on Gitter

    @rsc-dev has just created a chat room. You can visit it here: https://gitter.im/rsc-dev/loophole.

    This pull-request adds this badge to your README.md:

    Gitter

    If my aim is a little off, please let me know.

    Happy chatting.

    PS: Click here if you would prefer not to receive automatic pull-requests from Gitter in future.

    opened by gitter-badger 0
  • Update README.md - add Tested with: A360

    Update README.md - add Tested with: A360

    Polar A360 Activity Tracker works fine - connect, list, dump, get, walk. 'list' issues a "[!] Failed to get extended info.", but that does not seem to be a problem, Manufacturer, Product name, Vendor ID, Product ID and Serial number are shown properly.

    opened by k3ho 0
  • Issue connecting Polar Vantage V

    Issue connecting Polar Vantage V

    Dear @rsc-dev, I get the following error message when I try to connect loophole to my Polar Vantage V:

    .../__init__.py", line 502, in open assert self.ep_out_0 is not None

    I realize the Vantage series was not out when you wrote the code, but would you be so kind as to look into this matter, or perhaps give me some pointers so that I can try myself?

    Many thanks in advance.

    opened by flblanc 0
  • Polar v650

    Polar v650

    Hi!

    I'm trying to use your software with Polar v650. The list command does see the device, but when I try to connect it I get an error

    loophole(no device)>list 0 - Polar V650 (BUEY4HDMAIMVW8OJ)

    loophole(no device)>connect 0 Traceback (most recent call last): File "~/anaconda2/lib/python2.7/site-packages/loophole/main.py", line 300, in main() File "~/anaconda2/lib/python2.7/site-packages/loophole/main.py", line 293, in main cli.cmdloop(__INTRO.format(version)) File "~/anaconda2/lib/python2.7/cmd.py", line 142, in cmdloop stop = self.onecmd(line) File "~/anaconda2/lib/python2.7/cmd.py", line 221, in onecmd return func(arg) File "~/anaconda2/lib/python2.7/site-packages/loophole/main.py", line 116, in do_connect self.device.open() File "~/anaconda2/lib/python2.7/site-packages/loophole/polar/init.py", line 667, in open self.usb.open(self.usb_device) File "~/anaconda2/lib/python2.7/site-packages/loophole/polar/init.py", line 587, in open self.usb.open(usb_device) File "~/anaconda2/lib/python2.7/site-packages/loophole/polar/init.py", line 502, in open assert self.ep_out_0 is not None AssertionError

    Is it possible to solve?

    Thanks!

    opened by ArsenyMironov 2
  • Polar Ignite

    Polar Ignite

    Hi Roscoe, I'm wondering if you're still doing any work on this. I bought a polar ignite model, and unfortunately loophole doesn't seem to want to connect. If you have any thoughts on what I might try, I'd appreciate it very, very much.

    opened by JeffCdev 7
Releases(0.5.2)
Owner
[roscoe]
Coder. Security oriented. Inquisitive.
[roscoe]
Unofficial Python wrapper for official Hacker News API

haxor Unofficial Python wrapper for official Hacker News API. Installation pip install haxor Usage Import and initialization: from hackernews import H

147 Sep 18, 2022
A Dm Bot, also knows as Mass DM bot which can send one message to All of the Users in a Specific Server!

Discord DM Bot discord.py 1.7.2 python 3.9.5 asyncio 3.4.3 Installation Cloud Host Tutorial uploaded in YouTube, watch it by clicking here. Local Host

hpriyam8 7 Mar 24, 2022
Based on falcondai and fenhl's Python snowflake tool, but with documentation and simliarities to Discord.

python-snowflake-2 Based on falcondai and fenhl's Python snowflake tool, but with documentation and simliarities to Discord. Docs make_snowflake This

2 Mar 19, 2022
Discord raid tool!

GANG Multi Tool Menu: -- YOUTUBE TUTORIAL! Features: Most Advanced Multi Tool! Spammer DM Spammer Friend Spammer Reaction Spam WebhookSpammer Typing

1 Feb 13, 2022
Random-backlog-tweet - Pick a page from a sitemap at random and prep a tweet button for it

Random-backlog-tweet - Pick a page from a sitemap at random and prep a tweet button for it

Paul O'Leary McCann 0 Dec 01, 2022
This code is for a bot which will find a Twitter user's most tweeted word and tweet that word, tagging said user

max_tweeted_word This code is for a bot which will find a Twitter user's most tweeted word and tweet that word, tagging said user The program uses twe

Yasho Bapat 1 Nov 29, 2021
An elegant mirai-api-http v2 Python SDK.

Ariadne 一个适用于 mirai-api-http v2 的 Python SDK。 本项目适用于 mirai-api-http 2.0 以上版本。 目前仍处于开发阶段,内部接口可能会有较大的变化。 安装 poetry add graia-ariadne 或 pip install graia

Graia Project 259 Jan 02, 2023
Um simples bot público para todos usarem no discord!

Discord Bot - Código Público Características: Linguagem de Programação: Python Quantidade de comandos: 17 Comandos: Prefixo do bot: O prefixo desse bo

Kevin 3 Dec 31, 2021
A bot that is an updated & modified version of calvinnfernando's WebReg-Bot

WaitList-Bot A bot that is an updated & modified version of calvinnfernando's WebReg-Bot to automate getting into waitlisted classes in UCSD WebReg on

Issac In 1 Dec 01, 2022
Powerful spammer bots for telegram made with python and telethon.

Powerful spammer bots for telegram made with python and telethon. We can deploy upto 70 bots at a time.

32 Dec 15, 2022
a simple floating window for watch cryptocurrency price

floating-monitor with cryptocurrency 浮動視窗虛擬貨幣價格監控 a floating monitor window to show price of cryptocurrency. use binance api to get price 半透明的浮動視窗讓你方便

Lin_Yi_Shen 1 Oct 22, 2021
An unofficial API for lyricsfreak.com using django and django rest framework.

An unofficial API for lyricsfreak.com using django and django rest framework.

Hesam Norin 1 Feb 09, 2022
Cryptocurrency Prices Telegram Bot For Python

Cryptocurrency Prices Telegram Bot How to Run Set your telegram bot token as environment variable TELEGRAM_BOT_TOKEN: export TELEGRAM_BOT_TOKEN=your_

Sina Nazem 3 Oct 31, 2022
🐙 Share your Github stats for 2020 on Twitter

Year on Github 🐙 Share your Github stats for 2020 on Twitter. This project contains a small web app that let's you share stats about your Github acti

Johannes Rieke 129 Dec 25, 2022
A simple telegram bot that resolves video urls using yt-dlp

URL to Video Telegram Bot A simple telegram bot that resolves video urls using yt-dlp Copyright (C) 2021 Vítor Vasconcellos This program is free softw

Vítor 1 Nov 18, 2021
Automatically commits and pushes changes from a specified directory to remote repository

autopush a simple python program that checks a directory for updates and automatically commits any updated files (and optionally pushes them) installa

carreb 1 Jan 16, 2022
Github Workflows üzerinde Çalışan A101 Aktüel Telegam Bot

A101AktuelRobot Github Workflows üzerinde Çalışan A101 Aktüel Telegam Bot @A101AktuelRobot 💸 Bağış Yap ☕️ Kahve Ismarla 🌐 Telif Hakkı ve Lisans Copy

Ömer Faruk Sancak 10 Nov 02, 2022
A simple library for interacting with Amazon S3.

BucketStore is a very simple Amazon S3 client, written in Python. It aims to be much more straight-forward to use than boto3, and specializes only in

Jacobi Petrucciani 219 Oct 03, 2022
A Python client for the Softcite software mention recognizer server

Softcite software mention recognizer client Python client for using the Softcite software mention recognition service. It can be applied to individual

4 Feb 02, 2022
Pdisk Uploader Bot

pdisk-bot pdisk uploader telegram bot How To Use Configs TG_BOT_TOKEN - Get bot token from @BotFather API_ID - From my.telegram.org API_HASH - From my

lokaman chendekar 25 Oct 21, 2022