0

I'm working on a Arduino project found online but I'm having trouble with the configuration of the wifi module. Im using a Az Delivery ESP8266 wifi module and the code I have written is the following

#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();
}

I get no error on running and the code compiles but when I open the serial monitor I see that the wifi module fails the first cycle and prints module ERROR.

What am I missing?

2
  • Monitor as a SoftwareSerial instance? What exactly the ERROR? As far as I can see you never read anything from the monitor. Commented Oct 23, 2020 at 15:58
  • @hcheung there is no compile error. But the serial monitor of Arduino says "ESP8266 module ERROR" which is the message of my if cycle if the things go wrong Commented Oct 23, 2020 at 22:21

1 Answer 1

1
#include <ESP8266WiFi.h>
const char* ssid = "";                //replace with our wifi ssid
const char* password = "";         //replace with your wifi password
Serial.print("Connecting to wifi: ");
  Serial.println(ssid);
  
   while (WiFi.status() != WL_CONNECTED) {
     delay(500);
     Serial.print(".");
   }
   Serial.println("");
   Serial.println("WiFi connected");
   Serial.println("IP address: ");
   Serial.println(WiFi.localIP());```
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.