# MBT02SensorKit Documentation
This set of SDK only supports the Bluetooth Sensor device produced by Minew, and is currently a industrial temperature and humidity sensor. The SDK can help developers handle all the work between mobile phones and Sensors, including: scanning devices, connecting devices, writing data to devices, receiving data from devices, etc.
# Preliminary work
Overall framework: MTICentralManager is a device management class, which is always a singleton when the APP is running. MTIPeripheral is a device instance class. This suite will generate a MTIPeripheral instance for each device to facilitate monitoring and operating devices.
MTICentralManager : Device management class, which can scan the surrounding Sensor devices, and can connect them, verify them, etc.
MTIPeripheral : Device instance class. When MTICentralManager discovers a physical device, MTICentralManager will generate a MTIPeripheral instance, which corresponds to a physical device.
MTIFrameHandler : Device broadcast class, which can get the data when the device broadcasts.
MTConnectionHandler : Device connection class for receiving and sending data from the device.
MTISensorHandler:传感器操作类,进行设备的读写数据。
# Get started
# Development environment:
-Xcode10 +, the current SDK is compiled with Xcode15, please use Xcode10 and above for development; -iOS12.0, the minimum system version is iOS12;
# Import into the project::
Manually
- Copy the development kit files: MTIndustrialSensorKit.framework files to the project project directory, and then add them to the project.
PS:
- !!! In iOS10 and above, Apple added permission restrictions on Bluetooth APi. You need to add a string to the project's info.plist file: Privacy-Bluetooth Peripheral Usage Description-"Your usage description".
- !!! In iOS13 and above, Apple added permission restrictions on Bluetooth APi. You need to add a string to the project's info.plist file: Privacy-Bluetooth Always Usage Description-"Your usage description".
# Start development
# Scanning equipment
First you need to get the singleton of MTICentralManager, then check the current Bluetooth status of the phone, and then you can scan the device.
// Get Manager singleton
MTICentralManagerV3 *manager = [MTICentralManagerV3 sharedInstance];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// The current state of the Bluetooth switch on the mobile phone
if(self->manager.status == PowerStatePoweredOn) {
// start device scan
[manager startScan:^(NSArray<MTIPeripheral *> *peripherals) {
//According to the type of broadcast attribute, the required sensor type can be filtered.
self->deviceAry = peripherals;
}];
}
});
// Scanned devices can also be obtained using manager.scannedPeris
// If you need to respond to the Bluetooth status of your phone. Please listen for the callback.
[manager didChangesBluetoothStatus:^(PowerState status){
switch(status) {
case PowerStatePoweredOn:
NSLog(@"bluetooth status change to poweron");
break;
case PowerStatePoweredOff:
NSLog(@"bluetooth status change to poweroff");
break;
case PowerStateUnknown:
NSLog(@"bluetooth status change to unknown");
}
}];
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
PS: The entire SDK works only when the Bluetooth state of the phone is in Poweron.
# Connect to device
// The scanned device can be obtained from the previous step
MTIPeripheralV3 *device = deviceAry[0];
// Connect the device
[manager connectToPeriperal:device SecretKey:@"Device's secretKey"];
// Listen for device connection status.
[p.connector didChangeConnection:^(Connection connection) {
if (connection == Vaildated) {
// Successful verification, successfully connected to the device
NSLog(@"vaildated");
//Need to write a password, perform other operations after the password is verified successfully
}
if (connection == Disconnected) {
NSLog(@"device has disconnected.");
}
}];
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Other command operations
Continuing from the previous step, when the device successfully verifies that the written secretKey is correct, other command operations can be performed.
The following operations are in no particular order and can be selected by yourself.
# Buzzer Setting
MTLEDBuzzerData *data = [MTLEDBuzzerData new];
data.workPeriod = false; // The gear position is false (closed) when the configuration is inactive, and it becomes active when the gear position is true
data.buzzerDuration = 200;// unit is ms.
data.intervalDuration = 1000;// unit is ms.
[device.connector.sensorHandler setBuzzerConnectionConfiguration:data withCompletionHandler:^(BOOL success) {
if (success) {
NSLog(@"Setting successfully");
}
}];
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# LED Setting
MTLEDBuzzerData *dataG = [MTLEDBuzzerData new];
dataG.workPeriod = true; // The gear position is false (closed) when the configuration is inactive, and it becomes active when the gear position is true
dataG.buzzerDuration = 200;// unit is ms.
dataG.intervalDuration = 1000;// unit is ms.
[device.connector.sensorHandler setLEDviaLEConnectionConfiguration:dataG withCompletionHandler:^(BOOL success) {
if (success) {
NSLog(@"Setting successfully");
}
}];
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Fireware update
// ⚠️Note: The ota upgrade package that comes with the demo may not match the current device. Please use the matching firmware upgrade package to perform the ota upgrade after communicating with the business according to the hardware and firmware information of the device at hand. If you use the wrong firmware update package, this may make your device unusable.
// It is not feasible to distinguish whether the firmware upgrade package matches the device only by looking at the s3 s4 keywords, because the firmware version and hardware version of the device with different factory settings may not match, so be sure to confirm that the firmware upgrade package is correct.
NSData *otaPacketData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"S3V2_NV900_20210312_s3_ota_v1_0_23" ofType:@".bin"]];
/// ota device by using this method, input firmware data, then start ota, get statusChange in stateHandler, get firmware file upload progress in progressHandler, get error in errorHandler
/// @param originOtaData data of ota
/// @param stateHandler listen status change, only "Completed" means ota successfully.
/// @param progressHandler listen file uploading progress
/// @param errorHandler listen errors in ota stage
[device.connector startOTAWithOTAData:otaPacketData stateHandler:^(OTAState state) {
if (state == OTAStateStarting) {
NSLog(@"ota start");
} else if(state == OTAStateUploading) {
NSLog(@"ota uploading");
} else if(state == OTAStateAborted) {
NSLog(@"ota aborted");
} else if(state == OTAStateDisconnecting) {
NSLog(@"ota disconnect");
} else if (state == OTAStateCompleted) {
NSLog(@"ota successfully");
} else if(state == OTAStateFailed) {
NSLog(@"ota failed");
}
} progressHandler:^(float progress) {
NSLog(@"ota progress:%f", progress);
} errorHandler:^(NSError * _Nonnull error) {
NSLog(@"ota failed,error:%@",error);
}];
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
# Precautions
- Writing multiple instructions at the same time may cause an exception. It is recommended to write a new instruction after each instruction is completed.
# Documentation version record
- 2025.10.24 v1.0 first version;