Amazfit 2 Chip API Reference
class index:
- Core2
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:
address
, the Bluetooth MAC address of the device to connect. It should be in the form aa:bb:cc:dd:ee:ff (case insensitive).name
, [optional] the name of the device. It also could be obtained later from the device itself.key
: [optional] the encription key (AES/ECB) used to pair with the device. If not provided, it will be generated randomly.
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:
timeout
: (default: 5), maximum elapsed time to wait for devices to answer discovery.
find_all
def find_all(cls, timeout=5)
Classmethod to search compatible devices. It will return all the devices found.
Parameters:
timeout
: (default: 5), maximum elapsed time to wait for devices to answer discovery.
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:
cb
: the function or method to be called. The signature should be as follows:def callback([self,] axis)
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:
cb
: the function or method to be called. The signature should be as follows:def callback([self,] steps)
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:
name
: the device name (if provided on constructor, it will be updated)appearance
: a number which identifies the type of this device (like ‘Generic Phone’, ‘Sports Watch’ or ‘Heart rate Sensor’).privacy_flag
: indicates if this device has privacy enabled or disabled.min_connection_int
: Preferred connection parameter, BLE minimum connection interval.max_connection_int
: Preferred connection parameter, BLE maximum connection interval.slave_latency
: Preferred connection parameter, BLE Slave latency.timeout_mult
: Preferred connection parameter, BLE connection supervision timeout multiplier.service_changed_start
: Start of affected GATT attribute handle range.service_changed_end
: End of affected GATT attribute handle range.system_id
: This is a 64-bit structure which consists of a 40-bit manufacturer-defined identifier concatenated with a 24 bit unique Organizationally Unique Identifier.serial_number
: The serial number of this device.hardware_rev
: Hardware revision number.software_rev
: Software revision number.vendor_src
: Bit which identifies the source of the Vendor ID: Bluetooth SIG or USB implementer.vendor_id
: Identifies the product vendor from the namespace in the Vendor ID Sourceproduct_id
: Manufacturer managed identifier for this productproduct_ver
: Manufacturer managed version for this product
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.