Arduino Serial.Available()在255个字节后为false



我正在使用连接到Dragino NB IoT LTE Bg96的Arduino Nano BLE 33。我正在尝试阅读https获取呼叫的回复。get调用成功,为了读取它,我向BG96发送了AT命令。然后它把它发给乌亚特,我试着在arduino上读它。但在255个字符后,它停止了,我在不同的网站上尝试了它(有不同的响应(,但它在255个字后中断。我以前使用uint8_t(用于索引(,所以我认为这是错误的,但在我将其更改为int后,现在仍然会发生这种情况。

我的部分功能:

uint8_t bg96::check_response(char* desired_response){
char character;
int index = 0;
memset(response, 0, ARRAYSIZE);
while (Serial1.available()){
character = Serial1.read();
response[index] = character;
index++;
Serial.print(character);
}
response[index] = '';
Serial.print("index : ");
Serial.println(index);
Serial.print("Response:");
Serial.println(response); 

响应:

+QHTTPGET: 0,200
AT+QHTTPREAD=80
CONNECT
HTTP/1.1 200 OK
Server: nginx/1.14.2
Content-Type: text/plain; charset=UTF-8
Transfer-Encoding: chunked
Vary: Accept-Encoding
X-Request-Id: 616401ed-bb42-43b3-aba9-ab53952b9405
X-Token-Id: d242eb9a-9dc3index : 255
Response:

应该是:

完成HTTPS重新响应

由于错误发生在特定字节之后,通常意味着某种类型的溢出。您还没有显示完整的代码,响应数组的大小是多少(或ARRAYSIZE,因为您正在用memset清除它(。很可能您的响应[索引]会导致的越界访问

相关内容

最新更新