Kitchen Scale
Yolanda kitchen scale equipment is divided into two types: broadcast equipment and Bluetooth equipment.
When the broadcast kitchen scale is measuring, it will continuously emit a Bluetooth broadcast signal, which will contain weighing information.
The working process of this device is the same as Broadcast Scale:
When the Bluetooth kitchen scale is measuring, you need to find that the Bluetooth kitchen scale device is connected to the device before it can upload data normally.
1. initialization
Use QNBleApi.initSdk-to-initialize,-there-are-related-introductions-in-the-previous-article,-please-check
2. scanning
1. Set the Bluetooth scan callback monitor class
Before scanning, you need to set the listener class, the method is QNBleApi.setBleDeviceDiscoveryListener, this method only needs to be called once, remember to set to null/nil when you are sure you do n’t need to scan
android example:
QNBleApi.getInstance(context).setBleDeviceDiscoveryListener(new QNBleDeviceDiscoveryListener() {
@Override
public void onDeviceDiscover(QNBleDevice device) {
//The device does not need to handle the callback
}
@Override
public void onStartScan() {
//Back to start scanning
}
@Override
public void onStopScan() {
//return to the end of the scan
}
@Override
public void onScanFail(int code) {
//The callback for the scan failure will be returned with an error code. For details, please refer to the error code details page
}
@Override
public void onBroadcastDeviceDiscover(QNBleBroadcastDevice device) {
//Broadcast scale, this type of device needs to handle events in this callback
}
@Override
public void onKitchenDeviceDiscover(QNBleKitchenDevice device) {
//Kitchen scale, this kind of equipment needs to handle events in this callback
}
});
//(BleKitchenScale exclusive)DataListener
QNBleApi.getInstance(context).setKitchenDataListener(new QNBleKitchenDataListener() {
@Override
public void onGetBleKitchenWeight(QNBleKitchenDevice device, double weight) {
}
@Override
public void onBleKitchenConnecting(QNBleKitchenDevice device) {
setBleStatus(QNScaleStatus.STATE_CONNECTING);
}
@Override
public void onBleKitchenConnected(QNBleKitchenDevice device) {
setBleStatus(QNScaleStatus.STATE_CONNECTED);
}
@Override
public void onBleKitchenDisconnected(QNBleKitchenDevice device) {
setBleStatus(QNScaleStatus.STATE_DISCONNECTED);
}
@Override
public void onBleKitchenError(QNBleKitchenDevice device, int errorCode) {
Log.d("ConnectActivity", "onConnectError:" + errorCode);
setBleStatus(QNScaleStatus.STATE_DISCONNECTED);
}
});
iOS example:
//set proxy
QNBleApi *bleApi = [QNBleApi sharedBleApi];
bleApi.discoveryListener = self;
bleApi.bleKitchenDataListener = self; //(BleKitchenScale exclusive)DataListener
//Implement the proxy method
- (void)onDeviceDiscover:(QNBleDevice *)device {
//The device does not need to handle the callback
}
- (void)onBroadcastDeviceDiscover:(QNBleBroadcastDevice *)device {
//Broadcast scale, this type of device needs to handle events in this callback
}
- (void)onKitchenDeviceDiscover:(QNBleKitchenDevice *)device {
//Kitchen scale, this kind of equipment needs to handle events in this callback
}
- (void)onGetBleKitchenWeight:(QNBleKitchenDevice *)device weight:(double)weight {
//Bluetooth kitchen scale exclusive, measurement data callback
}
- (void)onStopScan {
//Callback when scanning is stopped
}
- (void)onStartScan {
//Callback when starting scanning
}
2. Start the scan
Confirm that Bluetooth is turned on, and Android needs to check the location permission
andlocation switch
. If you confirm that Bluetooth is turned on, the location permission is authorized, and the location service switch is turned on, you can start Bluetooth scanning
After Android 6.0, targetSdkVersion>= App above 23, you need to obtain positioning permission for Bluetooth scanning, please check About The location service switch is not mandatory, but some phones do not turn on this switch, and the device cannot be scanned, which is related to each mobile phone system. iOS13 system has added Bluetooth usage permission, you need to check whether there is usage permission, confirm that authorized and Bluetooth is turned on, start scanning
The scanning method is QNBleApi.startBleDeviceDiscovery,-the-scanned-device-data-will-be-in-the-scanning-interface-set-above-qnbledevicediscoverylistener Callback.
In addition, some feature settings related to scanning can be set in QNConfig, these options should be sufficient.
Usually the APP will have an interface dedicated to measurement. We generally scan for Bluetooth after the interface is displayed, and stop scanning when the interface disappears.
android example:
QNBleApi.getInstance(context).startBleDeviceDiscovery(new QNResultCallback() {
@Override
public void onResult(int code, String msg) {
//This method does not return to the device, but indicates whether the scan was started successfully
if (code != CheckStatus.OK.getCode()) {
ToastMaker.show(ScanActivity.this,code+":"+msg);
}
}
});
iOS example:
//start scan
[[QNBleApi sharedBleApi] startBleDeviceDiscovery:^(NSError *error) {
//The callback here indicates whether the scan method is successfully started
if (error) {
NSLog([NSString stringWithFormat:@"Failed to start scanning method, reason: %@",error]);
}
}];
3. connect device(BleKitchenScale exclusive)
Call the connection method to connect QNBleKitchenDevice object which callbacked in onKitchenDeviceDiscover
android example:
QNBleApi.getInstance(context).connectBleKitchenDevice(device, new QNResultCallback() {
@Override
public void onResult(int code, String msg) {
}
});
iOS example:
[_bleApi connectBleKitchenDevice:kitchenDevice callback:^(NSError *error) {
}];
three、Results processing
android example:
public void onKitchenDeviceDiscover(QNBleKitchenDevice device) {
if (null != device && device.getMac().equals(mBleDevice.getMac())) {
//Data processing
}
}
public void onGetBleKitchenWeight(QNBleKitchenDevice device, double weight) {
}
iOS example:
# pragma mark-Kitchen scale processing logic
- (void)onKitchenDeviceDiscover:(QNBleKitchenDevice *)device {
//Data processing
}
- (void)onGetBleKitchenWeight:(QNBleKitchenDevice *)device weight:(double)weight {
//Data processing
}
At this point, the basic process of the broadcast scale has been completed, the APP can save the data and display the data after receiving the analytical data. For other problems, please refer to the code in the Demo first. If you have any questions, you can also check FAQ. Common problems have not found related problems, you can try to search in the SDK if there are related APIs or instructions, if not, please contact our technical staff to assist in docking.
Demo address is as follows: iOSDemo