sidebar: auto

## MinewESLKit Documentation

​	This set of SDK only supports Bluetooth ESL devices produced by Minew. The SDK can help developers handle all the work between the phone and the ESL, including: scanning the device, connecting the device, writing data to the device, receiving data from the device, etc.

### preliminary work

​	Overall framework: MTCentralManager is a device management class, which is always a singleton when the APP is running. MTPeripheral is a device instance class. This suite will generate a MTPeripheral instance for each device to facilitate monitoring and operating devices.

**MTCentralManager** : Device management class, which can scan the surrounding ESL devices, and can connect them, verify them, etc.

**MTPeripheral** : Device instance class. When MTCentralManager discovers a physical device, MTCentralManager will generate a MTPeripheral instance, which corresponds to a physical device.

**MTBroadcastHandler** : Device broadcast class, which can get the data when the device broadcasts.

**MTConnectionHandler** : Device connection class for receiving and sending data from the device.

**MTUtils** : Equipment verification and data processing.

### Get started

##### Development environment:

-Xcode10 +, the current SDK is compiled with Xcode11, please use Xcode10 and above for development;
-iOS11, the minimum system version is iOS11;

##### Import into the project:

1. Copy the three framework files of the development kit: MinewESLKit.framework, iOSDFULibrary.framework, Zip.framework to the project directory, and then add them to the project.
2. If after adding the SDK, it shows that the path cannot be found when running, you can delete the package and add it again in General -> Frameworks, Libraries, and Embedded Content.

PS:

1. !!! 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".
2. !!! 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 MTCentralManager, then check the current Bluetooth status of the phone, and then you can scan the device.

```objective-c
// Get Manager singleton
MTCentralManager * manager = [MTCentralManager 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 <MTPeripheral *> * devices) {
        self-> deviceAry = devices;
    }];
    }
});
// 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");
	}
}];
```

**PS: The entire SDK works only when the Bluetooth state of the phone is in Poweron.** 

##### Connect to device

```objective-c
// The scanned device can be obtained from the previous step
MTPeripheral * device = deviceAry [0];
// Connect the device
[manager connectToPeriperal: device];
// Listen for device connection status.
[p.connector didChangeConnection: ^ (Connection connection) {
    if (connection == Vaildated) {
      // Successful verification, successfully connected to the device
        NSLog (@ "vaildated");
    }
    if (connection == Disconnected) {
        NSLog (@ "device has disconnected.");
    }
}];
```

##### Write data to the device

​	Take the next step, when the mobile phone successfully establishes a connection with a device and the authentication is successful, the device can read and write.

1. Write data

   ```objective-c
   [self-> _ per.connector writeData: data completion: ^ (BOOL success, NSError * _Nonnull error) {
      if (error) {
          NSLog (@ "write data failed:% @", error);
      }
      else {
          NSLog (@ "write data success");
      }
   }];
   ```

2. Receive data

   ```objective-c
   [_per.connector didReceiveData: ^ (NSData * _Nonnull data) {
      if (data) {
          NSLog (@ "receive data success:% @", data);
       }
       else {
          NSLog (@ "receive data failed");
       }
      }
   }];
   ```


### Schedule

##### MTCentralManager Property Description

|     Name     |    Type    |       Description        |
| :----------: | :--------: | :----------------------: |
|    status    | PowerState | phone's bluetooth status |
| scannedPeris |  NSArray   |     scanned devices      |

##### MTPeripheral Property Description

|    Name    |        Type         |          Description          |
| :--------: | :-----------------: | :---------------------------: |
| identifier |      NSString       |       device Identifier       |
| broadcast  | MTBroadcastHandler  | obejct of MTBroadcastHandler  |
| connector  | MTConnectionHandler | obejct of MTConnectionHandler |

##### MTBroadcastHanler Property Description

|       Name        |   Type    |    Description    |
| :---------------: | :-------: | :---------------: |
|       name        | NSString  |    device name    |
|       rssi        | NSInteger |    device RSSI    |
|        mac        | NSString  |    device Mac     |
|    identifier     | NSString  | device identifier |
|    firmVersion    | NSString  |    firmversion    |
|  hardwareVersion  | NSString  |  hardwareVersion  |
|    screenInfo     | NSString  |    screenInfo     |
|      battery      | NSString  |      battery      |
|     chipTemp      |  double   |     chipTemp      |
|     heartbeat     | NSString  |     heartbeat     |
|      tagRssi      | NSString  |      tagRssi      |
|     chipInfo      | NSString  |     chipInfo      |
|    imageIdData    |  NSData   |    imageIdData    |
|     errorCode     | NSInteger |     errorCode     |
| peripheralSupport | NSString  | peripheralSupport |

##### MTConnectionHandler Property Description

|    Name    |    Type    |      Description      |
| :--------: | :--------: | :-------------------: |
| macString  |  NSString  |      device Mac       |
| connection | Connection | device connect status |



## Notes

1. If after adding the SDK, it shows that the path cannot be found when running, you can delete the package and add it again in General -> Frameworks, Libraries, and Embedded Content.

2. MinewESLKit includes dual versions, as shown below:

   Among them, the file containing the words x86&ARM (hereinafter referred to as x86&ARM, which is the second zip file in the above figure) indicates that this development kit supports debugging in both the simulator and the physical real machine, and the file only contains the words ARM ( Hereinafter referred to as "ARM", which is the first zip file in the above figure) means that this development kit only supports physical debugging and release.

   !!! When publishing an APP based on this development kit, "ARM" must be used.

   This update is due to Apple's updated APPStore receiving policy, which may prevent developers from uploading applications containing x86_64 binary codes. So to be safe, please use "ARM" to package when uploading to APPStore.

   ![image-20200825100526893](/Users/minew/Library/Application Support/typora-user-images/image-20200825100526893.png)

## Change log

- 2020.03.03  v1.0 first version;
- 2020.08.25  v1.01 

