Things aliyun device end message passthrough setup issues payLoad

Outline

Since the low profile and limited resources, or have equipment requirements for network traffic, not suitable for direct configuration data and JSON things communication platform, the original data can be transparently transmitted things internet. This paper introduces for the document is not set on the device side payLoad, initial use error-prone process of example in conjunction with the official target payLoad introduced.

Test Procedure

1, with reference to official exemplary set test.

2, the physical type defined theme;
_

3, testing and certification

0x00002233441232013fa00000

_

4, the transmitting side payLoad process, noted that the incoming byte [] object, not a String object.

String hexString = "00002233441232013fa00000";
byte[] payLoad = hexToByteArray(hexString);
request.payloadObj = payLoad;
  • hexToByteArray ways:
    /**
     * hex字符串转byte数组
     * @param inHex 待转换的Hex字符串
     * @return  转换后的byte数组结果
     */
    public static byte[] hexToByteArray(String inHex){
        int hexlen = inHex.length();
        byte[] result;
        if (hexlen % 2 == 1){
            //奇数
            hexlen++;
            result = new byte[(hexlen/2)];
            inHex="0"+inHex;
        }else {
            //偶数
            result = new byte[(hexlen/2)];
        }
        int j=0;
        for (int i = 0; i < hexlen; i+=2){
            result[j]=hexToByte(inHex.substring(i,i+2));
            j++;
        }
        return result;
    }

    /**
     * Hex字符串转byte
     * @param inHex 待转换的Hex字符串
     * @return  转换后的byte
     */
    public static byte hexToByte(String inHex) {
        return (byte) Integer.parseInt(inHex, 16);
    }

5, equipment operating status:

_

Reference links

Data analysis uses examples
to convert between Java hexadecimal (Hex) and a byte array

Guess you like

Origin yq.aliyun.com/articles/706989