Unable to send data for every second using POST method. ( ESP32 - Arduino)
Posted: Tue Jan 05, 2021 12:08 pm
Hi,
I am using esp32 for my iot project, in that i have to send the data for every second. Most of the time board is able to send the data to server but some times data is missing for 4 to 5 seconds. ( i am using post method) help me with this regards.
I am using esp32 for my iot project, in that i have to send the data for every second. Most of the time board is able to send the data to server but some times data is missing for 4 to 5 seconds. ( i am using post method) help me with this regards.
- #include <WiFi.h>
- #include <HTTPClient.h>
- const char* ssid = "D-Link_1";
- const char* password = "12345678";
- void setup() {
- Serial.begin(115200);
- delay(4000); //Delay needed before calling the WiFi.begin
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) { //Check for the connection
- delay(1000);
- Serial.println("Connecting to WiFi..");
- }
- Serial.println("Connected to the WiFi network");
- }
- void loop() {
- if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
- HTTPClient http;
- http.begin("http://192.168.0.103:9002/data"); //Specify destination for HTTP request
- http.addHeader("Content-Type", "application/json"); //Specify content-type header
- int httpResponseCode = http.POST("[{\"x\": 1, \"x1\": 5000, \"x2\": 3, \"x3\": 5, \"x4\": 6, \"x5\": 7}]"); //Send the actual POST request
- String response = http.getString(); //Get the response to the request
- Serial.println(httpResponseCode); //Print return code
- Serial.println(response); //Print request answer
- http.end(); //Free resources
- } else {
- Serial.println("Error in WiFi connection");
- }
- // delay(10); //Send a request every 10 seconds
- }