0

I am using WiFiEsp Library, ESP8266-01 Wifi Module, Arduino UNO and Arduino v.1.8.13. ESP Details: AT version:1.2.0.0. SDK version:1.5.4.1(39cb9a32) v1.0.0.

The module is also in AT+CWMODE=1.

My module connection is as follows:

RX: Pin 6

TX: Pin 7

VCC: 3.3V

GND: GND

CH-PD: 3.3V

I have created a wifi hotspot on my phone which I try to connect to using the module, so that I can be able to pass some variables from arduino sensor to my php script which is hosted locally on phpMyadmin.

However, I can not seem to make the connection past connecting to wifi, since it says wifi shield is not present. Even the AT commands dont work.

What could I be doing wrong? Below is my code snippet:

#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif
char ssid[] = "Googz";            // your network SSID (name)
char pass[] = "********";        // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status
char server[] = "localhost/bella/espdata.php";

// Initialize the Ethernet client object
WiFiEspClient client;
void setup(){
  // initialize serial for debugging
  Serial.begin(115200);
  // initialize serial for ESP module
  Serial1.begin(9600);
  // initialize ESP module
  WiFi.init(&Serial1);
  // check for the presence of the shield
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue
    while (true);
  }

  // attempt to connect to WiFi network
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network
    status = WiFi.begin(ssid, pass);
  }

  // you're connected now, so print out the data
  Serial.println("You're connected to the network");
  
  printWifiStatus();

  Serial.println();
  Serial.println("Starting connection to server...");
  // if you get a connection, report back via serial
  if (client.connect(server, 80)) {
    Serial.println("Connected to server");
    // Make a HTTP request
    client.println("GET /asciilogo.txt HTTP/1.1");
    client.println("Host: arduino.cc");
    client.println("Connection: close");
    client.println();
  }
}

void loop()
{
  // if there are incoming bytes available
  // from the server, read them and print them
  while (client.available()) {
    char c = client.read();
    Serial.write(c);
  }

  // if the server's disconnected, stop the client
  if (!client.connected()) {
    Serial.println();
    Serial.println("Disconnecting from server...");
    client.stop();

    // do nothing forevermore
    while (true);
  }
}
  • 1
    Swap your TX and RX pins. TX should connect to RX and RX should connect to TX. – Majenko Aug 2 at 11:20
  • Let me get this, so I should switch from using pins 6 and 7 and use 0 and 1 in arduino right? – Ngugi Kariuki Aug 2 at 11:46
  • No, you should switch from using 6 and 7 to using 7 and 6. The pin you designate as TX should connect to the RX of the ESP-01, not to the TX of the ESP-01. And vise-versa for the pin you designate as RX. – Majenko Aug 2 at 11:51
  • Still hits me with the same error. Even AT commands are not failing. Could it be the IDE version that's the problem? – Ngugi Kariuki Aug 2 at 12:45
  • Is there any other possible possibility of sending variables from Arduino to php local server.? considering I don't access internet since its localhost – Ngugi Kariuki Aug 2 at 12:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.