我想首先发送整个文本到认定其长度和使用AT + CIPSEND = 长度的函数读取一些文本服务器的通数据来这里稍后打开TCP端口。在我的响应数据中添加一些额外的信息之前,一切正常。 我怀疑的字符限制,但无法找到一个理由,即使调试几个小时。Arduino的字符串连接Serial.println()不工作
Serial.println()不显示任何输出,因为它似乎字符串连接是不健康的。问题是文本没有被传递,因此CIPSEND不起作用。相应的代码部分及其输出如下所示。
void sendHTTPResponse(int connectionId, String content) {
Serial.println("SENDHTTPRESPONSE1: " + content);
// build HTTP response
String httpResponse;
String httpHeader;
// HTTP Header
httpHeader = "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=UTF-8\r\n";
httpHeader += "Content-Length: ";
httpHeader += content.length();
httpHeader += "\r\n";
httpHeader += "Connection: close\r\n\r\n";
Serial.println("SENDHTTPRESPONSE2: " + httpHeader);
httpResponse = httpHeader + content + " "; // There is a bug in this code: the last character of "content" is not sent, I cheated by adding this extra space
Serial.println("HTTPRESPONSE3: " + httpResponse);
sendCIPData(connectionId, httpResponse);
}
和串行监视器输出。 HTTPRESPONSE3似乎在某种程度上是空的?
SENDHTTPRESPONSE1: {"data":[{"id":"100"}]}{"data":[{"id":"100"}]}{"data":[{"id":"100"}]}{"data":[{"id":"100"}]}
SENDHTTPRESPONSE2: HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Content-Length: 92
Connection: close
DATA LENGTH:
======================================================
Executing command: AT+CIPSEND=0,0
HTTP/1.1
CoAT+CIPSEND=0,0
在此先感谢。
Arduino是不是C!而你的代码并不适合这么小的设备。将桌面编程技术应用于像Arduino这样的裸机嵌入式设备是一个不错的主意。 – Olaf
你有什么建议?或者请链接一些参考。 – eden
这是没有辅导网站。但是,你为什么不直接发送文本? – Olaf