Overall Architecture
The complete Mini Program includes Device App, Settings App and Side Service.
- Device App
- The Device App runs on a watch device
- The operating system of the watch device is Zepp OS
- The Device App can call the widget API to draw UI and call a series of sensors to obtain data
- Settings App(optional)
- Settings App runs in the Zepp App on mobile devices
- Settings App draws UI by calling render function
- Side Service(optional)
- Side Service runs in the Zepp App on mobile devices
- Side Service can communicate with external servers through Fetch API
Communication Relationships
BLE
BLE is used for communication between Device App and Side Service. The underlying BLE API is not user-friendly, so we provide the ZML tool library, which has a more complete implementation of the communication process and exposes the easy-to-use API.
- Use
this.request
method to send messages in Device App andonRequest
to receive messages in Side Service - Use
this.call
method to send messages in Side Service andonCall
to receive messages in Device App
For more information about ZML, please refer to ZML - Github
Settings Storage
Communication between Settings App and Side Service relies on Settings Storage API.
To facilitate the display of data relationships, two Settings Storage are drawn in the figure, which are actually the same thing.
Settings Storage use setItem
to set the data and use getItem
to get the value.
- Settings App -> Side Service (the red line)
- Use
addListener
API in Side Service to register callback function to listen to data changes in Settings Storage - Use
setItem
to change data in the Settings App and trigger the registered callback function - When use
setItem
to set data in the Side Service, automatically call Settings Appbuild
lifecycle, redraw UI.
- Use
- Side Service -> Settings App (the blue line)
- Use setItem to change data in the Side Service
- Settings Storage detects that data has changed, automatically triggers the re-rendering of the Settings App, and executes the
build
lifecycle
Side Service communicates with third-party Service using Fetch API
Usage reference Fetch API
More Info
Direct communication between "Device App" and "Settings App" is not possible and requires a "Side Service".
- For more information on communication relationships, please refer to How To Extract Health Data from Amazfit Smartwatches to a Web Server
- For a complete example of communication between Device App, Side Service, and Settings App, please refer to the example Post-Health-Data