我使用arduino和wifi盾牌将数据发布到ThingSpeak。我上周有这个工作,但现在我无法连接到ThingSpeak API来发布我的数据。相关功能是:
void sendData(String tsData) {
ESP8266Client client;
client.connect(thingSpeakAddress, 80);
delay(1000);
Serial.print("Attempting to send data...");
if (client.connected())
{
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+writeKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(tsData.length());
client.print("\n\n");
client.println(tsData);
lastConnectionTime = millis();
if (client.connected())
{
Serial.println("Connected to ThingSpeak!");
Serial.println();
Serial.print("Sent data: ");
Serial.println(tsData);
Serial.print("\n");
failedCounter = 0;
}
else
{
failedCounter++;
Serial.println("Connection to ThingSpeak failed");
Serial.println();
Serial.print("Tried to send data: ");
Serial.println(tsData);
Serial.print("\n");
}
}
else
{
failedCounter++;
Serial.println("Connection to ThingSpeak Failed");
Serial.println();
lastConnectionTime = millis();
}
}
然而,我无法连接。每次我得到"与ThingSpeak的连接失败。"为什么我不能连接?有没有更好的方法来解决这个问题?