0

我正在处理一个在线找到的 Arduino 项目,但我在配置 wifi 模块时遇到了问题。我使用的是 Az Delivery ESP8266 wifi 模块,我编写的代码如下

#define SSID "SSID" //replace XXXXX by your router SSID
#define PASS "PSW!" //replace YYYYY by your router password

 //communication with wifi module
    monitor.flush();
    monitor.println("AT");
    delay(2000);
    
    if(monitor.find("OK")){
      Serial.println("Communication with ESP8266 module: OK");
    }
    else {
      Serial.println("ESP8266 module ERROR");
    }

  //connect wifi router  
  connectWiFi(); 
     
  Serial.print("Sampling (");
  Serial.print(sampletime_ms/1000);
  Serial.println("s)...");
  
  //initialize timer
  starttime = millis();

}

boolean connectWiFi(){
  Serial.println("Connecting wi-fi...");
  String cmd ="AT+CWMODE=1";
  monitor.println(cmd);
  delay(2000);
  monitor.flush(); //clear buffer
  cmd="AT+CWJAP=\"";
  cmd+=SSID;
  cmd+="\",\"";
  cmd+=PASS;
  cmd+="\"";
  monitor.println(cmd);
  delay(5000);
  
  if(monitor.find("OK")){
    Serial.println("Connection succeeded!");
    return true;
  }else{
    Serial.println("Connection failed!");
    return false;
  }
  Serial.println();
}

我在运行时没有收到错误,并且代码可以编译,但是当我打开串行监视器时,我看到 wifi 模块在第一个周期失败并打印模块错误。

我错过了什么?

4

0 回答 0