Serial.find - printing out response to serial monitor?

Hi all,

Have a bug I’m trying to squash in some code where I’m using an esp8266 to connect to wifi and it’s not working.

Failing at the first hurdle where serial.find is looking for an OK response

  if (Serial.find("OK")) {
    //connect to your wifi network
    bool connected = connectWiFi();
    if (!connected) {
      //failure, need to check your values and try again
      Error();
    }
  } else {
     Serial.println("Failed to connect to wifi");
    Error();
  }

To help error-test this I’d like to understand what is exactly coming back from the serial.find request (ie is it nothing, something else etc)

Can anyone help me tweak my code to print out what it’s reading?

I guess it’s something like Serial.println();

Many thanks in advance!

the find() function does not save what is read from Serial so you will not have access to it. If you want to see what is coming in, you will have to read it and store it in String variable and then you can print that variable and then use the indexOf() function to see if “OK” is in that variable.

You might need to look into the library functions you are using to see what they return. The connectWiFi() function may return a verbose output from what it is connected to, or it may generate the ok based on what it detects in the connection.

You're on the wrong track. Just find out why connectWiFi() is failing. Check your TCP and login credentials. Also load a simple serial passthrough program to issue AT commands manually from the keyboard, to verify the hardware connections and baud rates.

hmm thanks all - TCP/login etc definitely right as this works perfectly when set up with my Arduino Uno, just fails when I'm trying to move it to the ESP8266.

Is there any different libraries I should be including or functions I should be using to run it off the 8266?

I'm pretty sure I'm doing something stupid, it's just picking out the right stupidity from the range I create..... :wink: