bportaluri / WiFiEsp

Arduino WiFi library for ESP8266 modules
GNU General Public License v3.0
551 stars 210 forks source link

Hardware serial tutorial needed !! Help !! #230

Closed kausikp11 closed 4 months ago

kausikp11 commented 4 months ago

I am trying to use baudrate 115200 to send a data faster this is my arduino code.

/*
 WiFiEsp example: WebClient

 This sketch connects to google website using an ESP8266 module to
 perform a simple web search.

 For more details see: http://yaab-arduino.blogspot.com/p/wifiesp-example-client.html
*/

#include "WiFiEsp.h"

// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(2, 3); // RX, TX
#endif

char ssid[] = "ACT103700825351";            // your network SSID (name)
char pass[] = "25851250";        // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status

char server[] = "arduino.cc";

// 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(&Serial);

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

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

  printWifiStatus();

  Serial1.println();
  Serial1.println("Starting connection to server...");
  // if you get a connection, report back via Serial1
  if (client.connect("192.168.0.104", 8000)) {
    Serial1.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();
    client.println(F("POST /simple_upload/ HTTP/1.1"));
    client.print(F("Host: "));
    client.println(F("192.168.0.104:8000"));
    client.println(F("Connection: close"));
  }
}

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

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

    // do nothing forevermore
    while (true);
  }
}

void printWifiStatus()
{
  // print the SSID of the network you're attached to
  Serial1.print("SSID: ");
  Serial1.println(WiFi.SSID());

  // print your WiFi shield's IP address
  IPAddress ip = WiFi.localIP();
  Serial1.print("IP Address: ");
  Serial1.println(ip);

  // print the received signal strength
  long rssi = WiFi.RSSI();
  Serial1.print("Signal strength (RSSI):");
  Serial1.print(rssi);
  Serial1.println(" dBm");
}

In this the Output at serial port 115200 is as follows

22:08:37.891 -> [WiFiEsp] Initializing ESP module
22:08:37.891 -> AT
22:08:38.919 -> AT
22:08:38.919 -> AT+RST
22:08:41.938 -> ATE0
22:08:41.938 -> AT+CWMODE=1
22:08:42.137 -> AT+CIPMUX=1
22:08:42.137 -> AT+CIPDINFO=1
22:08:42.137 -> AT+CWAUTOCONN=0
22:08:42.137 -> AT+CWDHCP=1,1
22:08:42.336 -> AT+GMR
22:08:42.369 -> [WiFiEsp] Initilization successful - 1.5.4
22:08:42.402 -> AT+CWJAP_CUR="ACT103700825351","25851250"
22:08:47.441 -> [WiFiEsp] Connected to ACT103700825351
22:08:47.475 -> AT+CWJAP?
22:08:47.475 -> AT+CIFSR
22:08:47.508 -> AT+CWJAP?
22:08:47.607 -> [WiFiEsp] Connecting to 192.168.0.104
22:08:47.607 -> AT+CIPSTART=3,"TCP","192.168.0.104",8000
22:08:47.607 -> AT+CIPSTATUS

But on software serial for checking debug serial value I get

22:10:49.179 -> Attempting to connect to WPA SSID: ACT103700825351
22:11:10.299 -> Attempting to connect to WPA SSID: ACT103700825351

Based on the serial output at port 115200, I can see it is connected, but why I am not getting the same in software serial?

Need help to know where I am doing wrong and how to make the code work?

kausikp11 commented 4 months ago

Issue resolved, add a external power supply to arduino. dont use the ftdi supply