- This SDK only support devices based on LW005-MP.
- We divide the communications between SDK and devices into two stages: Scanning stage, Connection stage.For ease of understanding, let’s take a look at the related classes and the relationships between them.
MKMPCentralManager
:global manager, check system’s bluetooth status, listen status changes, the most important is scan and connect to devices;
MKMPInterface
: When the device is successfully connected, the device data can be read through the interface inMKMPInterface
;
MKMPInterface+MKMPConfig
: When the device is successfully connected, you can configure the device data through the interface inMKMPInterface+MKMPConfig.h
;
in this stage, MKMPCentralManager
will scan and analyze the advertisement data of LW003 devices.
The device broadcast information includes whether a password is required when connecting.
- Enter the password to connect, then call the following method to connect:
connectPeripheral:password:sucBlock:failedBlock:
- You do not need to enter a password to connect, call the following method to connect:
connectPeripheral:sucBlock:failedBlock:
- Xcode9+, due to the DFU and Zip Framework based on Swift4.0, so please use Xcode9 or high version to develop;
- iOS12, we limit the minimum iOS system version to 12.0;
CocoaPods
SDK-LB is available through CocoaPods.To install it, simply add the following line to your Podfile, and then import <MKLoRaWAN-MP/MKMPSDK.h>:
pod 'MKLoRaWAN-MP/SDK'
-
!!!on iOS 10 and above, Apple add authority control of bluetooth, you need add the string to “info.plist” file of your project: Privacy - Bluetooth Peripheral Usage Description - “your description”. as the screenshot below.
-
!!! 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”.
First of all, the developer should get the sharedInstance of Manager:
MKMPCentralManager *manager = [MKMPCentralManager shared];
- 1.Set the scan delegate and complete the related delegate methods.
manager.delegate = self;
- 2.you can start the scanning task in this way:
[manager startScan];
- 3.at the sometime, you can stop the scanning task in this way:
[manager stopScan];
The MKMPCentralManager
contains the method of connecting the device.
/// Connect device function
/// @param trackerModel Model
/// @param password Device connection password,8 characters long ascii code
/// @param sucBlock Success callback
/// @param failedBlock Failure callback
- (void)connectPeripheral:(nonnull CBPeripheral *)peripheral
password:(nonnull NSString *)password
sucBlock:(void (^)(CBPeripheral *peripheral))sucBlock
failedBlock:(void (^)(NSError *error))failedBlock;
Through the manager, you can get the current Bluetooth status of the mobile phone, and the connection status of the device. If you want to monitor the changes of these two states, you can register the following notifications to achieve:
- When the Bluetooth status of the mobile phone changes,
mk_mp_centralManagerStateChangedNotification
will be posted.You can get status in this way:
[[MKMPCentralManager shared] centralStatus];
- When the device connection status changes,
mk_mp_peripheralConnectStateChangedNotification
will be posted.You can get the status in this way:
[MKMPCentralManager shared].connectState;
Register for mk_mp_deviceDisconnectTypeNotification
notifications to monitor data.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(disconnectTypeNotification:)
name:@"mk_mp_deviceDisconnectTypeNotification"
object:nil];
- (void)disconnectTypeNotification:(NSNotification *)note {
NSString *type = note.userInfo[@"type"];
/*
After connecting the device, if no password is entered within one minute, it returns 0x01. After successful password change, it returns 0x02, the device has no data communication for two consecutive minutes, it returns 0x03, and the shutdown protocol is sent to make the device shut down and return 0x04.
*/
}
- 20220119 first version;