HS2S Pro
WorkFlow
Scan and connect Hs2s Pro scale.
Get device info, if don't have any user info, create a user info and take a measure directly.
Get user info, if have this user info, get data stored in hs2s pro. if don't have this user info, create a user info.
Get offline data and take measurement.
Connection to device
1.Listen to device notify
private iHealthDevicesCallback miHealthDevicesCallback = new iHealthDevicesCallback() {
@Override
public void onScanDevice(String mac, String deviceType, int rssi, Map manufactorData) { }
@Override
public void onDeviceConnectionStateChange(String mac, String deviceType, int status, int errorID, Map manufactorData){ }
@Override
public void onScanError(String reason, long latency) { }
@Override
public void onScanFinish() { }
@Override
public void onDeviceNotify(String mac, String deviceType,
String action, String message) { }
}
int callbackId = iHealthDevicesManager.getInstance().registerClientCallback(miHealthDevicesCallback);
iHealthDevicesManager.getInstance().addCallbackFilterForDeviceType(callbackId, iHealthDevicesManager.TYPE_HS2SPRO);
iHealthDevicesManager.getInstance().addCallbackFilterForAddress(callbackId, String... macs)
2.Scan for HS2S Pro devices
iHealthDevicesManager.getInstance().startDiscovery(DiscoveryTypeEnum.HS2SPRO);
// Return
private iHealthDevicesCallback miHealthDevicesCallback = new iHealthDevicesCallback() {
@Override
public void onScanDevice(String mac, String deviceType, int rssi, Map manufactorData) {
Log.i(TAG, "onScanDevice - mac:" + mac + " - deviceType:" + deviceType + " - rssi:" + rssi + " - manufactorData:" + manufactorData);
}
}
3.Connect to HS2S Pro devices
iHealthDevicesManager.getInstance().connectDevice(mac, iHealthDevicesManager.TYPE_HS2SPRO)
Hs2sProControl control = iHealthDevicesManager.getInstance().getHs2sProControl(mDeviceMac);
API reference
Get the device info
Hs2sProControl control = iHealthDevicesManager.getInstance().getHs2sProControl(mDeviceMac);
control.getDeviceInfo();
// Return value
private iHealthDevicesCallback miHealthDevicesCallback = new iHealthDevicesCallback() {
@Override
public void onDeviceNotify(String mac, String deviceType, String action, String message) {
if (Hs2sProfile.ACTION_GET_DEVICE_INFO.equals(action)) {
try {
JSONObject obj = new JSONObject(message);
int userCount = obj.getInt(Hs2sProfile.HS_USER_COUNT)
int unit = obj.getInt(Hs2sProfile.HS_UNIT_CURRENT)
int bettery = obj.getInt(Hs2sProfile.BATTERY_HS)
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
Get the battery info
Hs2sProControl control = iHealthDevicesManager.getInstance().getHs2sProControl(mDeviceMac);
control.getBattery();
// Return value
private iHealthDevicesCallback miHealthDevicesCallback = new iHealthDevicesCallback() {
@Override
public void onDeviceNotify(String mac, String deviceType, String action, String message) {
if (Hs2sProfile.ACTION_BATTERY_HS.equals(action)) {
try {
JSONObject obj = new JSONObject(message);
int battery = obj.getInt(Hs2sProfile.BATTERY_HS)
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
Set the unit of device
Hs2sProControl control = iHealthDevicesManager.getInstance().getHs2sProControl(mDeviceMac);
// unit {@link Hs2sProfile#UNIT_KG} <br> {@link Hs2sProfile#UNIT_LB} <br> {@link Hs2sProfile#UNIT_ST}
control.setUnit(Hs2sProfile.UNIT_KG);
// Return value
private iHealthDevicesCallback miHealthDevicesCallback = new iHealthDevicesCallback() {
@Override
public void onDeviceNotify(String mac, String deviceType, String action, String message) {
if (Hs2sProfile.ACTION_SET_UNIT_SUCCESS.equals(action)) {
}
}
}
Get the info of user in hs2s pro
Hs2sProControl control = iHealthDevicesManager.getInstance().getHs2sProControl(mDeviceMac);
control.getUserInfo();
// Return value
private iHealthDevicesCallback miHealthDevicesCallback = new iHealthDevicesCallback() {
@Override
public void onDeviceNotify(String mac, String deviceType, String action, String message) {
if (Hs2sProfile.ACTION_GET_USER_INFO.equals(action)) {
try {
JSONObject obj = new JSONObject(message);
int userCount = obj.getInt(Hs2sProfile.USER_INFO_COUNT);
JSONArray userArr = obj.gegetJSONArray(Hs2sProfile.USER_INFO_ARRAY);
for (int i = 0; i < userCount; i++) {
JSONObject user = userArr.getJSONObject(i);
String userId = user.getString(Hs2sProfile.USER_INFO_USER_ID);
long time = user.getLong(Hs2sProfile.USER_INFO_CREATE_TIME);
String weigth = user.getString(Hs2sProfile.USER_INFO_WEIGHT);
int gender = user.getInt(Hs2sProfile.USER_INFO_GENDER);
int age = user.getInt(Hs2sProfile.USER_INFO_AGE);
int height = user.getInt(Hs2sProfile.USER_INFO_HEIGHT);
int impedance = user.getInt(Hs2sProfile.USER_INFO_IMPEDANCE);
int bodybuilding = user.getInt(Hs2sProfile.USER_INFO_BODYBUILDING);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
Create or update user info in device
Hs2sProControl control = iHealthDevicesManager.getInstance().getHs2sProControl(mDeviceMac);
/*
* @param id User id (The length of ID must be 32)
* @param weight weight (unit kg range: 20kg-180kg)
* @param gender 0:women 1:man
* @param age age 18-99 (If it is not within this range, it is impossible to measure the constitution correctly.)
* @param height height 90-220 cm (If it is not within this range, it is impossible to measure the constitution correctly.)
* @param impedance 0:No body fat measurement 1:body fat measurement
* @param bodybuilding 0:No Bodybuilding 1:Bodybuilding
*/
control.createOrUpdateUserInfo(String id, float weight, int gender, int age, int height, int impedance, int bodybuilding);
// Return value
private iHealthDevicesCallback miHealthDevicesCallback = new iHealthDevicesCallback() {
@Override
public void onDeviceNotify(String mac, String deviceType, String action, String message) {
if (Hs2sProfile.ACTION_CREATE_OR_UPDATE_USER_INFO.equals(action)) {
try {
JSONObject obj = new JSONObject(message);
int status = obj.getInt(Hs2sProfile.OPERATION_STATUS);
String description = obj.getString(Hs2sProfile.OPERATION_DESCRIBE);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
Delete user info in device
Hs2sProControl control = iHealthDevicesManager.getInstance().getHs2sProControl(mDeviceMac);
control.deleteUserInfo(String id);
// Return value
private iHealthDevicesCallback miHealthDevicesCallback = new iHealthDevicesCallback() {
@Override
public void onDeviceNotify(String mac, String deviceType, String action, String message) {
if (Hs2sProfile.ACTION_DELETE_USER_INFO.equals(action)) {
try {
JSONObject obj = new JSONObject(message);
int status = obj.getInt(Hs2sProfile.OPERATION_STATUS);
String description = obj.getString(Hs2sProfile.OPERATION_DESCRIBE);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
Specify tourist users
Hs2sProControl control = iHealthDevicesManager.getInstance().getHs2sProControl(mDeviceMac);
control.specifyTouristUsers();
// Return value
private iHealthDevicesCallback miHealthDevicesCallback = new iHealthDevicesCallback() {
@Override
public void onDeviceNotify(String mac, String deviceType, String action, String message) {
if (Hs2sProfile.ACTION_SPECIFY_USERS.equals(action)) {
try {
JSONObject obj = new JSONObject(message);
int status = obj.getInt(Hs2sProfile.OPERATION_STATUS);
String description = obj.getString(Hs2sProfile.OPERATION_DESCRIBE);
} catch (JSONException e) {
e.printStackTrace();
}
} else if (Hs2sProfile.ACTION_ONLINE_REAL_TIME_WEIGHT.equals(action)) {
try {
JSONObject obj = new JSONObject(message);
Double weight = obj.getDouble(Hs2sProfile.DATA_WEIGHT);
} catch (JSONException e) {
e.printStackTrace();
}
} else if (Hs2sProfile.ACTION_ONLINE_RESULT.equals(action)) {
try {
JSONObject obj = new JSONObject(message);
String dataId = obj.getInt(Hs2sProfile.DATA_ID);
int status = obj.getInt(Hs2sProfile.OPERATION_STATUS);
Double weight = obj.getDouble(Hs2sProfile.DATA_WEIGHT);
String description = obj.getString(Hs2sProfile.OPERATION_DESCRIBE);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
Specify Online Users
Hs2sProControl control = iHealthDevicesManager.getInstance().getHs2sProControl(mDeviceMac);
/*
* @param id User id (The length of ID must be 32)
* @param weight weight (unit kg range: 20kg-180kg)
* @param gender 0:women 1:man
* @param age age 18-99 (If it is not within this range, it is impossible to measure the constitution correctly.)
* @param height height 90-220 cm (If it is not within this range, it is impossible to measure the constitution correctly.)
* @param impedance 0:No body fat measurement 1:body fat measurement
* @param bodybuilding 0:No Bodybuilding 1:Bodybuilding
*/
control.specifyOnlineUsers(String id,
float weight,
int gender,
int age,
int height,
int impedance,
int bodybuilding)
// Return value
private iHealthDevicesCallback miHealthDevicesCallback = new iHealthDevicesCallback() {
@Override
public void onDeviceNotify(String mac, String deviceType, String action, String message) {
if (Hs2sProfile.ACTION_SPECIFY_USERS.equals(action)) {
try {
JSONObject obj = new JSONObject(message);
int status = obj.getInt(Hs2sProfile.OPERATION_STATUS);
String description = obj.getString(Hs2sProfile.OPERATION_DESCRIBE);
} catch (JSONException e) {
e.printStackTrace();
}
} else if (Hs2sProfile.ACTION_ONLINE_REAL_TIME_WEIGHT.equals(action)) {
try {
JSONObject obj = new JSONObject(message);
Double weight = obj.getDouble(Hs2sProfile.DATA_WEIGHT);
} catch (JSONException e) {
e.printStackTrace();
}
} else if (Hs2sProfile.ACTION_ONLINE_RESULT.equals(action)) {
try {
JSONObject obj = new JSONObject(message);
String dataId = obj.getInt(Hs2sProfile.DATA_ID);
int status = obj.getInt(Hs2sProfile.OPERATION_STATUS);
Double weight = obj.getDouble(Hs2sProfile.DATA_WEIGHT);
String description = obj.getString(Hs2sProfile.OPERATION_DESCRIBE);
} catch (JSONException e) {
e.printStackTrace();
}
} else if (Hs2sProfile.DATA_BODY_FAT_RESULT.equals(action)) {
try {
JSONObject obj = new JSONObject(message);
int status = obj.getInt(Hs2sProfile.OPERATION_STATUS);
String description = obj.getDouble(Hs2sProfile.OPERATION_DESCRIBE);
Double weight = obj.getDouble(Hs2sProfile.DATA_WEIGHT);
String dataId = obj.getString(Hs2sProfile.DATA_ID);
JSONArray impedanceArray = obj.getJSONArray(Hs2sProfile.DATA_IMPEDANCE);
for (int i = 0; i < impedanceArray.length(); i++) {
int impedance = impedanceArray.getInt(Hs2sProfile.DATA_IMPEDANCE);
}
int userCount = obj.getString(Hs2sProfile.DATA_USER_NUM);
int gender = obj.getString(Hs2sProfile.DATA_GENDER);
int age = obj.getString(Hs2sProfile.DATA_AGE);
int height = obj.getString(Hs2sProfile.DATA_HEIGHT);
long measureTs = obj.getLong(Hs2sProfile.DATA_MEASURE_TIME);
int correctTime = obj.getInt(Hs2sProfile.DATA_RIGHT_TIME);
int bodyBuilding = obj.getInt(Hs2sProfile.DATA_BODYBUILDING);
int type = obj.getInt(Hs2sProfile.DATA_INSTRUCTION_TYPE);
int impedanceErrorType = obj.getInt(Hs2sProfile.DATA_IMPEDANCE_ERRORS);
if(type == 1){
int bodyFit = obj.getString(Hs2sProfile.DATA_BODY_FIT_PERCENTAGE);
int muscleMass = obj.getString(Hs2sProfile.DATA_MUSCLE_MASS);
int boneSaltContent = obj.getString(Hs2sProfile.DATA_BONE_SALT_CONTENT);
int bodyWater = obj.getString(Hs2sProfile.DATA_BODY_WATER_RATE);
int protein = obj.getString(Hs2sProfile.DATA_PROTEIN_RATE);
int footEncryptionImpedance = obj.getString(Hs2sProfile.DATA_IMPEDANCE_ENCRYPT);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
Get off line data count
Hs2sProControl control = iHealthDevicesManager.getInstance().getHs2sProControl(mDeviceMac);
control.getOfflineDataCount(String userId);
// Return value
private iHealthDevicesCallback miHealthDevicesCallback = new iHealthDevicesCallback() {
@Override
public void onDeviceNotify(String mac, String deviceType, String action, String message) {
if (Hs2sProfile.ACTION_HISTORY_DATA_NUM.equals(action)) {
try {
JSONObject obj = new JSONObject(message);
int count = countObj.getInt(Hs2sProfile.HISTORY_DATA_COUNT);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
Get offline data
Hs2sProControl control = iHealthDevicesManager.getInstance().getHs2sProControl(mDeviceMac);
control.getOfflineData(String id)
// Return value
private iHealthDevicesCallback miHealthDevicesCallback = new iHealthDevicesCallback() {
@Override
public void onDeviceNotify(String mac, String deviceType, String action, String message) {
if (Hs2sProfile.ACTION_HISTORY_DATA.equals(action)) {
try {
JSONArray historyArr = new JSONArray(message);
for (int i = 0; i < historyArr.length(); i++) {
JSONObject obj = historyArr.getJSONObject(i);
Double weight = obj.getDouble(Hs2sProfile.DATA_WEIGHT);
String dataId = obj.getString(Hs2sProfile.DATA_ID);
JSONArray impedanceArray = obj.getJSONArray(Hs2sProfile.DATA_IMPEDANCE);
for (int i = 0; i < impedanceArray.length(); i++) {
int impedance = impedanceArray.getInt(Hs2sProfile.DATA_IMPEDANCE);
}
int userCount = obj.getString(Hs2sProfile.DATA_USER_NUM);
int gender = obj.getString(Hs2sProfile.DATA_GENDER);
int age = obj.getString(Hs2sProfile.DATA_AGE);
int height = obj.getString(Hs2sProfile.DATA_HEIGHT);
long measureTs = obj.getLong(Hs2sProfile.DATA_MEASURE_TIME);
int correctTime = obj.getInt(Hs2sProfile.DATA_RIGHT_TIME);
int bodyBuilding = obj.getInt(Hs2sProfile.DATA_BODYBUILDING);
int type = obj.getInt(Hs2sProfile.DATA_INSTRUCTION_TYPE);
int impedanceErrorType = obj.getInt(Hs2sProfile.DATA_IMPEDANCE_ERRORS);
if(type == 1){
int bodyFit = obj.getString(Hs2sProfile.DATA_BODY_FIT_PERCENTAGE);
int muscleMass = obj.getString(Hs2sProfile.DATA_MUSCLE_MASS);
int boneSaltContent = obj.getString(Hs2sProfile.DATA_BONE_SALT_CONTENT);
int bodyWater = obj.getString(Hs2sProfile.DATA_BODY_WATER_RATE);
int protein = obj.getString(Hs2sProfile.DATA_PROTEIN_RATE);
int footEncryptionImpedance = obj.getString(Hs2sProfile.DATA_IMPEDANCE_ENCRYPT);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
Delete offline data
Hs2sProControl control = iHealthDevicesManager.getInstance().getHs2sProControl(mDeviceMac);
control.deleteOfflineData(String id);
// Return value
private iHealthDevicesCallback miHealthDevicesCallback = new iHealthDevicesCallback() {
@Override
public void onDeviceNotify(String mac, String deviceType, String action, String message) {
if (Hs2sProfile.ACTION_DELETE_HISTORY_DATA.equals(action)) {
try {
JSONObject obj = new JSONObject(message);
int status = obj.getInt(Hs2sProfile.OPERATION_STATUS)
String description = obj.getString(Hs2sProfile.OPERATION_DESCRIBE)
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
Start heart rate measurement mode
If you call this function, Hs2s pro will switch to heart rate measurement mode and the weight measurement is not availabe. If you want to start the weight measurement, need to call the stopHeartRateMode function or disconnect the Hs2s Pro BLE's connection with Phone.
Hs2sProControl control = iHealthDevicesManager.getInstance().getHs2sProControl(mDeviceMac);
control.startHeartRateMode();
// Return value
private iHealthDevicesCallback miHealthDevicesCallback = new iHealthDevicesCallback() {
@Override
public void onDeviceNotify(String mac, String deviceType, String action, String message) {
if (Hs2sProfile.ACTION_START_HEARTRATE_MEASURE.equals(action)) {
Log.i("", "Heart rate measurement is started");
try {
JSONObject obj = new JSONObject(message);
int status = obj.getInt(Hs2sProfile.OPERATION_STATUS);
String description = obj.getString(Hs2sProfile.OPERATION_DESCRIBE);
} catch (JSONException e) {
e.printStackTrace();
}
} else if (Hs2sProfile.ACTION_HEARTRATE_RESULT.equals(action)) {
try {
JSONObject obj = new JSONObject(message);
int status = obj.getInt(Hs2sProfile.OPERATION_STATUS);
int heartrate = obj.getInt(Hs2sProfile.DATA_HEARTRATE);
Log.i("", "The heartrate is " + heartrate);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
Stop heart rate measurement mode
If you call this function, Hs2s Pro will stop heart rate measurement mode and back to the weight measurement mode.
Hs2sProControl control = iHealthDevicesManager.getInstance().getHs2sProControl(mDeviceMac);
control.stopHeartRateMode();
// Return value
private iHealthDevicesCallback miHealthDevicesCallback = new iHealthDevicesCallback() {
@Override
public void onDeviceNotify(String mac, String deviceType, String action, String message) {
if (Hs2sProfile.ACTION_STOP_HEARTRATE_MEASURE.equals(action)) {
Log.i("", "Heart rate measurement is stop");
try {
JSONObject obj = new JSONObject(message);
int status = obj.getInt(Hs2sProfile.OPERATION_STATUS);
String description = obj.getString(Hs2sProfile.OPERATION_DESCRIBE);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}