Trying to Upload Data to Server Using ESP32

Posts: 2
Joined: Sun Aug 05, 2018 4:48 am

Trying to Upload Data to Server Using ESP32

Postby nnnayeem » Sun Aug 05, 2018 4:59 am

Hello Everyone. I am trying to send post request to a specific url using esp32 arduino core. But every time I run the code It returns 200.

In the backend I am trying to get the data from post request sent by esp32. But the value return null for every request. I tested the backend using postman to find out if there is any wrong and I found out that data is uploading successfully using postman.

But the same code is not working for esp32. In arduino ide I wrote the following code:

Code: Select all

#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "xxxxx";
const char* password =  "xxxxxxx";
#define LED_BUILTIN 2
void setup() {
  delay(4000);   //Delay needed before calling the WiFi.begin
  WiFi.begin(ssid, password); 
  while (WiFi.status() != WL_CONNECTED) { //Check for the connection
    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("");  //Specify destination for HTTP request
   http.addHeader("Content-Type", "application/json");     
   int httpResponseCode = http.POST("{\"floor\":\"22\",\"switch\":\"7\",\"status\":\"1\"}");
    String response = http.getString();                       //Get the response to the request
    Serial.println(httpResponseCode);   //Print return code
    Serial.println(WiFi.localIP());//Print request answer
    Serial.print("Error on sending POST: ");
   http.end();  //Free resources
    Serial.println("Error in WiFi connection");   
  delay(1000);  //Send a request every 10 seconds

In the backend I am using laravel 5.5. And my code:

Code: Select all

public function postData(Request $request){
        $data = json_decode(array_first($request->all()),true);
        $floor  =$data['floor'];
        $switch =$data['switch'];
        $status =$data['status'];
        $p = ['floor'=>$floor,'switch'=>$switch,'status'=>$status];
        $p = serialize($p);
        DB::insert('insert into arduino (body) values (?)', [$p]);
        return $status;


Posts: 3461
Joined: Thu Nov 26, 2015 4:08 am

Re: Trying to Upload Data to Server Using ESP32

Postby ESP_Sprite » Sun Aug 05, 2018 5:51 am

Moved to the Arduino subforum.

Who is online

Users browsing this forum: Baidu [Spider], gagga11 and 11 guests