Cloud Printer Product R&D Instruction

3.Download the SDK for network configuration

Download Android SDK DEMO url:https://file.cdn.sunmi.com/SUNMIDOCS/CloudPrinter_AndroidSDK_Demo.zip
Download WeChat mini program SDK url:https://file.cdn.sunmi.com/SUNMIDOCS/CloudPrinter_WeChatSDK.rar
Download IOS SDK DEMO url:https://file.cdn.sunmi.com/SUNMIDOCS/CloudPrinter_IOSSDK_Demo.rar

Introduction:You need conduct command communication with the Bluetooth on a phone for the process of cloud printer network distribution and cloud binding needs to be realized through Bluetooth. The processes of network configuration with Bluetooth has been encapsulated in the SunmiPrinterClient class of the SDK, with which you can complete the printer pairing through few steps in the APP. Before using this function, please make sure that your Bluetooth is on and the APP can access to your location. The following is the instruction of SDK interfaces. For details, please refer to DEMO.The newly-received printer has not configured WiFi, so it is not quite inconvenient during development. Therefore, we provide a network configuration tool which can be installed on Android phones for you to use. Please click to download WIFI configuration tool at DEMO Downoad

3.1 Network configuration SDK instruction (Android)

Android network configuration SDK package is BluetoothBinding.aar.

1)Class declaration

Function interface:

  • SunmiPrinterClient

Interface declaration:

   SunmiPrinterClient sunmiPrinterClicent = SunmiPrinterClient(Context context, IPrinterClient iPrinterClient);

Input parameter:

ParameterTypeSpecification
contextContext
iPrinterClientIPrinterClientThe callback class of the cloud printer bluetooth interface

2)Callback interface

In the process of configuring WiFi for printer, it is necessary to send messages to the printer through the BLE protocol. So we define a unified callback that is used to handle the Bluetooth data transmission.

Interface name:

  • sendDataFail

Callback method:

   public void sendDataFail(int code, String msg) {
       
    }

Callback parameter:

ParameterTypeSpecification
codeintMessage error code: 0 – failed to connect to Bluetooth; 1 – Bluetooth Notify failure
msgStringThe error message

3.2 Instruction of network configuration SDK interface(Android)

1)Start scanning the printer

Interface name:

  • startScan

Interface declaration:

   sunmiPrinterClient.startScan();

Callback method:

    public void onPrinterFount(PrinterDevice printerDevice) {
       
    }

Callback parameter:

ParameterTypeSpecification
printerDevicePrinterDeviceBluetooth printer class. The printer data which is scanned are only the default name and Bluetooth MAC address

2) Stop scanning the printer

Stopping scanning the printer before the current page is disposed or starts configurating the printer if there is no callback for the interface.

Interface name:

  • stopScan

Interface declaration:

   sunmiPrinterClient.stopScan();

3) Get printer SN

Interface name:

  • getPrinterSn

Interface declaration:

   sunmiPrinterClient.getPrinterSn(btAddress);

Input parameter:

ParameterTypeSpecification
btAddressStringThe Bluetooth MAC address of the printer

Callback methods:

  • Method 1:
   public void getSnRequestSuccess() {
        
    }

Specification: this method indicates that the command of getting the SN has been successfully sent and you can wait to get the SN. A timeout mechanism can be added to the method.

  • Method 2:
   public void onSnReceived(String sn) {
        
    }

Callback parameter:

ParameterTypeSpecification
snString打印机的sn

4)Get the list of WiFi which is searched by the printer

Interface name:

  • getPrinterWifiList

Interface declaration:

   sunmiPrinterClient.getPrinterWifiList(btAddress);

Input parameter:

ParameterTypeSpecification
btAddressStringThe Bluetooth MAC address of the printer

Callback methods:

  • Method 1:
   public void routerFound(Router router) {
        
    }

Callback parameters:

ParameterTypeSpecification
routerRouterThe WIFI class which is searched by the printer

Router class parameter specification

ParameterTypeSpecification
nameStringWIFI name
hasPwdbooleanWhether the WIFI has a password
pwdStringWIFI password
rssiintThe strength (0-4) of WIFI (the larger the value, the stronger the signal)
essidbyte[]WIFI essid which is needed in network configuration
  • Method 2:
public void onGetWifiListFinish() {
        
    }

Specification: printer scanning WiFi end.

  • Method 3:
public void onGetWifiListFail() {
        
    }

Specification: printer scanning WiFi failed.

5)Configure WIFI for the printer

Interface name:

  • setPrinterWifi

Interface declaration:

   sunmiPrinterClient.setPrinterWifi(btAddress, ssid, psw);

Input parameters:

ParameterTypeSpecification
btAddressStringThe Bluetooth MAC address of the printer
ssidbyte[]WIFI ESSID
pwdStringWIFI password

Callback methods:

  • Method 1:
   public void onSetWifiSuccess() {
       
    }

Specification: the printer receives the information of the WIFI to be configured and tries to connect to the WIFI. The timeout mechanism is recommended to be added here.

  • Method 2:
   public void wifiConfigSuccess() {
       
    }

Specification: the printer has successfully configured WIFI.

  • Method 3:
   public void onWifiConfigFail() {
      
    }

