# MTB02 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.
MTIFrameRRRHandler : Device broadcast class, which can get the data when the device broadcasts.
# 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
# Use
The sdk is Only one phases: scanning.
# Scanning section
# Start scanning
[[MTICentralManager sharedInstance] startScan:^(NSArray<MTIPeripheral *> *peripherals) {
if (peripherals.count != 0) {
NSMutableSet *uniqueMacs = [NSMutableSet set]; NSMutableArray *filteredPeripherals = [NSMutableArray array]; for (MTIPeripheral *per in peripherals) {
if (!isEmptyString(per.frameRRRHandler.mac) && per.frameRRRHandler.modelType == MTIFrameFlexibility) {
NSString *mac = per.frameRRRHandler.mac;
if (![uniqueMacs containsObject:mac]) {
[uniqueMacs addObject:mac];
[filteredPeripherals addObject:per];
} else {
NSUInteger index = [filteredPeripherals indexOfObjectPassingTest:^BOOL(MTIPeripheral *existingPer, NSUInteger idx, BOOL *stop) {
if ([existingPer.frameRRRHandler.mac isEqualToString:mac]){
per.frameRRRHandler.noneCounter = existingPer.frameRRRHandler.counter;
per.frameRRRHandler.updateLTime = [[NSDate new] timeIntervalSince1970]*1000;
}
return [existingPer.frameRRRHandler.mac isEqualToString:mac];
}];
if (index != NSNotFound) {
[filteredPeripherals replaceObjectAtIndex:index withObject:per];
}
}
}
}
NSSortDescriptor *rssiSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"frameRRRHandler.rssi" ascending:NO];
NSArray *filteredSortPeripherals = [filteredPeripherals sortedArrayUsingDescriptors:@[rssiSortDescriptor]];
NSMutableArray *filteredortedPeripherals = [NSMutableArray array];
filteredortedPeripherals = [filteredSortPeripherals mutableCopy];
NSLog([NSString stringWithFormat:@"Device Account:\t(%ld)",filteredortedPeripherals.count]);
self.mainTableView.peripherals = filteredortedPeripherals;
[self.mainTableView reloadData];
}
}];
}
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
PS: The entire SDK works only when the Bluetooth state of the phone is in Poweron.
MTB02 device has only one broadcast frame type:
AssetTagFrame
MTIFrameRRRHandler
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 RangeandMeasured PowermeasuredPower 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.
# Documentation version record
- 2026.03.19 v1.0 first version;