我的项目需要帮助。 这是我的代码:
void ConexaoServer(){
uint8_t buffer[1024] = {0};
if (wifi.createTCP(HOST_NAME, HOST_PORT)) {
Serial.print("Conexao com o Host OK!\r\n");
} else {
Serial.print("Conexao com o Host com ERRO!\r\n");
}
char *ComandoGET = "GET /teste HTTP/1.1\r\nHost: SmartHome\r\nConnection: close\r\n\r\n";
wifi.send((const uint8_t*)ComandoGET, strlen(ComandoGET));
uint32_t len = wifi.recv(buffer, sizeof(buffer), 10000);
if (len > 0) {
Serial.print("Received:[");
for(uint32_t i = 0; i < len; i++) {
Serial.print((char)buffer[i]);
}
Serial.print("]\r\n\r\n");
}
}
我从Serial
中的Node.js收到Received:[HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 4
ETag: W/"4-wArb1VtkpsN6In8g50pGNw"
Date: Wed, 31 Aug 2016 01:26:41 GMT
Connection: close
Luiz]
但我想收到Received:[Luiz]
。我怎么能这样做?
答案 0 :(得分:1)
您需要找到双换行符(\r\n\r\n
)并在此之后使用字符。
char payload[1024] = "";
char *pl = strstr((char*)buffer, "\r\n\r\n");
if (pl != NULL)
{
strcpy(payload, pl+4);
Serial.println(payload);
}