所以我开始使用 ESP8266,这是一段艰难的旅程。每当我认为自己拥有时,它都会失败。我做的最后一件事是安装新固件,突然间我得到了正常的单词和奇怪的字符。
我的代码:
代码:
全选#include
#include
SoftwareSerial esp(2, 3); // RX, TX
void setup()
{
Serial.begin(9600);
esp.begin(115200);
connectoToWifi();
}
void connectoToWifi()
{
String SSIDstring = ("\"WIFI_NAME_HERE\"");
String PASSstring = ("\"WIFI_PASSWORD_HERE\"");
sendData("AT+RST\r\n", 1000, true);
sendData("AT+CWMODE=1\r\n", 500, true);
sendData("AT+CWJAP=" + SSIDstring + "," + PASSstring + "\r\n", 5000, true);
sendData("AT+CIPSTATUS\r\n", 500, true);
sendData("AT+CIFSR\r\n", 500, true);
sendData("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",80\"", 500, true);
}
String sendData(String command, const int
timeout, boolean debug)
{
String response = "";
esp.print(command); // Stuur een "lees" karakter naar de ESP.
long int time = millis();
while ((time + timeout) > millis())
{
while (esp.available())
{
char c = esp.read(); // Lees het volgende karakter.
response += c;
}
}
if (debug)
{
Serial.println(response);
}
return response;
}
void loop()
{
}
在我的串行监视器中,我看到类似这样的内容:
我还尝试了其他 30 条建议,但似乎都没有用。一些不断回来的:- 闪烁它(做了 6 次)- 改变 esp 的波特率(非常受欢迎)- 检查连接- 重置它,闪烁它,改变波特率我在这里错过了什么?