# Sending sensor value from ESP32 to website using JSON POST issue

**URL:** <https://forum.arduino.cc/t/sending-sensor-value-from-esp32-to-website-using-json-post-issue/1379665>\
**Category:** Networking, Protocols, and Devices\
**Created:** [May 7, 2025, 7:41am UTC](https://forum.arduino.cc/t/sending-sensor-value-from-esp32-to-website-using-json-post-issue/1379665 "2025-05-07T07:41:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![adrianaryp](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@adrianaryp](https://forum.arduino.cc/u/adrianaryp)\
**Post date:** [May 7, 2025, 7:41am UTC](https://forum.arduino.cc/t/sending-sensor-value-from-esp32-to-website-using-json-post-issue/1379665/1 "2025-05-07T07:41:18Z")

</div>

hello everyone, so what im trying to do here is sending data to a hosted dashboard website using JSON POST, the ESP32 is done sending the data (because http code is showing 200 which mean the data is successfully sended) but the issue is the website didn't receive the data properly, below are part of my ESP32 code and php code i can provide

```arduino
..........................................................
//esp32
  //HTTP server (websocket)
  if (useWebsocket) {
    server.on("/flow", handleFlowData);
    server.begin();
  }
} 

void loop() {
  if (useWebsocket) {
    server.handleClient();
  }

  flowRate = random(1,70) / 10.0;
  totalWater += flowRate / 60.0 * 2.0;

  sendToDashboard();
  delay(2000);
}

void sendToDashboard() {
  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("Wifi Disconnected");
    return;
  }

  DynamicJsonDocument doc(128);
  doc["flow"] = flowRate;
  doc["total"] = totalWater;
  String jsonPayLoad;
  serializeJson(doc, jsonPayLoad);

  if (!useWebsocket) {
    HTTPClient http;
    http.begin(serverUrl);
    http.addHeader("Content-type", "application/json");
    Serial.println("Sending: " + jsonPayLoad);

    int httpCode = http.POST(jsonPayLoad);
    if (httpCode > 0) {
      Serial.printf("HTTP Sent: %d\n", httpCode);
    } else {
      Serial.printf("HTTP Error: %d\n", http.errorToString(httpCode).c_str());
    }
    http.end();
  }
  else {
    Serial.println("Websocket Data: " + jsonPayLoad);
  }
}

void handleFlowData(){
  DynamicJsonDocument doc(128);
  doc["flow"] = flowRate;
  doc["total"] = totalWater;
  String jsonPayLoad;
  serializeJson(doc, jsonPayLoad);

  server.send(200, "application/json", jsonPayLoad);
  
}

```

* * *

```arduino

//api php code for the website
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json");

$data = json_decode(file_get_contents('php://input'), true);

if (!isset($data['flow']) || !isset($data['total'])) {
    http_response_code(400);
    die(json_encode(["error" => "Invalid data"]));
}

file_put_contents('sensor_data.json', json_encode($data));

echo json_encode(["status" => "success"]);
?>

```

"$data = json\_decode(file\_get\_contents('php://input'), true); "is this part of my php code wrong? or do i miss something?

---

<div class="post-metadata">

**Author:** ![AresXT](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/aresxt/32/1201192_2.png) [@AresXT](https://forum.arduino.cc/u/AresXT)\
**Post date:** [May 7, 2025, 12:22pm UTC](https://forum.arduino.cc/t/sending-sensor-value-from-esp32-to-website-using-json-post-issue/1379665/2 "2025-05-07T12:22:20Z")

</div>

sry i dont know much about php but you can use postman to verify something like in postman in post api you can test your api .if it works and if you are receiving the data which means you need to look for the php part. in post man use post method **\< ESP32IP \>/flow**.if you receive the data in json there you can freely check the php code

Note : Make sure ESP32 and your PC are in same network

---

<div class="post-metadata">

**Author:** ![AresXT](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/aresxt/32/1201192_2.png) [@AresXT](https://forum.arduino.cc/u/AresXT)\
**Post date:** [May 7, 2025, 12:32pm UTC](https://forum.arduino.cc/t/sending-sensor-value-from-esp32-to-website-using-json-post-issue/1379665/3 "2025-05-07T12:32:48Z")

</div>

I have some doubts now .Where are you sending the data . Are you trying to send data from ESP32 to website . Also where is the website hosted in ESP32 or external

---

<div class="post-metadata">

**Author:** ![adrianaryp](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@adrianaryp](https://forum.arduino.cc/u/adrianaryp)\
**Post date:** [May 8, 2025, 4:00am UTC](https://forum.arduino.cc/t/sending-sensor-value-from-esp32-to-website-using-json-post-issue/1379665/4 "2025-05-08T04:00:09Z")

</div>

yes... i also considering this method after several failure

---

<div class="post-metadata">

**Author:** ![adrianaryp](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@adrianaryp](https://forum.arduino.cc/u/adrianaryp)\
**Post date:** [May 8, 2025, 4:01am UTC](https://forum.arduino.cc/t/sending-sensor-value-from-esp32-to-website-using-json-post-issue/1379665/5 "2025-05-08T04:01:56Z")

</div>

the website hosted in free domain (infinityfree). and yes, im trying to send data from ESP32 to the website.

---

<div class="post-metadata">

**Author:** ![AresXT](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/aresxt/32/1201192_2.png) [@AresXT](https://forum.arduino.cc/u/AresXT)\
**Post date:** [May 8, 2025, 4:07am UTC](https://forum.arduino.cc/t/sending-sensor-value-from-esp32-to-website-using-json-post-issue/1379665/6 "2025-05-08T04:07:45Z")

</div>

If you have to send data from esp32 to your hosted website its kind of tricky one .Since esp32 is local hosted it is only accessible in your local network or you port forward it if you have static ip from your service provider. I 'll suggest if you can host API or websocket or any other medium you can make esp32 as client and can connect to the website and feed their data but as ESP32 as server is kind trouble one .

Can you tell me what you are trying to accomplish may be i can give you some alternative ideas

---

<div class="post-metadata">

**Author:** ![adrianaryp](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@adrianaryp](https://forum.arduino.cc/u/adrianaryp)\
**Post date:** [May 8, 2025, 4:30am UTC](https://forum.arduino.cc/t/sending-sensor-value-from-esp32-to-website-using-json-post-issue/1379665/7 "2025-05-08T04:30:46Z")

</div>

I really appreciate you for answering very quickly, I actually manage to find the main problem after asking several colleague. turn out the issue is because of hosting security problem, infinityfree only support javascript based communication, Which explain why my esp cant reach out the website. Solved the problem after change the hosting to render platform.

Again thank you so much for considering to help my problem.

---

<div class="post-metadata">

**Author:** ![rag12](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/rag12/32/1126458_2.png) [@rag12](https://forum.arduino.cc/u/rag12)\
**Post date:** [May 9, 2025, 4:00pm UTC](https://forum.arduino.cc/t/sending-sensor-value-from-esp32-to-website-using-json-post-issue/1379665/8 "2025-05-09T16:00:24Z")

</div>

If relevant to you, there’s an effortless way to build an ESP32 device dashboard using the open source Mongoose Library and their Mongoose Wizard. They provide a step-by-step tutorial along with a short demo video:  
[https://mongoose.ws/articles/esp32-device-dashboard/](https://mongoose.ws/articles/esp32-device-dashboard/)

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [November 5, 2025, 4:01pm UTC](https://forum.arduino.cc/t/sending-sensor-value-from-esp32-to-website-using-json-post-issue/1379665/9 "2025-11-05T16:01:13Z")

</div>

Closed on November 5, 2025, 4:01pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
