Overview
DreisamLib is an SDK designed for device connection and data interaction. It provides functionalities such as device connection management, data synchronization, and historical data retrieval, making it suitable for the development of applications requiring communication with specific devices.Initialization-related Methods
Pre-initialization
- Function: Pre-initializes the SDK, which must be called in the main thread of the
Application.onCreatemethod. - Features:
- Minimal time consumption, without affecting the App’s first cold start experience.
- No collection of device information.
- Parameter:
context- Application context (Application instance).
Formal Initialization
- Function: Completes the formal initialization of the SDK.
- Call Timing: Can be invoked immediately after pre-initialization or delayed in a background thread, but it is mandatory to call this method.
- Parameters:
appId- AppId generated by the open platform.builder- Configuration builder (used to configure SDK parameters).
De-initialization
- Function: De-initializes the SDK and releases related resources.
Device Connection Management
Check Connection Preconditions
You can check the prerequisites for connection before establishing it, and developers can also perform permission checks independently by referring to the Demo.
- Function: Checks connection preconditions such as system authorization and network authentication.
- Parameter:
listener- Pre-check listener for receiving check results.
Connect to a Specified Device
Connect to the specified device by passing in the device information after scanning the device’s QR code. Developers need to handle the binding and connection logic on their own.
- If it is the first connection, developers can initiate a binding request to the server in the connection success callback.
- If the device is already bound, simply connect to it based on the device information bound to the server.
- Function: Connects to the device with the specified name.
- Parameter:
deviceName- Name of the device to be connected.
Set Connection Status Listener
- Function: Sets the device connection status listener.
- Parameter:
onConnectListener- Instance of the connection status listener.
Note: The SDK has a built-in automatic reconnection mechanism. Developers do not need to handle disconnection and reconnection, but only implement business logic such as UI updates. If the device disconnects, the SDK will attempt to reconnect after 30 seconds. If reconnection fails:
- If the App is running in the foreground, it will retry connecting after a delay until the connection is successfully established.
- If the App is running in the background, frequent background operations may cause the application to be suspended due to Android system process management. In this case, the SDK will wait for the heartbeat packet to trigger reconnection again.
Check Device Connection Status
- Function: Checks whether the device is connected.
- Return Value:
trueindicates connected;falseindicates disconnected.
Disconnect Device
- Function: Disconnects the currently connected device.
Heartbeat Detection
Start Heartbeat Detection
This is used to detect the device connection status and executes once every 5 minutes. If the device is disconnected, the SDK will retry connecting to it. Developers can also implement this logic on their own.
- Function: Starts device heartbeat detection.
Stop Heartbeat Detection
- Function: Stops device heartbeat detection.
Data-related Methods
Set Data Synchronization Listener
- Function: Sets the data synchronization status listener.
- Parameter:
callBack- Instance of the synchronization status listener.
Note:
- Under normal circumstances: The callback returns new data that has not been synchronized between the SDK and the device.
- When switching to a new mobile phone or logging out: All data will be returned in the callback. Developers can filter the required data according to the last message stored on their own server.
Retrieve Historical Data
- Function: Retrieves historical data within the specified time range.
- Parameters:
startTime- Start timestamp (in seconds).endTime- End timestamp (in seconds).callBack- Callback interface for historical data.
Set Real-time Data Callback
Data reported by the device will trigger a callback once every 3 minutes under normal circumstances.
- Function: Sets the real-time data analysis callback listener.
- Parameter:
listener- Instance of the real-time data analysis callback.
Log-related Methods
Set Connection Log Listener
- Function: Sets the connection log listener.
- Parameter:
onConnectLogListener- Instance of the log listener.
Listener Interfaces
OnPreCheckListener
Connection precondition check listenerOnAnalzeDatatListener
Real-time data analysis listenerOnConnectListener
Connection status listenerOnConnectLogListener
Connection log listenerOnHistoryDatasCallBack
Historical data callback interfaceOnSyncDatasCallBack
Data synchronization listenerEnumeration Types
DreisamGlucoseModel
Connection status enumerationNote: Difference betweenDEVICE_CONNECTINGandSHOW_CONNECTING:
DEVICE_CONNECTINGwill trigger a callback as soon as the device disconnects.SHOW_CONNECTINGis a connection-in-progress state displayed for user attention. A callback will only be triggered if the latest data is not up-to-date and the device is still disconnected.
Data Models
DreisamGlucoseModel
Blood glucose data modelRecommended Usage Flow
- Call
preInit()inApplication.onCreate()for pre-initialization. - Call
initSDK()at an appropriate time to complete formal initialization. - Set necessary listeners (connection status, data synchronization, etc.).
- Call
checkPreConditions()to verify preconditions. - After preconditions are satisfied, call
connectDevice()to connect to the device. - Once the device is connected successfully, perform data synchronization, retrieve historical data, or receive real-time data.
- When the SDK is no longer needed, call
disconnect()to terminate the connection, and callunInit()if necessary to release resources.
