我是物联网的新手。我正在做一个项目,其中包括收集天气信息并将数据发送到 Thingspeak。我努力将ESP8266连接到Arduino Uno。最后它响应串行监视器中的 AT 命令。但是,当我将这些命令完全写入文件并尝试将其上传到 Arduino 时,我收到了错误消息。
#include <SoftwareSerial.h>
#define DEBUG true
#define RX 0
#define TX 1
String TCP="TCP";
String HOST = "api.thingspeak.com";
String PORT = "80";
String AP = "Phani";
String PASS = "Nani8125297382";
String API = "M5VZGOK12OC13E7G";
String field = "field1";
int countTrueCommand;
int countTimeCommand;
boolean found = false;
int valSensor = 1;
SoftwareSerial esp8266(RX,TX);
void setup() {
Serial.begin(9600);
esp8266.begin(115200);
sendCommand("AT",5,"OK");
sendCommand("AT+CWMODE=1",5,"OK");
sendCommand("AT+CWJAP=""+ AP +"",""+ PASS +""",15,"OK");
countTrueCommand = 0;
}
void loop() {
String getData = "GET /update?api_key="+ API +"&"+ field +"="+String(valSensor);
switch(countTrueCommand) {
case 0: sendCommand("AT",5,"OK");break;
case 1: sendCommand("AT+RST",10,"invalid");break;
case 2: sendCommand("AT+CIPMUX=1",5,"OK"); break;
case 3: sendCommand("AT+CIPSTART=0,"+TCP+","+ HOST +","+ PORT,15,"OK"); break;
case 4: sendCommand("AT+CIPSEND=0," +String(getData.length()+4),4,">"); break;
case 5: esp8266.println(getData);delay(1500);countTrueCommand++; break;
case 6: sendCommand("AT+CIPCLOSE=0",5,"OK"); break;
case 7:
Serial.println(valSensor);
Serial.print(getData);
Serial.print(",");
Serial.println(getData.length());
valSensor = random(100000); // random value, change with sensor value if using sensor
countTrueCommand = 0;
delay(10000);
break;
}
}
void sendCommand(String command, int maxTime, char readReplay[]) {
Serial.print(countTrueCommand);
Serial.print(". at command => ");
Serial.print(command);
Serial.print(" ");
while(countTimeCommand < (maxTime*1))
{
esp8266.println(command);//at+cipsend
if(esp8266.find(readReplay))//ok
{
found = true;
break;
}
countTimeCommand++;
}
if(found == true)
{
Serial.println("OYI");
countTrueCommand++;
countTimeCommand = 0;
}
if(found == false)
{
Serial.println("Fail");
countTrueCommand = 0;
countTimeCommand = 0;
}
found = false;
}
我收到的错误是:
avrdude: Version 6.3-20171130
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"
Using Port : COM6
Using Programmer : arduino
Overriding Baud Rate : 115200
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x45
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xfc
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x45
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xfc
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x45
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xfc
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x45
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xfc
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x8a
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xfc
avrdude done. Thank you.
An error occurred while uploading the sketch
我不明白该怎么做。谁能帮我解决这个问题。