如何使用Chirp IO使用超声波正确发送json数组的长字符串?

时间:2019-04-24 06:48:28

标签: react-native payload

我想通过chi io通过超声波发送长字符串。我试图将字符串分成8个字节,并使用for循环发送它,但仅收到最后一部分。如何根据maxPayloadLengt中断字符串并发送完整的字符串?

String identifier = "hello how are you, make a string";

long maxPayloadLength = chirpConnect.maxPayloadLength();

String[] str=SplitStringByByteLength(identifier,"UTF-8",8);
// it will break string into 8 bytes chunks
for(int i=0; i<str.length;i++){ 
    byte[] payload = str[i].getBytes(Charset.forName("UTF-8"));
    if (maxPayloadLength < payload.length) {
         break;
    } else {
       ChirpError error = chirpConnect.send(payload);

       if (error.getCode() > 0) {
               Log.e("ChirpError: ", error.getMessage());
       } else {
               Log.v("ChirpSDK: ", "Sent " + identifier);
       }
   }
}

0 个答案:

没有答案