API References


Amazfit 2 Chip API Reference

class index:

amazfit API Documentation

Class Core2

This class provides access to the Huami Smart Chip (version 2), which could be found on Amazfit or Xiaomi sneakers. Use this class to discover a new device, connect and pair to it, retrieve device information, orientation, steps, etc.

For some of the properties, it also supports a push mechanism which allows to receive notifications when the property changes.

battery

[read-only property] Holds the current battery level, in percentage, of the device. It will retrieve it (synchronously) when used (no caching).

NOTE: due to a bug in the device firmware, this characteristic may not return any payload. In that case, None will be returned (an error will also be logged).

current_time

[read-only property] It returns the current date and time configuration of the device, in string format. It will retrieve it (synchronously) when used (no caching).

orientation

[read-only property] Returns the IMU orientation readings of the device. It is a tuple with two fields, one for each axis.

FIXME: semantic of these fields is to be determined!

steps

[read-only property] Provides the current step count of the device. It will retrieve it (synchronously) when used (no caching).

__init__

def __init__(self, address, name='', key=None)

Smart Chip (a.k.a Dyanmic Core 2) constructor. This is the basic object you need to instantiate. It could be created directly (providing the device address) or performing a discovery with the .find() method (explained later).

Parameters:

connect

def connect(self)

Try to connect to the device, using the provided address. Returns when then connection is established. If the device is not present (before the timeout expires), it will raise an exception. This method must be called before any other operation.

find

def find(cls, timeout=5)

Classmethod to search compatible devices. It will return the first found.

Parameters:

find_all

def find_all(cls, timeout=5)

Classmethod to search compatible devices. It will return all the devices found.

Parameters:

fire_orientation_read

def fire_orientation_read(self)

Forces a new read on the orientation characteristic. You should call on_orientation() before, in order to setup a notification callback.

on_orientation

def on_orientation(self, cb)

Enables notifications on orientation handle, and configures a callback to be called when a new notification arrives.

Parameters:

NOTE: the orientation characteristic will not issue new notifications when the value has changed. To receive them, you should force a new event with the fire_orientation_read() method.

on_steps

def on_steps(self, cb)

Enables notifications on step readings, and configures a callback to be called when a new notification arrives.

Parameters:

pair

def pair(self)

Bond with this device. It will exchange the private key used to cipher messages with the chip (although it is not necessary for every operation). This procedure also will reset the step counter in the device.

read_info

def read_info(self)

Retrieve all the static information provided by the device. After calling this method, you can access the following attributes:

wait_until_break

def wait_until_break(self)

Blocks the calling thread execution until it receives a KeyboardInterrupt (Ctrl+C) Use it (or use instead an event loop) to keep the application running while you wait for incoming events.