# MinewSensorKit Document
This SDK only supports the Bluetooth Asset Tag devices from Minew. The SDK helps developers to handle everything between the phone and the sensor, including: scanning the device, broadcasting data from the MTB02 device.。
# Preliminary work
Overall framework:AssetTagSensorBleManager
is the device management class, which is always a single instance when the app is running. AssetTagSensor
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.
AssetTagSensorBleManager
:Device management class that scans the surrounding MTB02 devices .
AssetTagSensor
:Example of an MTB02 sensor device acquired during scanning, inherited fromSensorModule
;
# 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/mtb02_asset_tag_sdk.jar') implementation files('libs/sensor_sdk_base.jar') implementation '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
The 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_AUDIO"/> <uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/> <uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/> <uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED"/> <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage" />
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Use
The sdk is Only one phases: scanning.
# Scanning section
# Start scanning
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.
val mBleManager = AssetTagSensorBleManager.getInstance()
when (BLETool.checkBluetooth(this@ScanDevicesListActivity)) {
BluetoothState.BLE_NOT_SUPPORT -> {
Toast.makeText(this@ScanDevicesListActivity, "Not Support BLE", Toast.LENGTH_SHORT).show()
}
BluetoothState.BLUETOOTH_OFF -> {
val enableIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
launcherActivityResultForBle.launch(enableIntent)
}
BluetoothState.BLUETOOTH_ON -> {
manager.startScan(this@ScanDevicesListActivity.application, 5*60*1000,object : OnScanAssetTagResultListener {
override fun onScanResult(scanList: MutableList<AssetTagSensor>?) {
}
override fun onStopScan(scanList: MutableList<AssetTagSensor>?) {
}
})
}
else -> {
}
}
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 AssetTagSensor
as shown below, which is stored in the broadcast frame object.
The sdk provides SensorModule
as the base class ofAssetTagSensor
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 |
mMinewFrameMap | HashMap | Adv data map |
The SensorModule
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
val module:PT100SensorEntity
val assetTagFrame: AssetTagFrame? =module.getMinewFrame(AssetTagAdvertisingFrameType.ASSET_TAG_FRAME)?.let {
it as AssetTagFrame
}
if (assetTagFrame != null) {
//mac
val macAddress = module.macAddress
//rssi
val rssi = module.rssi
//cteFlag
val cteFlag = assetTagFrame.cteLength
//encryptoFlag
val encryptoFlag = assetTagFrame.encryptoFlag
//noneCounter
val noneCounter = assetTagFrame.noneCounter
//measuredPower
val measuredPower = assetTagFrame.measuredPower
//rawDataHex
val rawDataHex = assetTagFrame.rawDataHex
//cteFlag
val cteFlag = assetTagFrame.cteLength
//cteFlag
val cteFlag = assetTagFrame.cteLength
//cteFlag
val cteFlag = assetTagFrame.cteLength
//encryptoDataByte
val encryptoDataByte = assetTagFrame.encryptoDataByte
//Encryption and decryption
val secretKey = ""//The key string entered by the user
val encryptoDataByte = when (encryptoFlag) {
1 -> {
//encipher
if (secretKey != null && secretKey.isNotEmpty()) {
CipherWrapper.data_decrypt(
AssetTagSensorUtil.hexStringToBytes(secretKey),
none,
encryptoDataByte
)
} else {
encryptoDataByte
}
}
else -> encryptoDataByte
}
val macData = ByteArray(6)
System.arraycopy(encryptoDataByte, 0, macData, 0, macData.size)
Tools.reverse(macData)
val macAddressHex = Tools.bytesToHexString(macData, ":")
// //battery vlotage
val batteryByte = ByteArray(2)
System.arraycopy(encryptoDataByte, 6, batteryByte, 0, batteryByte.size)
val battery=NumberUtil.setScale((assetTagFrame.getBatterVoltage(batteryByte)) / 1000f,3)//unit:V
//socTemperature
val socTemperatureByte = ByteArray(2)
System.arraycopy(encryptoDataByte, 8, socTemperatureByte, 0, socTemperatureByte.size)
val socTemperatur=assetTagFrame.getSocTemperature(socTemperatureByte)//unit:℃
}
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
MTB02 device has only one broadcast frame type:
AssetTagFrame
AssetTagFrame
Name Type Description encryptoFlag int 0unencrypted , 1encipher cteFlag int 0 Not configured,1Configuration cteLength int cte Length encryptoRange int Full Segment Encryption The full segment encryption range is the data between Encrypto Range
andMeasured Power
measuredPower int power noneSalt int NoneSalt encryptoDataByte byte[] Encrypting Data byte noneCounter int NoneCounter none byte[] none rawDataHex String Broadcast data hex string updateTime long Record broadcast frame data update time calculateAdvInterval long Record the broadcast data interval. Packet loss may occur. This value is inaccurate and is for reference only.
# History
- **2024/12/11 edit;