Specification: The reason why the printer configure WIFI failed is usually caused by a wrong password.

6)Exit network configuration

Specification: this method only has a unified callback for sending Bluetooth message failed. It is recommended to be called in onBackPressed method.

Interface name:

  • quitConfig

Interface declaration:

   sunmiPrinterClient.quitConfig(btAddress);

Input parameter:

ParameterTypeSpecification
btAddressStringThe Bluetooth MAC address of the printer

7)Request deleting WIFI configuration and using 2G network

Specification: this method only has a unified callback for sending Bluetooth message failed. This method can be called without WIFI if the printer is in 2G network.

Interface name:

  • deleteWifiInfo

Interface declaration:

   sunmiPrinterClient.deleteWifiInfo(btAddress);

Input parameter:

ParameterTypeSpecification
btAddressStringThe Bluetooth MAC address of the printer

8)Disconnect Bluetooth from printer

Specification: this method needs to be called when destroying the page

Interface name:

  • disconnect

Interface declaration:

   sunmiPrinterClient.disconnect(btAddress);

Input parameter:

ParameterTypeDeclaration
btAddressStringThe Bluetooth MAC address of the printer

3.3 Import the network configuration SDK (WeChat mini program)

Specification: please make sure the Bluetooth on your phone is on before using this function.

Please put the sdk.js file in the folder where you want to import the interface.

	const sdk = require('../blueConnect/sdk.js');

3.4 Instruction of network configuration SDK interface (WeChat mini program)

1)the Bluetooth module and start searching the devices nearby.

Interface name:

  • openBluetoothAdapter

Interface declaration:

  //the parameter of the interface is a callback function status
  sdk.openBluetoothAdapter((res) =› {
      console.log('the result of turning on Bluetooth', res);
    }); 

Callback parameter:

ParameterValueSpecification
status0Initialized the Bluetooth module successfully.
status10001Failed to initialize the Bluetooth module because the user has not turned on Bluetooth.

2)Get the list of the Bluetooth devices nearby

Interface name:

  • onBluetoothDeviceFound

Interface declaration:

  //The parameter of the interface is a callback function devicesList
  sdk.onBluetoothDeviceFound((devicesList) =› {
      console.log('devicesList', devicesList);
    })

Callback parameter:

ParameterValueSpecification
devicesList[ ]Array

3)Stop searching Bluetooth devices nearby

Interface name:

  • stopScanDevices

Interface declaration:

	sdk.startScanDevices();

4)Turn off the Bluetooth module. You can call this method to disconnect all established connection and release system resources.

Interface name:

  • closeBluetoothAdapter

Interface declaration:

	sdk.startScanDevices();

5)Connect to a Bluetooth device

Interface name:

  • createBLEConnection

Interface declaration:

	sdk.createBLEConnection(deviceId, (res) =› {
      this.setData({
        canWrite: res.canWrite,
        deviceId: res.deviceId,
        characteristicId: res.characteristicId,
        connected: res.connected,
      })
      console.log('the device is connected successfully', res)
    });

Interface parameter:

ParameterValueSpecification
deviceIdstringThe device list can be obtained through onBluetoothDeviceFound interface and the deviceId can be found in each device information.

Callback parameter:

parameterValueSpecification
status0Obtain eigenvalues after connect successfully. Parameter as follow
10001Connected failed
10002Connected successfully but failed to obtain eigenvalues (Device does not support R&W eigenvalues)
characteristicIdstringEigenvalues ID
deviceIdstringDevice ID
serviceIdstringService ID

6)Get the cloud printer SN

Interface name:

  • getSN

Interface declaration:

  //The parameter of the interface is a callback function
  sdk.getSN((data) =› {
      console.log('sn', data);
      this.setData({
        sn: data
      });
    });

Callback parameter:

ParameterValueSpecification
datastringSN character string

7)Get the list of WiFi which is searched by the cloud printer

Interface name:

  • getWifiList

Interface declaration:

  //The parameter of the interface is a callback function
	sdk.getWifiList((data) =› {
      this.setData({
        wifiList: data
      })
      console.log('wifiList', data);
    });

Callback parameter:

ParameterValueSpecification
data[ ]Array, among which each element stands for a piece of WIFI information including SSID (WIFI name), mode (WIFI mode), RSSI (WIFI strength) and complete (the complete information reply to the command)

8)Wi-Fi Connect to a specified WIFI

Interface name:

  • connectWifi

Interface declaration:

	sdk.connectWifi(essid, password, (res) =› {
      console.log('Print WIFI connection result', res);
    });

Interface parameter:

ParameterValueSpecification
essidstringWIFI name
passwordstringWIFI password

Callback parameter:

ParameterValueSpecification
status0Connect to WIFI successful
10001Connect to WIFI failed. Please check the WIFI ssid and password

9)Exit network setting

Interface name:

  • cancelConnect

Interface declaration:

	sdk.cancelConnect();

10)Delete WIFI configuration

Interface name:

  • deleteWifi

Interface declaration:

	sdk.cancelConnect();

11)Disconnect from Bluetooth

Interface name:

  • closeBLEConnection

Interface declaration:

	sdk.closeBLEConnection();