# MinewSensorKit document
This SDK only supports the Bluetooth sensor devices from Minew. The SDK helps developers to handle everything between the phone and the sensor, including: scanning the device, broadcasting data, connecting to the device, writing data to the device, receiving data from the S4 device.
# Preliminary work
Overall framework: S4SensorBleManager
is the device management class, which is always a single instance when the app is running. S4SensorEntity
is the device instance class, this suite generates an instance for each device, which is used after scanning and connecting, and contains device broadcast data inside, which will be updated during scanning as the device keeps broadcasting.
S4SensorBleManager
:Device management class that scans the surrounding S4 devices and can connect them, verify them, etc.;
S4SensorEntity
:Example of an S4 sensor device acquired during scanning, inherited from BaseBleDeviceEntity
# Import to project
Development Environment
The minimum sdk support is Android 5.0, corresponding to API Level 21. set
minSdkVersion
to 21 or above inbuild.gradle
of the module.android { defaultConfig { applicationId "com.xxx.xxx" minSdkVersion 21 } }
1
2
3
4
5
6
7Add jar to the module's libs folder and add the following statement to the
build.gradle
of themodule
(add the dependency directly):implementation files('libs/base_ble_library.jar') implementation files('libs/minew_s4.jar') api 'org.lucee:bcprov-jdk15on:1.52.0'
1
2
3Or right-click the jar file and select
Add as Library
to add it to the current module.Add the configuration to the.so library file in the App directory build.gradle
android { defaultConfig { ndk { abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64' } } sourceSets { main { jniLibs.srcDirs = ['libs'] } } }
1
2
3
4
5
6
7
8
9
10
11
12
13
14The following permissions are required in
AndroidManifest.xml
, and iftargetSdkVersion
is greater than 23, you need to do permission management to get the permissions.<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" tools:node="replace" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" tools:node="replace" /> <uses-permission android:name="android.permission.BLUETOOTH_SCAN" /> <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" /> <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" /> <uses-permission android:name="android.permission.READ_MEDIA_AUDIO" /> <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" /> <!-- Required to maintain app compatibility. --> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Use
The sdk is divided into three phases: scanning, connecting, and reading and writing.
# Scanning section
# Start scannin
For Android 6.0 and above systems, when performing BLE scanning, you need to apply for Bluetooth permission and turn on the positioning switch before proceeding.
To enable Bluetooth scanning, you need to turn on Bluetooth first. If you scan without turning on Bluetooth, the APP will crash. You can use BLETool.checkBluetooth(this) to determine whether Bluetooth is turned on. If it is not turned on, you can turn on Bluetooth first.
S4SensorBleManager mBleManager = S4SensorBleManager.getInstance();
switch (BLETool.checkBluetooth(this)){
case BLE_NOT_SUPPORT:
Toast.makeText(this, "Not Support BLE", Toast.LENGTH_SHORT).show();
break;
case BLUETOOTH_ON:
mBleManager.startScan(this, 5 * 60 * 1000, new OnScanDevicesResultListener<S4SensorEntity>() {
@Override
public void onScanResult(List<S4SensorEntity> list) {
}
@Override
public void onStopScan(List<S4SensorEntity> list) {
}
});
break;
case BLUETOOTH_OFF:
Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, 4);
break;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
The SDK does not process the Bluetooth scanning duration internally, but scanning is a power-consuming operation. The SDK stops scanning after 5 minutes by default. If you still need to continue scanning, you can provide a timer or refresh operation to continue calling the scanning method to continue scanning the device.。
# Retrieve data
During the scan, the APP is able to get a part of the current data of the device through the sdk. The data of the device is obtained through S4SensorEntity
as shown below, which is stored in the broadcast frame object.
The sdk provides BaseBleDeviceEntity
as the base class of S4SensorEntity
to store the public data of the sensor device as shown in the following table.
Name | Type | Description |
---|---|---|
macAddress | String | device mac |
name | String | Device name |
rssi | int | Signal strength |
The BaseBleDeviceEntity
also keeps a Map, which is used internally to store the device broadcast data frames it acquires during a scan, and can be retrieved as follows
S4SensorEntity module;
DeviceStaticInfoFrame deviceInforFrame = (DeviceStaticInfoFrame)module.getMinewFrame(FrameType.DEVICE_INFORMATION_FRAME);
CombinationFrame combinationFrame = (CombinationFrame) module.getMinewFrame(FrameType.INDUSTRIAL_HT_FRAME);
if (deviceInforFrame != null) {
//Device mac address
String macAddress = deviceInforFrame.getMacAddress();
//Percentage of power
int battery = deviceInforFrame.getBattery();
//firmware version
String firmwareVersion = deviceInforFrame.getFirmwareVersion();
}
if (combinationFrame != null) {
//status
float doorSensorAlarmStatus = combinationFrame.getDoorSensorAlarmStatus();
float tamperProofAlarmStatus = combinationFrame.getTamperProofAlarmStatus();
float triggerAlarmStatus = combinationFrame.getTriggerAlarmStatus();
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
There are 2 types of adv frames for S4 device。
Device static information frame
DeviceStaticInfoFrame
Name Type Description frameVersion int device type firmwareVersion String Firmware Version batteryLevel int Battery Level Percentage macAddress String firmware mac peripheralSupportInfo PeripheralSupportInfo Description of peripheral support
Combination frame
CombinationFrame
Name Type TypeTypeDescription doorSensorAlarmStatus int Door status sensor alarm status, 1 on, 0 off tamperProofAlarmStatus int Alarm status, 1 triggered, 0 normal triggerAlarmStatus int Trigger alarm state, 1 on, 0 off openCount int The maximum number of times the door status sensor opens the door is 255. If the number exceeds 255, the value is re-counted from zero closeCount int The maximum number of times the door status sensor closes is 255. If the number exceeds 255, the value is counted again from zero tamperProofCount int The maximum number of times the anti-disassembly switch is enabled is 255. If the number exceeds 255, the number starts from zero again
# Connections
It is usually necessary to stop scanning before connecting. sdk provides methods to connect and disconnect.。
S4SensorBleManager mBleManager = S4SensorBleManager.getInstance();
//Stop scanning
mBleManager.stopScan(context);
//Setting the device secret key
String key="3141592653589793";
mBleManager.setSecretKey(key);
//Connection, module for the device to be connected
S4SensorEntity module;
mBleManager.connect(context,module);
2
3
4
5
6
7
8
9
10
Note: Before connecting the device, please confirm whether the device is scanned, if no device broadcast is scanned and the connection method is called, the connection will fail.
# Disconnect
S4SensorBleManager mBleManager = S4SensorBleManager.getInstance();
S4SensorEntity module;
//Disconnect. macAddress is the device mac
mBleManager.disConnect(macAddress);
2
3
4
After calling connect()
, there will be a status listener in sdk for the connection process.
//Setting the listener
mBleManager.setOnConnStateListener(new OnConnStateListener() {
/*
* Status callbacks during connection
*
* @param macAddress device mac
* @param connectionState status
*/
@Override
public void onUpdateConnState(String address, BleConnectionState state) {
switch (state) {
case Disconnect:
//Connection failure or device disconnection will be called back, active disconnection will not call back the .
break;
case Connecting:
//This state will be called back after calling connect()
break;
case Connected:
//The initial connection was successful, as a transition phase, but not really successful at this point.
break;
case AuthenticateFail:
//Key verification failed.
break;
case AuthenticateSuccess:
//Key verification successful.
break;
case ConnectComplete:
//Connection is complete, the device is now ready for read and write operations.
break;
default:
break;
}
}
});
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
During the connection process, sdk will return multiple connection states to the app, which the app needs to handle properly.
- BleConnectionState.Connecting,BleConnectionState.Connected: Connecting the device in, do not do time-consuming operations in this state, because at this time in the connected device discovery service, and send authentication data, etc.
- BleConnectionState.ConnectComplete: The sensor device is successfully connected at this point, and can perform read and write operations, such as configuring broadcast parameters, sensor configuration, reading historical data, etc.
- BleConnectionState.AuthenticateFail:The secret key is verified during the authentication process. If the entered secret key is incorrect, this state will be called back and the device will actively disconnect.
- BleConnectionState.AuthenticateSuccess:The secret key is verified during the authentication process. If the entered secret key is correct, this status will be called back.
- BleConnectionState.Disconnect: The callback will be made if the connection fails or the device is disconnected.
# Reading and writing
The read and write APIs are as follows:
/**
*Set device key
* @param macAddress device mac
* @param secretKey secret key key
* @param listener
*/
void setDeviceSecretKey(String macAddress, String secretKey, OnModifyConfigurationListener listener);
/**
* Query device running status
* @param macAddress device mac
* @param listener listener
*/
void queryDeviceOperationStatus(String macAddress,OnQueryResultListener<DeviceOperationStatusConfig> listener);
/**
* Query device version information
* @param macAddress device mac
* @param listener listener
*/
void queryDeviceFirmwareInfo(String macAddress, OnQueryResultListener<FirmwareVersionModel> listener);
/**
* Read historical data
*
* @param macAddress device mac
* @param rules Historical data acquisition rules, 0 means to obtain all data, 1 means to obtain data of a certain time *period, when rules==0, startTime and endTime do not need to be passed, and 0 is passed by default
* @param startTime starting timestamp unit: seconds
* @param endTime end timestamp unit: seconds,Cannot be greater than systemTime
* @param systemTime real-time timestamp unit: seconds
* @param listener listener
*/
void queryHistoryData(String macAddress,int rules,long startTime,long endTime,long systemTime, OnQueryResultListener<HistoryDoorMagnetData> listener);
/**
* Query adv frame broadcast parameters
* @param macAddress device mac
* @param slot Query the broadcast channel value, default value 0.slot = 0 CombinationFrame 、slot = 1
* CombinationFrame
* @param listener listener
*/
void queryAdvParametersConfiguration(String macAddress,int slot, OnQueryResultListener<AdvParametersConfig> listener);
/**
* Set broadcast frame broadcast parameters
*
* @param macAddress device mac
* @param frameType FrameType enumeration gets getFrameTypeVersion()
* @param slotNumber sets the channel value corresponding to the broadcast,
* @param advertisingInterval broadcast interval in milliseconds, the broadcast interval is adjustable from 100ms ~ 60000mss, and step is 100ms;
* @param txPower -40 -20 -16 -12 -8 -4 0 4dBm
* @param listener listener
*/
void setAdvParametersConfiguration(String macAddress,String frameType, int slotNumber,int advertisingInterval, int txPower, OnModifyConfigurationListener listener);
/**
* query trigger config
* @param macAddress device mac
* @param listener listener
*/
void queryTriggerConfiguration(String macAddress, OnQueryResultListener<List<TriggerConfigBean>> listener);
/**
* setting trigger config
* @param macAddress device mac
* @param triggerConfigList trigger config data
* @param listener listener
*/
void setTriggerConfiguration(String macAddress, List<TriggerConfigBean> triggerConfigList, OnModifyConfigurationListener listener);
/**
* Query switch options
* @param macAddress device mac
* @param listener listener
*/
void queryOptionSwitch(String macAddress, OnQueryResultListener<List<OptionSwitchConfig>> listener);
/**
* Set the switch function option
* @param macAddress device mac
* @param optionValue The switch value is 0 or 1
* @param listener listener
*/
void setLightOptionSwitch(String macAddress, int optionValue, OnModifyConfigurationListener listener);
/**
* Set data storage options
* @param macAddress device mac
* @param optionValue The switch value is 0 or 1
* @param listener listener
*/
void setDataStoreOptionSwitch(String macAddress, int optionValue, OnModifyConfigurationListener listener);
/**
* Synchronize the device Linux time
* @param macAddress device mac
* @param timestamp Current system time, unit: second
* @param listener listener
*/
void setSyncTime(String macAddress,long timestamp,OnModifyConfigurationListener listener);
/**
* query the working period
* @param macAddress device mac
* @param listener listener
*/
void queryWorkPeriodsConfiguration(String macAddress, OnQueryResultListener<WorkPeriodsListConfig> listener);
/**
* Set the working period
* @param macAddress device mac
* @param workPeriodConfigList Time period data of work
* @param listener listener
*/
void setWorkPeriodsConfiguration(String macAddress, List<WorkPeriodConfig> workPeriodConfigList, OnModifyConfigurationListener listener);
/**
* Verify the OTA upgrade file
* @param zipFilePath ota file path
* @return true = s4 ota file,
*/
boolean verifyOtaFile(String zipFilePath);
/**
* Firmware upgrade
*
* @param macAddress device mac
* @param isLinkUpgrade true url upgrade, false firmware package upgrade. The default value is false, and the url upgrade * method is not supported.
* @param dfuTarget isLinkUpgrade =false, dfuTarget = 0,
* @param upgradeData upgrade package data
* @param listener listener
*/
public void firmwareUpgrade(String macAddress,boolean isLinkUpgrade,int dfuTarget,byte[] upgradeData, OnFirmwareUpgradeListener listener);
/**String macAddress
* Restore factory settings
*
* @param macAddress device mac
* @param listener listener
*/
public void reset(String macAddress, OnModifyConfigurationListener listener);
/**
* Shutdown
* @param macAddress device mac
* @param listener listener
*/
public void powerOff(String macAddress, OnModifyConfigurationListener listener);
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# Some methods are supplemented:
Set the device key. You must call this method to set the key before connecting the device。
S4SensorBleManager mBleManager = S4SensorBleManager.getInstance(); String secretKey = "3141592653589793" mBleManager.setSecretKey(mAddress,secretKey);
1
2
3
4Synchronizing device time。
S4SensorBleManager mBleManager = S4SensorBleManager.getInstance(); mBleManager.setSyncTime(mMac, System.currentTimeMillis() / 1000, new OnModifyConfigurationListener() { @Override public void onModifyResult(boolean b) { Toast.makeText(context,"SyncTime Result:"+b,Toast.LENGTH_LONG).show(); } });
1
2
3
4
5
6
7Example Query the running status of the device。
S4SensorBleManager mBleManager = S4SensorBleManager.getInstance(); mBleManager.queryDeviceOperationStatus(macAddress,new OnQueryResultListener<DeviceOperationStatusConfig>() { @Override public void OnQueryResult(boolean b, DeviceOperationStatusConfig deviceOperationStatus) { //b :true = query succeeds. false = query fails Toast.makeText(context,"Query Result:"+b,Toast.LENGTH_LONG).show(); if(b){ int battery = deviceOperationStatus.getBattery(); long sinceBootInSeconds = deviceOperationStatus.getSinceBootInSeconds(); } } });
1
2
3
4
5
6
7
8
9
10
11
12Query device version information.。
S4SensorBleManager mBleManager = S4SensorBleManager.getInstance(); mBleManager.queryDeviceFirmwareInfo(macAddress,new OnQueryResultListener<FirmwareVersionModel>() { @Override public void OnQueryResult(boolean b, FirmwareVersionModel firmwareVersionModel) { //b :true = query succeeds. false = query fails firmwareVersionModel=null。 Toast.makeText(context,"Query Result:"+b,Toast.LENGTH_LONG).show(); if(b){ List<VersionInfo> versionInfoList = firmwareVersionModel.getVersionInfoList(); String firmwareName = versionInfoList.get(0).getFirmwareName(); int firmwareType = versionInfoList.get(0).getFirmwareType(); String firmwareVersion = versionInfoList.get(0).getFirmwareVersion(); } } });
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15Query advframe broadcast parameters and configure adv parameters.
/** * Set broadcast frame broadcast parameters * * @param macAddress device mac * @param frameType FrameType enumeration gets getFrameTypeVersion() * @param slotNumber sets the channel value corresponding to the broadcast, * @param advertisingInterval broadcast interval in milliseconds, the broadcast interval is adjustable from 100ms ~ 60000mss, and step is 100ms; * @param txPower -40 -20 -16 -12 -8 -4 0 4dBm * @param listener listener */ S4SensorBleManager mBleManager = S4SensorBleManager.getInstance(); S4SensorEntity module String macAddress = module.getMacAddress(); //slot = 0 DeviceStaticInfoFrame 、slot = 1 CombinationFrame // query DeviceStaticInfoFrame AdvParametersConfig deviceInfoAdvParametersConfig = null; mBleManager.queryAdvParametersConfiguration(macAddress, 0, new OnQueryResultListener<AdvParametersConfig>() { @Override public void OnQueryResult(boolean b, AdvParametersConfig advParametersConfig) { if(b){ deviceInfoAdvParametersConfig = advParametersConfig; } Toast.makeText(context,"Query Adv Result:"+b,Toast.LENGTH_LONG).show(); } }); //set DeviceStaticInfoFrame mBleManager.setAdvParametersConfiguration(macAddress, deviceInfoAdvParametersConfig.getFrameType(), deviceInfoAdvParametersConfig.getSlotNumber(), deviceInfoAdvParametersConfig.getAdvertisingInterval(), deviceInfoAdvParametersConfig.getTxPower(),new OnModifyConfigurationListener() { @Override public void onModifyResult(boolean b) { Toast.makeText(context,"Set Adv Parameters Result:"+b,Toast.LENGTH_LONG).show(); } }); //query CombinationFrame AdvParametersConfig combinationAdvParametersConfig= null mBleManager.queryAdvParametersConfiguration(macAddress, 1, new OnQueryResultListener<AdvParametersConfig>() { @Override public void OnQueryResult(boolean b, AdvParametersConfig advParametersConfiguration) { if(b){ combinationAdvParametersConfiguration = advParametersConfiguration; } Toast.makeText(context,"Query Adv Result:"+b,Toast.LENGTH_LONG).show(); } }); //Only CombinationFrame,,alwaysAdvertising=0 Regular Mode,alwaysAdvertising=1Energy-saving Mode //set CombinationFrame mBleManager.setAdvParametersConfiguration(macAddress, combinationAdvParametersConfig.getFrameType(), combinationAdvParametersConfig.getSlotNumber(), combinationAdvParametersConfig.getAdvertisingInterval(), combinationAdvParametersConfig.getTxPower(),new OnModifyConfigurationListener() { @Override public void onModifyResult(boolean b) { Toast.makeText(context,"Set Adv Parameters Result:"+b,Toast.LENGTH_LONG).show(); } });
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62Querying trigger parameters and setting trigger parameters.
S4SensorBleManager mBleManager = S4SensorBleManager.getInstance(); S4SensorEntity module; String macAddress = module.getMacAddress(); List<TriggerConfigBean> mTriggerConfigBeanList = new ArrayList<>() //query trigger mBleManager.queryTriggerConfiguration(macAddress, 0, new OnQueryResultListener<List<TriggerConfigBean>>() { @Override public void OnQueryResult(boolean b, List<TriggerConfigBean> triggerConfigBeanList) { if(b){ mTriggerConfigBeanList.clear(); mTriggerConfigBeanList.addAll(triggerConfigBeanList); for (TriggerConfigBean triggerConfigBean : triggerConfigBeanList) { LogUtil.d("triggerConfig:"+triggerConfigBean.toString()); } } Toast.makeText(context,"Query Adv Result:"+b,Toast.LENGTH_LONG).show(); } }); //settting trigger ,Triggers can only be configured in CombinationFrame //The adv interval is adjustable from 100ms to 60000ms and the scale is 100ms. //The adv duration is adjustable from 1s to 900s, and the scale is 1s //The adv txpower -40 -20 -16 -12 -8 -4 0 4dBm mBleManager.setTriggerConfiguration(macAddress, mTriggerConfigBeanList, new OnModifyConfigurationListener() { @Override public void onModifyResult(boolean b) { Toast.makeText(context,"Set Trigge Parameters Result:"+b,Toast.LENGTH_LONG).show(); } }); //tips: Triggers can only be configured in CombinationFrame //alwaysAdvertising=0 Regular Mode,alwaysAdvertising=1Energy-saving Mode ///alwaysAdvertising=0 Regular Mode needs to set the trigger type to TriggerSource.BUTTON_RELEASE_TRIGGER for example: TriggerConfigBean releaseTrigger = TriggerConfigBean(); releaseTrigger.setSlotNumber(combinationAdvParametersConfig.getSlotNumber()); releaseTrigger.setTriggerSource(TriggerSource.BUTTON_RELEASE_TRIGGER.getTriggerValueHex()); releaseTrigger.setAdvertisingInterval(combinationAdvParametersConfig,getAdvertisingInterval()); releaseTrigger.setTxPower(combinationAdvParametersConfig,getTxPower()) releaseTrigger.setAdvertisingDuration(advertisingDuration);//by custom mTriggerConfigBeanList.add(releaseTrigger); call setTriggerConfiguration() //alwaysAdvertising=1Energy-saving Mode, You need to set two triggers: TriggerSource.DOOR_OPEN_TRIGGER and TriggerSource.DOOR_CLOSE_TRIGGER for example: TriggerConfigBean openTrigger = TriggerConfigBean(); openTrigger.setSlotNumber(combinationAdvParametersConfig.getSlotNumber()); openTrigger.setTriggerSource(TriggerSource.DOOR_OPEN_TRIGGER.getTriggerValueHex()); openTrigger.setAdvertisingInterval(combinationAdvParametersConfig,getAdvertisingInterval()); openTrigger.setTxPower(combinationAdvParametersConfig,getTxPower()) openTrigger.setAdvertisingDuration(advertisingDuration);//by custom mTriggerConfigBeanList.add(openTrigger); TriggerConfigBean closeTrigger = TriggerConfigBean(); closeTrigger.setSlotNumber(combinationAdvParametersConfig.getSlotNumber()); closeTrigger.setTriggerSource(TriggerSource.DOOR_CLOSE_TRIGGER.getTriggerValueHex()); closeTrigger.setAdvertisingInterval(combinationAdvParametersConfig,getAdvertisingInterval()); closeTrigger.setTxPower(combinationAdvParametersConfig,getTxPower()) closeTrigger.setAdvertisingDuration(advertisingDuration);//by custom mTriggerConfigBeanList.add(closeTrigger); call setTriggerConfiguration() //tips: //The slotNumber, advertisingInterval, txPower of the trigger and the slotNumber, advertisingInterval, txPower of the CombinationFrame must be consistent. The trigger only needs to change the advertisingDuration //The configuration parameters of the trigger are best read from the device by calling queryTriggerConfiguration(), and the trigger configuration parameters in the relevant mode are filtered out according to the mode.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62Query and configure the switch status of the device。
S4SensorBleManager mBleManager = S4SensorBleManager.getInstance(); S4SensorEntity module; String macAddress = module.getMacAddress(); //Query List<OptionSwitchConfig> mOptionSwitchConfigList = new ArrayList<>() mBleManager.queryOptionSwitch(macAddress, new OnQueryResultListener<List<OptionSwitchConfig>>(){ @Override public void OnQueryResult(boolean b, List<OptionSwitchConfig> optionSwitchConfigs) { if(b){ mOptionSwitchConfigList.clear(); mOptionSwitchConfigList.addAll(optionSwitchConfigs); for (OptionSwitchConfig optionSwitchConfig : optionSwitchConfigs) { //type == 5,light effect switch; optionStatus == 1, open ;optionStatus == 0,close; // type == 6, data store switch; optionStatus == 1, open ;optionStatus == 0,close; LogUtil.d("optionSwitchConfig:"+optionSwitchConfig.toString()); } } Toast.makeText(context,"Query Switch Result:"+b,Toast.LENGTH_LONG).show(); } }); //Set the door status sensor effect switch //optionStatus == 1, open ;optionStatus == 0,close; int optionStatus = 1; mBleManager.setLightOptionSwitch(macAddress, optionStatus, new OnModifyConfigurationListener(){ @Override public void onModifyResult(boolean b) { Toast.makeText(context,"Set Switch Result:"+b,Toast.LENGTH_LONG).show(); } }); //Set the switch for storing data //optionStatus == 1, open ;optionStatus == 0,close; int optionStatus = 1; mBleManager.setDataStoreOptionSwitch(macAddress, optionStatus, new OnModifyConfigurationListener(){ @Override public void onModifyResult(boolean b) { Toast.makeText(context,"Set Switch Result:"+b,Toast.LENGTH_LONG).show(); } });
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43Query and set device working hours。
S4SensorBleManager mBleManager = S4SensorBleManager.getInstance(); S4SensorEntity module; String macAddress = module.getMacAddress(); //Query mBleManager.queryWorkPeriodsConfiguration(mMac, new OnQueryResultListener<WorkPeriodsListConfig>() { @Override public void OnQueryResult(boolean b, WorkPeriodsListConfig workPeriodsListConfig) { if(b){ mWorkPeriodsListConfig = workPeriodsListConfig; for (WorkPeriodConfig workPeriodConfig : mWorkPeriodsListConfig.getConfigList()) { //Start time, unit: seconds long startTime = workPeriodConfig.getStartTime(); int hours = startTime / 3600; int minutes = (startTime % 3600) / 60; int seconds = startTime % 60; //end time, unit: seconds long endTime = workPeriodConfig.getStartTime()+workPeriodConfig.getDuration(); int hours2 = endTime / 3600; int minutes2 = (endTime % 3600) / 60; int seconds2 = endTime % 60; //workPeriodConfig.getDuration()==0,disable;workPeriodConfig.getDuration()>0,enable; LogUtil.d("workPeriodConfig:"+workPeriodConfig.toString()); } } Toast.makeText(context,"Query WorkPeriods Result:"+b,Toast.LENGTH_LONG).show(); } }); //set mBleManager.setWorkPeriodsConfiguration(mMac, mWorkPeriodsListConfig.getConfigList(), new OnModifyConfigurationListener() { @Override public void onModifyResult(boolean b) { Toast.makeText(context,"Set WorkPeriods Result:"+b,Toast.LENGTH_LONG).show(); } });
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35Query the historical data of the door status s4 sensor
/** * Read historical data * * @param macAddress device mac * @param rules Historical data acquisition rules, 0 means to obtain all data, 1 means to obtain data of a certain time *period, when rules==0, startTime and endTime do not need to be passed, and 0 is passed by default * @param startTime starting timestamp unit: seconds * @param endTime end timestamp unit: seconds,Cannot be greater than systemTime * @param systemTime real-time timestamp unit: seconds * @param listener listener */ long systemTime = System.currentTimeMillis()/1000; long startTime = (systemTime-60*60*1000*24)/1000; long endTime = System.currentTimeMillis()/1000; int rule = 0; mBleManager.queryHistoryData(macAddress,rule, startTime, endTime, systemTime, new OnQueryResultListener<HistoryHtData>() { @Override public void OnQueryResult(boolean b, HistoryHtData historyHtData) { if(b){ List<HtData> htDataList = historyHtData.getHistoryDataList(); for (HtData htData : htDataList) { } }else{ Toast.makeText(context,"selectHTHistoryData Result: fail",Toast.LENGTH_LONG).show(); } } });
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33Firmware upgrade。
/** * Firmware upgrade * * @param macAddress device mac * @param isLinkUpgrade true url upgrade, false firmware package upgrade. The default value is false, and the url upgrade * method is not supported. * @param dfuTarget isLinkUpgrade =false, dfuTarget = 0, * @param upgradeData upgrade package data * @param listener listener */ mBleManager.firmwareUpgrade(mac, false,0,upgradeData, new OnFirmwareUpgradeListener() { /** * Progress of writing data to the upgrade package */ @Override public void updateProgress(int progress) { } / * * * If the upgrade succeeds, the device will disconnect from the mobile phone. Therefore, the OnConnStateListener callback will be triggered to return BleConnectionState. Disconnect state * / @Override public void upgradeSuccess() { } /** * Upgrade failure */ @Override public void upgradeFailed() { } });
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35factory data reset.
mBleManager.reset(macAddress, new OnModifyConfigurationListener() { @Override public void onModifyResult(boolean success) { } });
1
2
3
4
5
6
7Power Off。
mBleManager.powerOff(macAddress, new OnModifyConfigurationListener() { @Override public void onModifyResult(boolean success) { } });
1
2
3
4
5
6
7
# History
- **2024/03/27 Add edit document;