/*
  AT Firmware simulation example

  Use the serial monitor to interface with the AT firmware. For instance, to scan for WiFi:

AT+CWMODE=1
AT+CWLAP

  Connect to WiFi:

AT+CWJAP="Wokwi-GUEST",

  Show the current IP address:

AT+CIFSR

  Show firmware version

AT+GMR

  To show list list of available commands:

AT+CMD?

*/

int incomingByte = 0;

void ClearBuffer(int dly)
{
  for(int i= 0; i < dly; i++)
  {
    while(Serial1.available() > 0)
    {
      incomingByte = Serial1.read();
      Serial.write(incomingByte);
    }
    delay(1);
  }
}
void SendATCmd(String str, int dly)
{
  Serial1.println(str);
  ClearBuffer(dly);
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Welcome to the AT Playground!");
  Serial.println("-----------------------------");
  Serial1.begin(115200);
  Serial.println("Start Serial 1");

  delay(1000);
  Serial.println("Send AT commands");
  SendATCmd("AT+CWMODE=1", 500);
  //SendATCmd("AT+CWLAP", 2000);
  SendATCmd("AT+CWJAP=\"Wokwi-GUEST\",", 8000);
  //SendATCmd("AT+CIFSR", 2000);

  String server = "v-p.bnr.la";
  String content = "api_key=tPmAT5Ab3j7F9&sensor=DHT11&location=Wokwi&value1=19.77&value2=39.95&value3=1025.56";
  int    at_dly = 100;

  // send POST request
  // .\curl -v -d 'api_key=tPmAT5Ab3j7F9&sensor=curlBME&location=G28 Office&value1=19.77&value2=39.95&value3=1025.56'
  //              http://v-p.bnr.la/~micros/insert.php
  // results: http://v-p.bnr.la/~micros/eds_data_display.php

  // AT+HTTPCLIENT=3,0,"http://v-p.bnr.la/~micros/insert.php",,,1,
  //               "api_key=tPmAT5Ab3j7F9&sensor=DHT11&location=Wokwi&value1=19.77&value2=39.95&value3=1025.56"

  /*SendATCmd("AT+HTTPCLIENT=3,0,\"http://v-p.bnr.la/~micros/insert.php\",,,1,"
            "\"api_key=tPmAT5Ab3j7F9&sensor=DHT11&location=Wokwi&value1=19.77&value2=39.95&value3=1025.56\"",
            1000);
  */

  // connect via TCP
  SendATCmd("AT+CIPMUX=0", 500);
  SendATCmd("AT+CIPSTART=\"TCP\",\"" + server + "\",80", 2000);
  SendATCmd("AT+CIPMODE=1", 500);

  // Make a HTTP request
  SendATCmd("AT+CIPSEND", 1000);
  SendATCmd("POST /~micros/insert.php HTTP/1.1", at_dly);
  SendATCmd("Host: " + server, at_dly);
  SendATCmd("Connection: keep-alive", at_dly);
  SendATCmd("Accept: */*", at_dly);
  SendATCmd("Content-Length: " + String(content.length()), at_dly);
  SendATCmd("Content-Type: application/x-www-form-urlencoded", at_dly);
  SendATCmd("", at_dly);
  SendATCmd(content, at_dly);
  Serial1.print("+++");
  // read and discard response
  ClearBuffer(2000);

  // disconnect
  SendATCmd("AT+CIPCLOSE", 1000);
 }

void loop() {
  // put your main code here, to run repeatedly:
  if(Serial1.available() > 0)
  {
    incomingByte = Serial1.read();
    Serial.write(incomingByte);
  }
}
Loading
esp-01