我正在使用连接到Dragino NB-IoT LTE Bg96的Arduino Nano BLE33。我正在尝试读取https get调用的回复。get调用成功了,为了读取它,我向BG96发送了AT命令。然后它将其发送到Uart,然后我尝试在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] = '\0';
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:
它应该是:
发布于 2021-04-26 09:47:31
由于错误发生在某个字节之后,它通常意味着某种溢出。您还没有展示完整的代码,响应数组(或ARRAYSIZE,因为您正在使用memset清除它)的大小是多少。您的响应索引最有可能导致越界访问
https://stackoverflow.com/questions/67196576
复制相似问题