Unable to send data for every second using POST method. ( ESP32 - Arduino)

mahesh_embd
Posts: 1
Joined: Tue Jan 05, 2021 11:49 am

Unable to send data for every second using POST method. ( ESP32 - Arduino)

Postby mahesh_embd » 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.
  1. #include <WiFi.h>
  2. #include <HTTPClient.h>
  3.  
  4. const char* ssid = "D-Link_1";
  5. const char* password =  "12345678";
  6.  
  7. void setup() {
  8.  
  9.   Serial.begin(115200);
  10.   delay(4000);   //Delay needed before calling the WiFi.begin
  11.  
  12.   WiFi.begin(ssid, password);
  13.  
  14.   while (WiFi.status() != WL_CONNECTED) { //Check for the connection
  15.     delay(1000);
  16.     Serial.println("Connecting to WiFi..");
  17.   }
  18.  
  19.   Serial.println("Connected to the WiFi network");
  20.  
  21. }
  22.  
  23. void loop() {
  24.  
  25.   if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
  26.  
  27.     HTTPClient http;
  28.  
  29.     http.begin("http://192.168.0.103:9002/data");  //Specify destination for HTTP request
  30.     http.addHeader("Content-Type", "application/json");             //Specify content-type header
  31.  
  32.     int httpResponseCode = http.POST("[{\"x\": 1, \"x1\": 5000, \"x2\": 3, \"x3\": 5, \"x4\": 6, \"x5\": 7}]");   //Send the actual POST request
  33.  
  34.     String response = http.getString();                       //Get the response to the request
  35.     Serial.println(httpResponseCode);   //Print return code
  36.     Serial.println(response);           //Print request answer
  37.     http.end();  //Free resources
  38.  
  39.   } else {
  40.  
  41.     Serial.println("Error in WiFi connection");
  42.  
  43.   }
  44.  
  45. //  delay(10);  //Send a request every 10 seconds
  46.  
  47. }

Who is online

Users browsing this forum: Bing [Bot] and 61 guests