Please help me to post data from arduino uno to a webpage using wifi(ESP-01) module. I try with AT commands it didn't give the response from my webpage
#include <SoftwareSerial.h>
#include <ArduinoJson.h>
#define DEBUG true
#define RX 10
#define TX 11
String WIFI_SSID = "*****"; // Your WiFi ssid
String PASSWORD = "*****"; // Password
//String DEVICE_SECRET_KEY = "**";
//String PATH = "/v1/events";
//String PORT = "8000";
//String HOST = "http://10.**.***.66:8000/data";
String HOST = "10.**.240.**";
String PATH = "/data";
String PORT = "8000";
String response;
int countTrueCommand;
int countTimeCommand;
boolean found = false;
SoftwareSerial esp8266(RX, TX);
StaticJsonBuffer<200> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
void setup()
{
Serial.begin(115200);
esp8266.begin(115200);
esp8266.println("AT");
Serial.println(esp8266.read());
sendCommandToESP8266("AT", 5, "OK");
sendCommandToESP8266("AT+CWMODE=3", 5, "OK");
sendCommandToESP8266("AT+CWJAP=\"" + WIFI_SSID + "\",\"" + PASSWORD + "\"", 20, "OK");
}
void loop()
{
root["key"] = "sdfsdfsd";
String key;
root.printTo(key);
String postRequest = "POST " + PATH + " HTTP/1.1\r\n" +
"Host: " + HOST + "\r\n" +
"Accept: *" + "/" + "*\r\n" +
"Content-Length: " + key.length() + "\r\n" +
"Content-Type: application/json\r\n"
"\r\n" + key;
Serial.print("pst:" + postRequest);
sendCommandToESP8266("AT+CIPMUX=1", 5, "OK");
sendCommandToESP8266("AT+CIPSTART=0,\"TCP\",\"" + HOST + "\"," + PORT, 15, "OK");
String cipSend = "AT+CIPSEND=0," + String(postRequest.length());//GET /test.php?Data=2\r\nHost:192.168.1.13\r\n\r\n
sendCommandToESP8266(cipSend, 4, ">");
sendData(postRequest);
while (esp8266.available())
{
if (esp8266.find("+IPD,"))
{
// String msg;
esp8266.find("?");
// msg = esp8266.readStringUntil(' ');
response = esp8266.readStringUntil(' ');
Serial.print(response);
Serial.println();
}
}
printResponse;
// sendCommandToESP8266("AT+CIPCLOSE=0", 5, "OK");
}
void sendCommandToESP8266(String command, int maxTime, char readReplay[]) {
Serial.print(countTrueCommand);
Serial.print(". at command => ");
Serial.print(command);
Serial.print(" ");
while (countTimeCommand < (maxTime * 1))
{
esp8266.println(command);
if (esp8266.find(readReplay))
{
found = true;
break;
}
countTimeCommand++;
}
if (found == true)
{
Serial.println("Success");
countTrueCommand++;
countTimeCommand = 0;
}
if (found == false)
{
Serial.println("Fail");
countTrueCommand = 0;
countTimeCommand = 0;
}
found = false;
}
void sendData(String postRequest) {
Serial.println(postRequest);
Serial.println();
esp8266.println(postRequest);
delay(15000);
countTrueCommand++;
}
void printResponse() {
while (esp8266.available()) {
Serial.println();
Serial.println(esp8266.readStringUntil('\n'));
}
}
Please help me to get the response from the webpage using this code.