> void sendATCommand(const char *command, int delayTime) {
> Serial.print("Sending: ");
> Serial.println(command);
> ec200u.println(command);
> delay(delayTime);
> Serial.println("Response:");
> while (ec200u.available()) {
> Serial.write(ec200u.read());
> }
> Serial.println("\n---------------------------\n");
> }
>
> void setup() {
> Serial.begin(115200);
> ec200u.begin(115200, SERIAL_8N1, RXD2, TXD2);
> delay(2000);
>
> sendATCommand("AT+QIACT?", 2000); // Check if the module is connected to the internet
>
> sendATCommand("AT+QHTTPURL=62,80", 2000); // Set URL length
> delay(1000);
> sendATCommand("URL", 2000); // Send URL
>
> sendATCommand("AT+QHTTPPOST=164,80,80", 2000); // Prepare for HTTP POST
> delay(1000);
>
> String postData = "POST /api/v1/GR65NXZ5XGqiVE5e8CCC/telemetry HTTP/1.1\r\n";
> postData += "Host: http://thingsboard.cloud\r\n";
> postData += "Content-Type: application/json\r\n";
> postData += "Accept: */*\r\n";
> postData += "Content-Length: 16\r\n\r\n"; // Proper blank line before JSON data
> postData += "{temperature:24}";
>
> Serial.println("Sending POST Data...");
> Serial.println(postData); // Print POST data in Serial Monitor
>
> ec200u.print(postData);
> delay(5000);
>
> Serial.println("Response:");
> while (ec200u.available()) {
> Serial.write(ec200u.read());
> }
> Serial.println("\n---------------------------\n");
> }
>
> void loop() {
> }
> THIS IS MY CODE AND
>
>
> AT+QIACT?
>
> +QIACT: 1,1,1,"10.172.77.133"
>
> OK
>
> ---------------------------
>
> Sending: AT+QHTTPURL=62,80
>
> Response:
>
> AT+QHTTPURL=62,80
>
> CONNECT
>
> ---------------------------
>
> Sending: http://thingsboard.cloud/api/v1/GR65NXZ5XGqiVE5e8CCC/telemetry
>
> Response:
>
> OK
>
> ---------------------------
>
> Sending: AT+QHTTPPOST=164,80,80
>
> Response:
>
> AT+QHTTPPOST=164,80,80
>
> CONNECT
>
> ---------------------------
>
> Sending POST Data...
>
> POST /api/v1/GR65NXZ5XGqiVE5e8CCC/telemetry HTTP/1.1
>
> Host: http://thingsboard.cloud
>
> Content-Type: application/json
>
> Accept: */*
>
> Content-Length: 16
>
> {temperature:24}
>
> Response:
>
> OK
>
> +QHTTPPOST: 0,400
>
> ---------------------------
pls add
AT+QHTTPCFG=“requestheader”,1
POST data such as
POST /api/v1/GR65NXZ5XGqiVE5e8CCC/telemetry HTTP/1.1
Host: http://thingsboard.cloud
Content-Type: application/json
Accept: /
Content-Length: 16
**you need to add \r\n
{temperature:24}
#include <HardwareSerial.h>
#define RXD2 12 // EC200U RX pin connected to ESP32 TX
#define TXD2 13 // EC200U TX pin connected to ESP32 RX
HardwareSerial ec200u(2);
void sendATCommand(const char *command, int delayTime) {
Serial.print("Sending: ");
Serial.println(command);
ec200u.println(command);
delay(delayTime);
Serial.println("Response:");
while (ec200u.available()) {
Serial.write(ec200u.read());
}
Serial.println("\n---------------------------\n");
}
void readResponse(int timeout) {
long int time = millis();
while ((millis() - time) < timeout) {
while (ec200u.available()) {
char c = ec200u.read();
Serial.write(c);
}
}
Serial.println("\n---------------------------\n");
}
void setup() {
Serial.begin(115200);
ec200u.begin(115200, SERIAL_8N1, RXD2, TXD2);
delay(2000);
sendATCommand("AT+QIACT?", 2000); // Check if the module is connected to the internet
sendATCommand("AT+QHTTPCFG=\"requestheader\",1", 2000); // Enable request header
sendATCommand("AT+QHTTPURL=62,80", 2000); // Set URL length
delay(1000);
sendATCommand("http://thingsboard.cloud/api/v1/GR65NXZ5XGqiVE5e8CCC/telemetry", 2000); // Send URL
sendATCommand("AT+QHTTPPOST=167,80,80", 2000); // Prepare for HTTP POST
delay(1000);
String postData = "POST /api/v1/GR65NXZ5XGqiVE5e8CCC/telemetry HTTP/1.1\r\n";
postData += "Host: http://thingsboard.cloud\r\n"; // Fixed host format
postData += "Content-Type: application/json\r\n";
postData += "Accept: /\r\n";
postData += "Content-Length: 18\r\n\r\n"; // Proper blank line before JSON data
postData += "{\"temperature\":24}";
Serial.println("Sending POST Data...");
Serial.println(postData); // Print post data to serial monitor
ec200u.print(postData);
delay(1000);
ec200u.write(0x1A); // Send Ctrl+Z to indicate end of data
delay(5000);
Serial.println("Response:");
readResponse(5000); // Improved response reading
// Read HTTP response
}
void loop() {
}
above is my program updated one and following is the result i started getting character length in response but still 400 error is their
can you please run if it’s working for you or not.
Sending: AT+QIACT?
Response:
AT+QIACT?
+QIACT: 1,1,1,“10.221.167.160”
OK
Sending: AT+QHTTPCFG=“requestheader”,1
Response:
AT+QHTTPCFG=“requestheader”,1
OK
Sending: AT+QHTTPURL=62,80
Response:
AT+QHTTPURL=62,80
CONNECT
Sending: http://thingsboard.cloud/api/v1/GR65NXZ5XGqiVE5e8CCC/telemetry
Response:
OK
Sending: AT+QHTTPPOST=167,80,80
Response:
AT+QHTTPPOST=167,80,80
CONNECT
Sending POST Data…
POST /api/v1/GR65NXZ5XGqiVE5e8CCC/telemetry HTTP/1.1
Host: http://thingsboard.cloud
Content-Type: application/json
Accept: /
Content-Length: 18
{"temperature":24}
Response:
OK
+QHTTPPOST: 0,400,435