This article mainly describes how to use the smart cloud device to access the SDK to transparently transmit data between the APP and the device. Between APP and MCU, there are two data transparent transmission methods:
Use "extended type" data points for transparent transmission
Do not define data points directly for transparent transmission of data, that is, purely transparent
First understand what is transparent and what is passthrough? Transparent transmission refers to transparent transmission. That is, regardless of the transmission service, the transmission network is only responsible for transmitting the service to be transmitted to the destination node, and at the same time, the transmission quality can be ensured without processing the transmitted service.
This is similar to express mail, which may arrive at your hands through various combinations of bicycles, cars, trains, and planes, but you don't have to worry about what goes on among them.
Why do you want to pass it? Transparent transmission is generally used to read remote serial data. For example, every Internet surfer in an Internet cafe must have an ID card to access the Internet, but the ID card database cannot be placed in every Internet cafe. Therefore, the serial data of the card reader is transmitted back to the public security bureau through transparent transmission, and the identity card number is compared on the platform of the Public Security Bureau.
Closer to home, now enter today's theme, to talk about, which two transparent transmission methods between the smart cloud APP and MCU.
Manner 1: Spread type data point transparent transmission
1. Define data points
Defining an extended type of data point in the data points in the product management of the Wisdom cloud, as shown in the figure above: The defined data length is 60 bytes (in case of transparent transmission, the data length temporarily supports data transmission within 900 bytes).
2. Device data report protocol description
The device MCU reports transparent transmission data according to the data point definition format. After completing the definition of a new product, each new product has a corresponding serial port communication protocol file. The file download path is as follows:
In the 4.9 part of the serial communication protocol document file, the MCU reports the data format, as shown below:
The dev_status (60B) in the figure is the data that needs to be transparently transmitted.
3. SDK callback interface description
The APP receives the callback interface of the MCU report data: didReceiveData, and determines that the result is GizWifiErrorCode.GIZ_SDK_SUCCESS. The received data may be ordinary data points or extended data points.
4.APP receive data code example
Andriod received an MCU report extension data type code example:
Final protected static char[] hexArray = "0123456789ABCDEF".toCharArray(); // Turn the hexadecimal byte into a string For example byte value {0x62, 0x63}, Then it will change to "6263" public static String bytesToHex(byte[] bytes) { char[] hexChars = new char[bytes.length * 3]; For (int j = 0; j < bytes.length; j++) { int v = bytes[j] & 0xFF; hexChars[j * 3] = hexArray[v >>> 4]; hexChars[j * 3 + 1] = hexArray[v & 0x0F]; hexChars[j * 3 + 2] = ''; } return new String(hexChars); } @Overrideprotected void didReceiveData(GizWifiErrorCode result, GizWifiDevice device, ConcurrentHashMap dataMap, int sn) { if (result == GizWifiErrorCode.GIZ_SDK_SUCCESS) { // Ordinary data point types, Boolean, integer, and enumeration data This type is generally readable and writable if (dataMap.get("data") != null) { ConcurrentHashMap map = (ConcurrentHashMap) dataMap.get("data"); // Expand data points, Key is "kuozhan" byte[] bytes = (byte[]) map.get("kuozhan"); String string = bytesToHex(bytes); Toast.makeText(this, string, Toast.LENGTH_SHORT).show(); } }} |
iOS received MCU report extension data type code example:
- (void)device:(GizWifiDevice *)device didReceiveData:(NSError *)result data:(NSDictionary *)dataMap withSN:(NSNumber *)sn{ If (result.code == GIZ_SDK_SUCCESS) { NSLog (@"received data"); NSDictionary *data = dataMap[@"data"]; NSString *kuozhan = data[@"kuozhan"]; NSLog(@"dataMap = %@", dataMap); NSLog(@"kuozhan = %@", kuozhan); }} |
5. Device reporting data case
Case: Data is reported according to the data point reporting format:
FF FF 00 42 05 00 00 00 04 01 02 03 04 05 06 07 08 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 78
Note that the defined extended data type is 60 bytes. Therefore, when reporting data, you must also ensure that the number of “device status†bytes in the report command is 60 bytes. Otherwise, the APP will not receive data. The extra data can be zero-filled.
There is a "kuozhan" key in the dataMap dictionary received by the APP. The corresponding value is the transparent data.
dataMap = { Alerts={ }; Data ={ Kuozhan = <01020304 05060708 09000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000>; }; Faults={ }; } |
6.APP issued data code example
The APP sends extended data according to the data point definition in the write interface of the GizWifiDevice class.
Andriod issued an extended data type command code example:
Byte[] input1 = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 }; // byte[] input2 = { 11, 22, 33, 44, 55, 66, 77, 88, 99}; ConcurrentHashMap dataMap = new ConcurrentHashMap(); dataMap.put("kuozhan", input1); Device.write(dataMap, 0); |
iOS issued extended data type command code example:
Char input1[7] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77}; // char input2[7] = {11, 22, 33, 44, 55, 66, 77}; NSData* data = NSDictionary *request = @{@"kuozhan": data}; [self.device write:request withSN:44]; |
In the above code, the transparent transmission results of input1 and input2 are different. The input1 defines the hexadecimal value, and the input2 contains the decimal value. If the value of 0x11 in input1 is used to send to the device, then the device will receive a hexadecimal value of 0x11. If the value of 11 using input2 is sent to the device, then the device will receive 0x0b (decimal 11 corresponds to 16 Base b). Use input1 to deliver the device. The data received by the MCU is:
FF FF 00 43 03 45 00 00 01 01 11 22 33 44 55 66 77 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 77 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 01 11 22 33 44 55 66 77 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 69 69 00 00 00 00 69 69
Method 2: No data points are transparently transmitted
1 device data reporting protocol description
The format of the data reported by the MCU is shown in the following table. The packet length (len) refers to the length of the byte from the command start to the checksum (including the command and checksum). Dev_status needs to transparently transmit data. It can be set to any length, but it supports 900B transmission temporarily.
If the device reports the instruction: FF FF 00 0D 05 00 00 00 06 11 22 33 44 55 66 77 F4; then the transparent data is 11 22 33 44 55 66 77
2. SDK callback interface description
The APP terminal receives the callback interface of the MCU report data: didReceiveData. If the result is GizWifiErrorCode.GIZ_SDK_SUCCESS, it indicates that the received data is successful. The value of the “binary†field in the dataMap of the returned parameter is transparently transmitted.
3.APP receive data code example
Andriod receives MCU no data point reporting code example:
@Overrideprotected void didReceiveData(GizWifiErrorCode result, GizWifiDevice device, ConcurrentHashMap dataMap, int sn) { If (result == GizWifiErrorCode.GIZ_SDK_SUCCESS) { // transparently pass data, no data point definition, Suitable for developers to define their own self-parse if (dataMap.get("binary") != null) { byte[] binary = (byte[]) dataMap.get("binary"); Log.i("info", "Binary data:" + bytesToHex(binary)); // After receiving it needs to resolve itself } }} |
iOS receives MCU no data point reporting code example:
- (void)device:(GizWifiDevice *)device didReceiveData:(NSError *)result data:(NSDictionary *)dataMap withSN:(NSNumber *)sn{ If (result.code == GIZ_SDK_SUCCESS) { NSLog (@"received data"); NSLog(@"dataMap = %@", dataMap); NSString *binary = dataMap[@"binary"]; // need to parse binary data later }} |
If the MCU reports: FF FF 00 0D 05 00 00 00 06 11 22 33 44 55 66 77 F4 the APP will print: Binary data: 11 22 33 44 55 66 77
4.APP issued data code example
APP sends the json format in the write interface of the GizWifiDevice class: {"binary": "xxxxxx"}; The data format received by the MCU is as follows:
Andriod issued no data point transparent data code example:
Byte[] input1 = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 };ConcurrentHashMap dataMap = new ConcurrentHashMap();dataMap.put("binary", input1);device.write(dataMap, 0); |
iOS delivers data point transparent data code example:
Char input1[7] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77}; // char input2[7] = {11, 22, 33, 44, 55, 66, 77}; NSData* data = [NSData dataWithBytes:input1 length:sizeof(input1)] ;NSDictionary *request = @{@"binary": data}; [self.device write:request withSN:0]; |
The data format sent by the MCU to the APP (that is, the data received by the MCU after the bytes array is delivered): FF FF 00 0D 03 16 00 00 05 11 22 33 44 55 66 77 07
Powerwall Battery is a high-tech product developed to meet the requirements of the new home backup power supply. It has the characteristics of integration, miniaturization, light weight, intelligence, standardization, and environmental protection.ZTTEK-48V-100Ah has a lithium (LiFePO4) battery storage capacity of 5kWh, allowing you to stay away from the grid as you like.
Home Solar Energy Storage,Home Solar Energy Storage Battery,Home Energie Storage Batterie,Lithium Battery For Solar Energy Storage
Jiangsu Zhitai New Energy Technology Co.,Ltd , https://www.zt-tek.com