27,508
社区成员




环境: arduino + NBIOT BC260 , 用arduinoIDE开发
StringBuilder<512> strBuilder;
strBuilder.append("AT+QMTCONN=0,");
strBuilder.append(clientId);
strBuilder.append(",");
strBuilder.append(username);
strBuilder.append(",");
strBuilder.append(passwd);
String t_str = strBuilder.toString();
Serial.println(t_str);
delay(1000);
Serial.println(t_str.substring(0,128));
delay(100);
Serial.println(t_str.substring(0,90));
delay(100);
bool isOK = isConnectNBIOT(t_str, "OK");
bool isMqttOk = isConnectNBIOT("AT+QMTCONN=0," + String(clientId), "+QMTCONN: 0,0,0");
}
//带返回真假的AT命令调用函数,如: connectNBIOT("AT+QMTCONN", "+QMTCONN: 0,0,0");
bool isConnectNBIOT(String cmd, char *res) {
while (1) {
cmd.trim(); // 去除 cmd 字符串中的空格
if (cmd.length() <= 0) return;
Serial.println(SERIAL_OUT_MAX_LEN);
int length = cmd.length();
for (int i = 0; i < length; i += SERIAL_OUT_MAX_LEN) {
if (i + SERIAL_OUT_MAX_LEN < length) {
Serial.print(cmd.substring(i, i + SERIAL_OUT_MAX_LEN));
} else {
Serial.println(cmd.substring(i));
}
}
String response = "";
while (Serial.available()) {
//Serial.println("进入while (Serial.available() > 0) 循环");
response += (char)Serial.read();
}
if (response.indexOf(res) != -1) {
//Serial.println("MQTT Connected successfully!");
return true;
} else {
Serial.print(cmd);
Serial.println(" Return ERROR! isConnectNBIOT()");
}
delay(1000);
}
return false;
}
一、我尝试修改Arduino串口缓冲区大小
好不容易在C:\Users\HuaWei\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino找到HardwareSerial.cpp和HardwareSerial.h, 我用的硬串口。打开HardwareSerial.h在开头修改如下代码,有反应但没效果。说明HardwareSerial.h,这个文件是对的,但没效果。
#define SERIAL_RX_BUFFER_SIZE 192 // 接收缓冲区
#define SERIAL_TX_BUFFER_SIZE 192 // 发送缓冲区
//#if !defined(SERIAL_TX_BUFFER_SIZE)
//#if ((RAMEND - RAMSTART) < 1023)
//#define SERIAL_TX_BUFFER_SIZE 64
//#else
//#define SERIAL_TX_BUFFER_SIZE 128
//#endif
//#endif
//#if !defined(SERIAL_RX_BUFFER_SIZE)
//#if ((RAMEND - RAMSTART) < 1023)
//#define SERIAL_RX_BUFFER_SIZE 64
//#else
//#define SERIAL_RX_BUFFER_SIZE 128
//#endif
//#endif
怎么解决,谁有好的办法?
我要调用AT命令,命令不长不行