But if I upload a blank sketch I can scan, connect ect. ect. to a Wifi network via AT commands... but this code doesn't do anything. I go into the Serial Monitor and no serial data is displayed ever... can't quite figure it out
I've blanked out my SSID/Password but other than that its the exact code.
Thanks!
#include <WiFiEsp.h>
#include <WiFiEspClient.h>
#include <WiFiEspServer.h>
#include <WiFiEspUdp.h>
const char* ssid  = "xxx";
const char* password = "xxx";
void setup() {
 Serial.begin(115200);
 delay(10);
 // We start by connecting to a WiFi network
 Serial.println();
 Serial.println();
 Serial.print("Connecting to ");
 Serial.println(ssid);
Â
 WiFi.begin(ssid, password);
Â
 while (WiFi.status() != WL_CONNECTED) {
  delay(500);
  Serial.print(".");
 }
 Serial.println("");
 Serial.println("WiFi connected");Â
 Serial.println("IP address: ");
 Serial.println(WiFi.localIP());
}
void loop() {
}
I did, I imagine if I didn't I wouldn't be able to see the data via the Serial Monitor when using AT commands right? but either way I have my SM as: Both NL & CR / 115200
RDaugherty:
But if I upload a blank sketch I can scan, connect ect. ect. to a Wifi network via AT commands.
The Arduino/ESP8266 connections for doing that are the reverse of those needed to use WiFiESP (RX-RX, TX-TX for the former vs. RX-TX, TX-RX for the latter).
pert:
Which board are you running the WiFiEsp code on?
The Arduino/ESP8266 connections for doing that are the reverse of those needed to use WiFiESP (RX-RX, TX-TX for the former vs. RX-TX, TX-RX for the latter).
It is an Uno (Tested on both 3.3V and 5V rail)
That makes sense because I realized later on that if I reverse the header for the RX/TX I get this;
"Conne
"Connecting To: xxxxx"
But then nothing else ever happens there. And its disheartening because I should never get that "Conne" its like its resetting? But I never see the power light flicker.
As Juraj pointed out, you need to understand that when you have your ESP8266 connected to pins 0 and 1 of your Uno then you are using Serial to control the ESP8266 via AT commands. The trouble is that we usually use Serial also for sending debug output to the Serial Monitor. The ESP8266 may be confused by this debug output. The problem is made worse because there is debug output to Serial coded into the WiFiESP library, which is left on by default. I found that I needed to turn this off before the library would work with my ESP8266 connected to Serial. To do this you need to open WiFiESP/src/utility/debug.h and change line 32 from:
#define _ESPLOGLEVEL_ 3
to:
#define _ESPLOGLEVEL_ 0
It's unfortunate to lose all debug output when you're first trying to get the system working since you're basically working blind until you can get network communication going, after which you can use that for debug output if you like. I didn't have any problem with that but others are not so lucky with their ESP8266 ventures.
An alternative is to connect the ESP8266 to different pins on your Uno and use SoftwareSerial library. The downside of this is that software serial is not reliable at the default 115200 baud of the ESP8266 AT firmware. You can change the baud rate via an AT command, which would probably be easiest done by sending the command directly from the Serial Monitor, as you were doing before you started on your journey with the WiFiESP libirary.
It looks like you forgot the WiFi.init() call in your sketch. You should add the following line after the Serial.begin() call:
WiFi.init(&Serial);
I recommend starting with the example sketches you will find at File > Examples > WiFiESP until you have gotten everything working correctly to avoid problems like this. Note the example sketches are written assuming you will be using SoftwareSerial library on your Uno but they can be easily adapted if you prefer to stick with the connection on Serial.
pert:
As Juraj pointed out, you need to understand that when you have your ESP8266 connected to pins 0 and 1 of your Uno then you are using Serial to control the ESP8266 via AT commands. The trouble is that we usually use Serial also for sending debug output to the Serial Monitor. The ESP8266 may be confused by this debug output. The problem is made worse because there is debug output to Serial coded into the WiFiESP library, which is left on by default. I found that I needed to turn this off before the library would work with my ESP8266 connected to Serial. To do this you need to open WiFiESP/src/utility/debug.h and change line 32 from:
#define _ESPLOGLEVEL_ 3
to:
#define _ESPLOGLEVEL_ 0
It's unfortunate to lose all debug output when you're first trying to get the system working since you're basically working blind until you can get network communication going, after which you can use that for debug output if you like. I didn't have any problem with that but others are not so lucky with their ESP8266 ventures.
An alternative is to connect the ESP8266 to different pins on your Uno and use SoftwareSerial library. The downside of this is that software serial is not reliable at the default 115200 baud of the ESP8266 AT firmware. You can change the baud rate via an AT command, which would probably be easiest done by sending the command directly from the Serial Monitor, as you were doing before you started on your journey with the WiFiESP libirary.
It looks like you forgot the WiFi.init() call in your sketch. You should add the following line after the Serial.begin() call:
WiFi.init(&Serial);
I recommend starting with the example sketches you will find at File > Examples > WiFiESP until you have gotten everything working correctly to avoid problems like this. Note the example sketches are written assuming you will be using SoftwareSerial library on your Uno but they can be easily adapted if you prefer to stick with the connection on Serial.
Bleh, that was the problem, not calling
WiFi.init(&Serial);
I may look into SoftwareSerial (Which is now NewSoftwareSerial, right?)
RDaugherty:
I may look into SoftwareSerial (Which is now NewSoftwareSerial, right?)
There is a library named SoftwareSerial included with the Arduino IDE. It used to be a 3rd party library that I believe was named something like NewSoftwareSerial but was renamed to SoftwareSerial when it was adopted by Arduino, to match the name of their previous software serial library. There are some alternative 3rd party software serial libraries that may be superior to SoftwareSerial, I haven't used any of them so I can't say from personal experience. SoftwareSerial is easy to get started with since it's already installed but of course installing a 3rd party Arduino library is quite simple. https://www.arduino.cc/en/Reference/SoftwareSerial
Hmm, looks like I was mistaken. I'm getting further but still not connecting;
Connecting to MySpectrumWiFi72-2G
[WiFiEsp] Initializing ESP module
AT
AT
AT+RST
ATE0
AT+CWMODE=1
AT+CIPMUX=1
AT+CIPDINFO=1
AT+CWAUTOCONN=0
AT+CWDHCP=1,1
AT+GMR
[WiFiEsp] Initilization successful - 1.5.4
AT+CWJAP_CUR="MySpectrumWiFi72-2G","xxxx"
[WiFiEsp] Failed connecting to MySpectrumWiFi72-2G
AT+CIPSTATUS
Connecting...
Using this code;
#include <WiFiEsp.h>
const char* ssid  = "MySpectrumWiFi72-2G";
const char* password = "xxxx";
void setup() {
 Serial.begin(115200);
 delay(10);
 // We start by connecting to a WiFi network
 Serial.println();
 Serial.println();
 Serial.print("Connecting to ");
 Serial.println(ssid);
 WiFi.init(&Serial);
  WiFi.begin(ssid, password);
Â
 while (WiFi.status() != WL_CONNECTED) {
  delay(500);
  Serial.println("Connecting...");
 }
 Serial.println(WiFi.localIP());
Â
}
void loop() {
}
#include <WiFiEsp.h>
#include "SoftwareSerial.h"
const char* ssid  = "MySpectrumWiFi72-2G";
const char* password = "xxx";
#ifndef HAVE_HWSERIAL1
SoftwareSerial Serial1(6, 7); // RX, TX
#endif
void setup() {
 Serial.begin(115200);
 delay(10);
 // We start by connecting to a WiFi network
 Serial.println();
 Serial.println();
 Serial.print("Connecting to ");
 Serial.println(ssid);
 WiFi.init(&Serial);
  WiFi.begin(ssid, password);
Â
 while (WiFi.status() != WL_CONNECTED) {
  delay(500);
  Serial.println("Connecting...");
 }
 Serial.println(WiFi.localIP());
Â
}
void loop() {
}
I get...
onnecting to MySpectrumWiFi72-2G
[WiFiEsp] Initializing ESP module
AT
[WiFiEsp] >>> TIMEOUT >>>
AT
[WiFiEsp] >>> TIMEOUT >>>
AT
[WiFiEsp] >>> TIMEOUT >>>
AT
[WiFiEsp] >>> TIMEOUT >>>
AT
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] Cannot initialize ESP module
AT+CWJAP_CUR="MySpectrumWiFi72-2G","fancygate667"
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] Failed connecting to MySpectrumWiFi72-2G
AT+CIPSTATUS
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] No tag found
Connecting...
but try this code I stole mostly from Martyn Currey
const int LED = 13;
String IncomingString;
#include <SoftwareSerial.h>
SoftwareSerial ESPserial(6, 7); // RX | TX
//int rc = 0;
void setup()
{
 pinMode(LED, OUTPUT);
 Serial.begin(9600);  // communication with the host computer
 //while (!Serial) { ; }
 // Start the software serial for communication with the ESP8266
 ESPserial.begin(115200);
 Serial.println("");
 Serial.println("Remember to to set Both NL & CR in the serial monitor.");
 Serial.println("Ready");
 Serial.println("");
 ESPserial.println("AT+GMR");
 // delay(1000);
 // rc = ESPserial.read();
 // Serial.println(rc);
 // delay(1000);
 // ESPserial.println("AT+CIFSR");
 // delay(1000);
 // ESPserial.println("AT+CIFSR");
}
void loop()
{
 boolean StringReady = false;
 while (ESPserial.available()) {
  IncomingString = ESPserial.readString();
  StringReady = true;
  if (StringReady) {
   Serial.println("Received String: " + IncomingString);
   if (IncomingString.indexOf("CIFSR") != -1) {
    digitalWrite(LED, HIGH);
    Serial.println(IncomingString);
   }
   if (IncomingString.indexOf("GMR") != -1) {
    digitalWrite(LED, LOW);
   }
  }
 }
 // listen for communication from the ESP8266 and then write it to the serial monitor
 if ( ESPserial.available() ) {
  Serial.write( ESPserial.read() );
 }
 // listen for user input and send it to the ESP8266
 if ( Serial.available() )   {
  ESPserial.write( Serial.read() );
 }
}
include the LED for debugging, then change AT+CIFSR to AT+CWJAP="SSID","password"
and again move Rx and Tx The \ backslashes necessary
EDIT: I used String variables, I know senior members say "NO STRING VARIABLES", but it works
or, better yet, ignore lunatic ravings (it's really hard to troubleshoot on the forum)
// Basic serial communication with ESP8266
// Uses serial monitor for communication with ESP8266
//
//Â Pins
//Â Arduino pin 2 (RX) to ESP8266 TX
//Â Arduino pin 3 to voltage divider then to ESP8266 RX
//Â Connect GND from the Arduiono to GND on the ESP8266
//Â Pull ESP8266 CH_PD HIGH
//
// When a command is entered in to the serial monitor on the computer
// the Arduino will relay it to the ESP8266
//
#include <SoftwareSerial.h>
SoftwareSerial ESPserial(2, 3); // RX | TX
void setup()
{
  Serial.begin(9600);  // communication with the host computer
  //while (!Serial) { ; }
  // Start the software serial for communication with the ESP8266
  ESPserial.begin(9600);Â
  Serial.println("");
  Serial.println("Remember to to set Both NL & CR in the serial monitor.");
  Serial.println("Ready");
  Serial.println(""); Â
}
void loop()
{
  // listen for communication from the ESP8266 and then write it to the serial monitor
  if ( ESPserial.available() ) { Serial.write( ESPserial.read() ); }
  // listen for user input and send it to the ESP8266
  if ( Serial.available() )   { ESPserial.write( Serial.read() ); }