# 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 device, etc.
Currently the SDK only supports the use of millimeter-wave radar sensors.
# Preliminary work
Overall framework: RadarSensorBleManager
is the device management class, which is always a single instance when the app is running. RadarSensor
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.
RadarSensorBleManager
:Device management class that scans the surrounding ESL devices and can connect them, verify them, etc.;
RadarSensor
:An instance of a millimeter-wave radar sensor device obtained 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
MinewSensorKit.jar
to the module's libs folder and add the following statement to thebuild.gradle
of themodule
(add the dependency directly).implementation files('libs/radar_sensor_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.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.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.BLUETOOTH_SCAN" /> <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> <receiver android:name="com.minew.radar.scan.OreoPendingReceiver" android:exported="false"> <intent-filter> <action android:name="com.minew.sensor.sdk.ACTION_FOUND" /> </intent-filter> </receiver>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Use
The sdk is divided into three phases: scanning, connecting, and reading and writing.
# Scanning section
# Start scanning
For Android 6.0 or above, you need to apply for location permission and turn on the location switch before you can perform BLE scanning.
To turn on Bluetooth scanning, you need to turn on Bluetooth first, if you go to scan without turning on Bluetooth, the app will flash back. BLETool.isBluetoothTurnOn can be used to determine if Bluetooth is turned on. If not open, you can call BLETool.setBluetoothTurnOn to open it.
RadarSensorBleManager manager = RadarSensorBleManager.getInstance(context);
if(BLETool.isBluetoothTurnOn(context)){
manager.startScan(context,new OnScanSensorResultListener() {
@Override
public void onScanResult(List<RadarSensor> list) {
//scan result
}
@Override
public void onStopScan(List<RadarSensor> list) {
//stop scan result
}
});
//Set scan duration 5 minutes, sdk default scan duration 5 minutes
manager.startScan(context,5*60*1000,new OnScanSensorResultListener() {
@Override
public void onScanResult(List<RadarSensor> list) {
//scan result
}
@Override
public void onStopScan(List<RadarSensor> list) {
//stop scan result
}
});
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
The sdk does not handle the length of the Bluetooth scan internally, but the scan is a power hungry operation, the sdk stops scanning in 5 minutes by default, if you still need to continue scanning, you can provide a timer or refresh and other operations to continue to call the scan 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 RadarSensor
as shown below, which is stored in the broadcast frame object.
Name | Type | Description |
---|---|---|
macAddress | String | device mac |
name | String | device name |
rssi | int | Signal strength |
RadarSensor
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
DeviceStaticInfoFrame deviceInforFrame = (DeviceStaticInfoFrame)module.getMinewFrame(RadarAdvertisingFrameType.DEVICE_STATIC_INFO_FRAME);
PeopleFlowMonitoringFrame peopleFlowFrame = (PeopleFlowMonitoringFrame)module.getMinewFrame(RadarAdvertisingFrameType.PEOPLE_FLOW_MONITORING_FRAME);
PeopleCoordinateInformationFrame peopleCoordinateFrame = (PeopleCoordinateInformationFrame)module.getMinewFrame(RadarAdvertisingFrameType.PeopleCoordinateInformationFrame);
if (deviceInforFrame != null) {
//Device mac address
String macAddress = deviceInforFrame.getMacAddress();
//Percentage of power
int battery = deviceInforFrame.getBattery();
//firmware version
String firmwareVersion = deviceInforFrame.getFirmwareVersion();
}
if (peopleFlowFrame != null) {
//Number of entrances detected by radar
int numberOfEntries = peopleFlowFrame.getNumberOfEntries();
//Number of trips detected by radar
int numberOfExits = peopleFlowFrame.getNumberOfExits();
}
if (peopleCoordinateFrame != null) {
//Total number of people detected by radar
int totalNumberOfPerson = peopleCoordinateFrame.getTotalNumberOfPerson();
//Personnel coordinate information detected by radar
List<CoordinateInformation> coordinateInformationLists = peopleCoordinateFrame.getCoordinateInformationLists();
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
There are 3 types of broadcast frames for radar equipment. But there can only be 2 kinds of broadcasts at the same time. People flow monitoring radar equipment has equipment static information frames and people flow monitoring frames, and personnel coordinate information radar equipment has equipment static information frames and personnel coordinate information monitoring frames.
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
People flow monitoring frame
PeopleFlowMonitoringFrame
Name Type Description frameVersion int device type serialNumber int Every time the radar sensor outputs monitoring data, the serial number is increased by 1. numberOfEntries int Number of entrances detected by radar numberOfExits int Number of trips detected by radar digitalSignature int Digital signature totalNumberOfPerson int Total number of people monitored People flow monitoring frame
- PeopleCoordinateInformationFrame
Name Type Description frameVersion int device type serialNumber int Every time the radar sensor outputs monitoring data, the serial number is increased by 1. totalNumberOfPerson int Total number of people monitored coordinateInformationLists List<CoordinateInformation> Coordinate information - CoordinateInformation
Name Type Description x float X-axis coordinates y float y-axis coordinates z float z-axis coordinates
# Connections
It is usually necessary to stop scanning before connecting. sdk provides methods to connect and disconnect.
//Stop scanning
manager.stopScan(context);
//Setting the device secret key
String key;
manager.setSecretKey(key);
//Connection, module for the device to be connected
RadarSensor module;
manager.connect(context,module);
//Disconnect. macAddress is the device mac
manager.disConnect(macAddress);
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.
After calling connect()
, there will be a status listener in sdk for the connection process.
//Setting the listener
manager.setOnConnStateListener(new OnConnStateListener() {
/*
* Status callbacks during connection
*
* @param macAddress device mac
* @param connectionState status
*/
@Override
public void onUpdateConnState(String address, MSensorConnectionState state) {
switch (state) {
case Disconnect:
//Connection failure or device disconnection will be called back, active disconnection will not call back the //status
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 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
During the connection process, sdk will return multiple connection states to the app, which the app needs to handle properly.
- MSensorConnectionState.Connecting, MSensorConnectionState.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.
- MSensorConnectionState.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.
- Disconnect: The callback will be made if the connection fails or the device is disconnected. If the APP actively calls
manager.disConnect(macAddress);
it will not call back this state.
# Reading and writing
The read and write APIs are as follows.
/**
* Set the secret key of the device
* @param eaxKey The secret key corresponding to the device
*/
@Override
public void setSecretKey(String macAddress, String password);
/**
* Set device information frame broadcast parameters
*
* @param macAddress mac
* @param advertising Interval broadcast interval, in milliseconds, the broadcast interval is adjustable from 100ms to * 5000ms, and the scale is 100ms;
* @param txPower -40 -20 -16 -12 -8 -4 0 4dBm
* @param listener
*/
void setDeviceInfoFrameAdvertisingParametersConfiguration(String macAddress, int advertisingInterval, int txPower, OnModifyConfigurationListener listener);
/**
* Query device information frame broadcast parameters
*
* @param macAddress mac
* @param listener
*/
void queryDeviceInfoFrameAdvertisingParametersConfiguration(String macAddress, OnQueryResultListener<DeviceInfoAdvertisingParametersConfiguration> listener);
/**
* Set radar frame broadcast parameters
*
* @param macAddress mac
* @param advertising Interval broadcast interval, in milliseconds, the broadcast interval is adjustable from 100ms to * 5000ms, and the scale is 50ms;
* @param txPower -40 -20 -16 -12 -8 -4 0 4dBm
* @param listener
*/
void setRadarFrameAdvertisingParametersConfiguration(String macAddress, int advertisingInterval, int txPower, OnModifyConfigurationListener listener);
/**
* Set radar frame broadcast parameters
*
* @param macAddress mac
* @param listener
*/
void queryRadarFrameAdvertisingParametersConfiguration(String macAddress, OnQueryResultListener<RadarMonitorAdvertisingParametersConfiguration> listener);
/**
* Set radar traffic configuration
*
* @param macAddress mac
* @param maps configuration maps
* @param listener
*/
void setRadarPeopleFlowMonitorConfiguration(String macAddress, Map<PeopleFlowMonitorCommandKeys,Object> maps, OnModifyConfigurationListener listener);
/**
* Query radar traffic configuration
*
* @param macAddress mac
* @param listener
*/
void queryRadarPeopleFlowMonitorConfiguration(String macAddress, OnQueryResultListener<RadarPeopleFlowMonitorParametersConfiguration> listener);
/**
* Set radar coordinate configuration
*
* @param macAddress mac
* @param maps configuration maps
* @param listener EnumMap
*/
void setRadarPeopleCoordinateMonitorConfiguration(String macAddress, Map<PeopleCoordinateMonitorCommandKeys,Object> maps, OnModifyConfigurationListener listener);
/**
* Query radar coordinate configuration
*
* @param macAddress mac
* @param listener
*/
void queryRadarPeopleCoordinateMonitorConfiguration(String macAddress, OnQueryResultListener<RadarPeopleCoordinateMonitorParametersConfiguration> listener);
/**
* Check the type of radar
*
* @param macAddress mac
* @param listener
*/
void queryMillimeterWaveRadarSensorType(String macAddress, OnQueryResultListener<MillimeterWaveRadarSensor> listener);
/**
* This instruction is used to control the light on and off. The single cycle time in the instruction = single cycle light * on time + single cycle light off time. The single cycle time must be greater than the single cycle light on time, * otherwise an error code of 20 will be reported, and the * instruction will not be executed.
* @param macAddress
* @param colorTable
* @param totalOperationTime LE, total operating time, 1~ 65535 (S)
* @param singleCycleLightingTime LE, Lighting time in a single cycle, 1~ 65535 (MS)
* @param singleCycleTime LE, single cycle time, 1~ 65535 (MS)
* @param brightness, 1~ 100
*/
void setLEDParameters(String macAddress, ColorTable colorTable,int totalOperationTime,int singleCycleLightingTime,int singleCycleTime,int brightness,OnModifyConfigurationListener listener);
/**
* Firmware upgrade
*
* @param macAddress mac
* @param upgradeData
* @param listener
*/
public void firmwareUpgrade(String macAddress,byte[] upgradeData, OnFirmwareUpgradeListener listener);
/** String macAddress
* Restore factory settings
*
* @param macAddress mac
* @param listener
*/
public void reset(String macAddress, OnModifyConfigurationListener listener);
/**
* Shut down
* @param macAddress mac
* @param 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
A post script of some methods
Read and set device information frame broadcast parameter configuration
PeopleFlowMonitorCommandKeys
Name Description SCAN_TIME Configure scan interval (unit ms, range [100,10000], default 100) HEAT_TIME Configure heartbeat interval (unit s, range [10,999], default 60) VERTICAL_HEIGHT Set vertical distance (in cm, range (50,500), default 270) SENS Configure sensitivity (range [1,19], default is 2) RANGE Configure radial distance (unit cm, range [10,1000], default 1000) XPOSI Configure X forward range (unit cm, range[-100,300),, default 100) XNEGA Configure X negative range (unit cm, range [-300,100), default -100) YPOSI Configure Y forward range (unit cm, range [-100,300), default value 50) YNEGA Configure Y negative range (unit cm, range [-300,100), default -50) SCAN_XPOSI Configure X forward scan range (unit cm, range[0,300]) SCAN_XNEGA Configure X negative scan range (unit cm, range[-300,0)) SCAN_YPOSI Configure Y forward scan range (unit cm, range[0,300]) SCAN_YNEGA Configure Y negative scan range (unit cm, range [-300,0)) SCAN_HEIGHT Configure scan height(unit ms, range[50,500]) PeopleCoordinateMonitorCommandKeys
Name Description SCAN_TIME Configure scan interval (unit ms, range [100,10000], default 100) MONITOR_TIME Configure monitoring interval (unit s, range [1,99], default 1) HEAT_TIME Configure heartbeat interval (unit s, range [10,999], default 60) RANGE Configure radial distance (in cm, range [100,1000], default 600) SENS Configure sensitivity (range [1,19], default is 2) DOOR1 Gate 1 configuration (range [-3, 3], including -3 and 3, supports up to one decimal place) DOOR2 Gate 1 configuration (range [-3, 3], including -3 and 3, supports up to one decimal place) DOOR3 Gate 1 configuration (range [-3, 3], including -3 and 3, supports up to one decimal place) WINDOWS1 Gate 1 configuration (range [-3, 3], including -3 and 3, supports up to one decimal place) WINDOWS2 Gate 1 configuration (range [-3, 3], including -3 and 3, supports up to one decimal place) WINDOWS3 Gate 1 configuration (range [-3, 3], including -3 and 3, supports up to one decimal place) //read broadcast parameter information manager.queryDeviceInfoFrameAdvertisingParametersConfiguration (mAddress, new OnQueryResultListener < DeviceInfoAdvertisingParametersConfiguration > () { @Override Public void OnQueryResult (boolean queryResult, DeviceInfoAdvertisingParametersConfiguration queryInfo) { //queryResult is true, indicating that the query succeeded, otherwise it failed IF (queryResult) { } else { //query failed } } }); //Set broadcast parameter information Int advertising Interval = 1000; Int txPower = -4; manager.setDeviceInfoFrameAdvertisingParametersConfiguration (macAddress, advertising Interval, txPower, new OnModifyConfigurationListener () { @Override Public void onModifyResult (boolean success) { //success is true, indicating that the setting was successful, otherwise it is a failure } });
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21Read and set equipment radar monitoring frame broadcast parameter configuration
//read broadcast parameter information manager.queryRadarFrameAdvertisingParametersConfiguration (mAddress, new OnQueryResultListener < RadarMonitor AdvertisingParametersConfiguration > () { @Override Public void OnQueryResult (boolean queryResult, RadarMonitor AdvertisingParametersConfiguration queryInfo) { //queryResult is true, indicating that the query succeeded, otherwise it failed IF (queryResult) { } else { //query failed } } }); //Set broadcast parameter information Int advertising Interval = 1000; Int txPower = -4; manager.setRadarFrameAdvertisingParametersConfiguration (macAddress, advertising Interval, txPower, new OnModifyConfigurationListener () { @Override Public void onModifyResult (boolean success) { //success is true, indicating that the setting was successful, otherwise it is a failure } });
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21Read and set device radar traffic monitoring parameter configuration.
//Read the traffic configuration parameter information manager.queryRadarPeopleFlowMonitorConfiguration (mAddress, new OnQueryResultListener < RadarPeopleFlowMonitor ParametersConfiguration > () { @Override Public void OnQueryResult (boolean queryResult, RadarPeopleFlowMonitoring orParametersConfiguration queryInfo) { //queryResult is true, indicating that the query succeeded, otherwise it failed IF (queryResult) { } else { //query failed } } }); //Set the traffic configuration parameter information Map < PeopleFlowMonitorCommandKeys CommandKeys, Object > maps = new HashMap < > (); Maps.put (PeopleFlowMonitor CommandKeys. HEAT_TIME, 100); Maps.put (PeopleFlowMonitor CommandKeys. VERTICAL_HEIGHT, 100); Maps.put (PeopleFlowMonitor CommandKeys.SCAN_TIME, 1000); Maps.put (PeopleFlowMonitor CommandKeys. SENS, 2); Maps.put (PeopleFlowMonitor CommandKeys. XPOSI, 50); Maps.put (PeopleFlowMonitor CommandKeys. XNEGA, -50); manager.setRadarPeopleFlowMonitoringConfiguration (macAddress, maps, new OnModifyConfigurationListener () { @Override Public void onModifyResult (boolean success) { //success is true, indicating that the setting was successful, otherwise it is a failure } });
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
27Read and set equipment radar personnel coordinate monitoring parameter configuration.
//Read the personnel coordinate configuration parameter information manager.queryRadarPeopleCoordinateMonitoring orConfiguration (mAddress, new OnQueryResultListener < RadarPeopleCoordinateMonitoring orParametersConfiguration > () { @Override Public void OnQueryResult (boolean queryResult, RadarPeopleCoordinateMonitoring orParametersConfiguration queryInfo) { //queryResult is true, indicating that the query succeeded, otherwise it failed IF (queryResult) { } else { //query failed } } }); //Set personnel coordinate configuration parameter information Map < PeopleCoordinateMonitor CommandKeys, Object > maps = new HashMap < > (); Maps.put (PeopleCoordinateMonitor CommandKeys. HEAT_TIME, 100); Maps.put (PeopleCoordinateMonitor CommandKeys. SCAN_TIME, 1000); Maps.put (PeopleCoordinateMonitor CommandKeys. MONITOR_TIME, 10); Maps.put (PeopleCoordinateMonitor CommandKeys. SENS, 2); List < CoordinateBean > doorList = new ArrayList < > (); doorList.add (new CoordinateBean (-3,0)); doorList.add (new CoordinateBean (0,3)); Maps.put (PeopleCoordinateMonitoring CommandKeys. DOOR1, doorList); List < CoordinateBean > windowList = new ArrayList < > (); windowList.add (new CoordinateBean (-1, 1)); windowList.add (new CoordinateBean (2, 3)); Maps.put (PeopleCoordinateMonitor CommandKeys. WINDOWS1, windowList); manager.setRadarPeopleCoordinateMonitor Configuration (macAddress, maps, new OnModifyConfigurationListener () { @Override Public void onModifyResult (boolean success) { //success is true, indicating that the setting was successful, otherwise it is a failure } });
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
32Firmware Upgrade。。
/** * Firmware upgrade * * @param macAddress device mac * @param isLinkUpgrade Whether it is a connection upgrade, set false by the upgrade package, and set true by the url upgrade * method. * @param dfuTarget Upgrade Bluetooth firmware dfuTarget = 0, upgrade radar firmware dfuTarget = 1 * @param upgradeData Upgrade package data * @param listener listener */ manager.firmwareUpgrade(mac,isLinkUpgrade,dfuTarget, upgradeData, new OnFirmwareUpgradeListener() { /** * Progress of writing upgrade package data */ @Override public void updateProgress(int progress) { } /** * Upgrade success callback, at this time the device will actively disconnect from the phone, so it will trigger *OnConnStateListener callback, return * MSensorConnectionState.Disconnect state */DisconnectState. @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
35
36Set the radar device type.
//Query the type of radar manager.queryMillimeterWaveRadarSensorType (mAddress, new OnQueryResultListener < MillimeterWaveRadarSensor > () { @Override Public void OnQueryResult (boolean queryResult, MillimeterWaveRadarSensor queryInfo) { //queryResult is true, indicating that the query succeeded, otherwise it failed IF (queryResult) { RadarFirmwareType radarFirmwareType = queryInfo.getRadarFirmwareType (); Switch (radarFirmwareType) { Case PEOPLE_FLOW_MONITORING_FRAME: RadarPeopleFlowMonitoring orParametersConfiguration radarPeopleFlowConfiguration = getRadarPeopleFlowMonitoring orParametersConfiguration () Break; Case PEOPLE_COORDINATE_INFOMATION_FRAME: RadarPeopleCoordinateMonitor orParametersConfiguration radarPeopleCoordinateConfiguration = getRadarPeopleCoordinateMonitor orParametersConfiguration (); Break; Default: Break; } } else { //query failed } } });
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22Restore factory settings.
/** * Restore factory settings * * @param macAddress mac */ Manager.reset (macAddress, new OnModifyConfigurationListener () { @Override Public void onModifyResult (boolean success) { //success is true, indicating that the setting was successful, otherwise it is a failure } });
1
2
3
4
5
6
7
8
9
10
11
8.shutdown。
/**
* Reset
*
* @parameter macAddress device mac
*/
Manager.poweroff (macAddress, new OnModifyConfigurationListener () {
@overlay
Public void onModifyResult {Boolean Success}
//success is true, indicating that the setting was successful, otherwise it is a failure
}
});
2
3
4
5
6
7
8
9
10
11
# History
- **2023/07/19 add;