Invoke HTTP request using AT Command, but I am getting output as ">" which I am not able to get as why the output is like this:
// #include <SoftwareSerial.h>
SoftwareSerial ESP8266(2, 3);
String Network = "xyz"; String Password = "xyz";
void setup() {
Serial.begin(9600);
ESP8266.begin(115200); ESP8266.println("AT+CIOBAUD=9600"); readESP8266(4000);
ESP8266.begin(9600); InitESP8266(); ConnectToWebsite(); }
void loop() { while(ESP8266.available()) {
Serial.println(ESP8266.readString()); }}
/* Function to initialise ESP8266 */ void InitESP8266() {
ESP8266.println("AT"); readESP8266(2000);
ESP8266.println("AT+CWMODE=3"); //Wifi mode readESP8266(5000);
ESP8266.println("AT+CWJAP=""+ Network + "","" + Password +"""); //connect wifi readESP8266(10000);
ESP8266.println("AT+CIFSR"); // IP adress readESP8266(1000);
ESP8266.println("AT+CIPMUX=1"); // multiple connections readESP8266(1000);
}
/* Function to connect to the server */ void ConnectToWebsite() {
ESP8266.println("AT+CIPSTART=1,"TCP","jsonplaceholder.typicode.com",80"); //connect to website readESP8266(10000);
ESP8266.println("AT+CIPSEND=1,114"); readESP8266(2000);
String httpreq = "GET /posts/1 HTTP/1.1"; // Make a HTTP request: ESP8266.println(httpreq); readESP8266(10000);
readESP8266(5000);
//Serial.println("\r\n"); }
//read and display message void readESP8266(const int timeout) { String reponse = ""; long int time = millis(); while( (time+timeout) > millis()) { while(ESP8266.available()) { char c = ESP8266.read(); reponse+=c; } } Serial.print(reponse);
}#include <SoftwareSerial.h> SoftwareSerial ESP8266(2, 3); String Network = "xyz"; String Password = "xyz"; void setup() { Serial.begin(9600); ESP8266.begin(115200); ESP8266.println("AT+CIOBAUD=9600"); readESP8266(4000); ESP8266.begin(9600); InitESP8266(); ConnectToWebsite(); } void loop() { while(ESP8266.available()) { Serial.println(ESP8266.readString()); } } /* Function to initialise ESP8266 */ void InitESP8266() { ESP8266.println("AT"); readESP8266(2000); ESP8266.println("AT+CWMODE=3"); //Wifi mode readESP8266(5000); ESP8266.println("AT+CWJAP=\""+ Network + "\",\"" + Password +"\""); //connect wifi readESP8266(10000); ESP8266.println("AT+CIFSR"); // IP adress readESP8266(1000); ESP8266.println("AT+CIPMUX=1"); // multiple connections readESP8266(1000); } /* Function to connect to the server */ void ConnectToWebsite() { ESP8266.println("AT+CIPSTART=1,\"TCP\",\"jsonplaceholder.typicode.com\",80"); //connect to website readESP8266(10000); ESP8266.println("AT+CIPSEND=1,114"); readESP8266(2000); String httpreq = "GET /posts/1 HTTP/1.1"; // Make a HTTP request: ESP8266.println(httpreq); readESP8266(10000); readESP8266(5000); //Serial.println("\r\n"); } //read and display message void readESP8266(const int timeout) { String reponse = ""; long int time = millis(); while( (time+timeout) > millis()) { while(ESP8266.available()) { char c = ESP8266.read(); reponse+=c; } } Serial.print(reponse); }````
If I use WIFI ESP then I am getting following error
#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[] = "xyz"; // your network SSID (name) char pass[] = "xyz"; // 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(&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);} }
void printWifiStatus() { // print the SSID of the network you're attached to Serial.print("SSID: "); Serial.println(WiFi.SSID());
// print your WiFi shield's IP address IPAddress ip = WiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip);
// print the received signal strength long rssi = WiFi.RSSI(); Serial.print("Signal strength (RSSI):"); Serial.print(rssi); Serial.println(" dBm"); }
// Emulate Serial1 on pins 6/7 if not present #ifndef HAVE_HWSERIAL1 #include "SoftwareSerial.h" SoftwareSerial Serial1(2, 3); // RX, TX #endif char ssid[] = "xyz"; // your network SSID (name) char pass[] = "xyz"; // 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(&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); } } void printWifiStatus() { // print the SSID of the network you're attached to Serial.print("SSID: "); Serial.println(WiFi.SSID()); // print your WiFi shield's IP address IPAddress ip = WiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip); // print the received signal strength long rssi = WiFi.RSSI(); Serial.print("Signal strength (RSSI):"); Serial.print(rssi); Serial.println(" dBm"); }````
WiFiEsp]````[WiFiEsp] I >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] Initializing ESP module
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] Cannot initialize ESP module
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] No tag found
WiFi shield not present
Attempting to connect to WPA SSID: xyz
[WiFiEsp] >>> TIMEOUT >>>
Please let me know in case you figure out the issue. [WiFiEsp] >>> TIMEOUT >>> [WiFiEsp] >>> TIMEOUT >>> [WiFiEsp] >>> TIMEOUT >>> [WiFiEsp] >>> TIMEOUT >>> [WiFiEsp] Cannot initialize ESP module [WiFiEsp] >>> TIMEOUT >>> [WiFiEsp] No tag found WiFi shield not present Attempting to connect to WPA SSID: xyz [WiFiEsp] >>> TIMEOUT >>>
Please let me know in case you figure out the issue.