Read Device Version Information and Battery Level¶
⚠️ Note: This document describes how to use the SDK's API to operate the scanning device and provides sample code in C. Please note that the API is a synchronous operation and may block the main thread when used.
⚠️ Note: Before using the API, you need to connect the device and register for message notifications to receive messages from the device. For detailed steps, please refer to Message Notification.
1. Read Device Bluetooth Version Information¶
To read the device's Bluetooth version information, you need to perform a read
operation using the following Bluetooth service and characteristic UUIDs:
Bluetooth | UUID |
---|---|
Service | 0x0000ff0000001000800000805f9b34fb |
Characteristic | 0x0000ff0200001000800000805f9b34fb |
By performing a Bluetooth read
operation on the above service and characteristic, you can obtain the device's Bluetooth version information version
. The data is encoded in UTF-8.
version
represents the device's Bluetooth version information. For example: OTA_D_V0.1.8
, where V0.1.8
is the version number.
2. Read Device Firmware Version Information¶
2.1 Write Command¶
To read the device's firmware version information, you need to perform a write without response
operation using the following Bluetooth service and characteristic UUIDs:
Bluetooth | UUID |
---|---|
Service | 0x0000ff0000001000800000805f9b34fb |
Characteristic | 0x0000ff0400001000800000805f9b34fb |
Use the following command to get the data to write to the characteristic:
const char* result = inateck_scanner_cmd_software_version();
The return result is in JSON
format. If the call is successful, result
will return:
{
"status": 0,
"data": [0, 1, 2, 3],
}
If the call fails, result
will return:
{
"status": 1,
"data": [],
}
data
is the data to write to the characteristic, a byte array. This data needs to be sent to the device to obtain the firmware version information.
2.2 Message Parsing¶
After waiting for the device to respond, you can use the following method to parse the data:
const char* result = inateck_scanner_cmd_software_result(data, data_length);
The return result is in JSON
format. If the call is successful, result
will return:
{
"status": 0,
"data": "BCST-75 V1.1.0 AI"
}
If the call fails, result
will return:
{
"status": 1,
"data": ""
}
data
is the device firmware version information. For example: BCST-75 V1.1.0 AI
.
2.3 Sample Code¶
#include <stdio.h>
#include <string.h>
#include "inateck_scanner_cmd.h"
int main() {
const char* result = inateck_scanner_cmd_software_version();
if (result) {
// result is in JSON format, parse the data
const unsigned char* data = (const unsigned char*)result;
int data_length = strlen(result);
// Send data via Bluetooth write without response
// Assume there is a function send_data_via_bluetooth to send data
send_data_via_bluetooth(data, data_length);
// Wait for the device to respond, receive data
// Assume there is a function receive_data_via_bluetooth to receive data
receive_data_via_bluetooth();
const unsigned char* data = get_received_data();
int data_length = get_received_data_length();
// Parse the data
const char* result = inateck_scanner_cmd_software_result(data, data_length);
if (result) {
// Parse the JSON result, parse according to actual situation
const char* version = ...; // Parse version
printf("Firmware Version Information: %s\n", version);
}
}
return 0;
}
3. Read Device Battery Information¶
To read the device's battery information, you need to perform a read
operation using the following Bluetooth service and characteristic UUIDs:
Bluetooth | UUID |
---|---|
Service | 0x0000ff0000001000800000805f9b34fb |
Characteristic | 0x00002a1900001000800000805f9b34fb |
By performing a Bluetooth read
operation on the above service and characteristic, you can obtain the device's battery information battery
. battery
is the device's battery percentage, ranging from 0-100.