# How to send a data from PHP Script to node-red dashboard

**URL:** https://discourse.nodered.org/t/how-to-send-a-data-from-php-script-to-node-red-dashboard/51554
**Category:** General
**Tags:** node-red-dashboard
**Created:** [27 September 2021 03:21 UTC](https://discourse.nodered.org/t/how-to-send-a-data-from-php-script-to-node-red-dashboard/51554 "2021-09-27T03:21:46Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![Ghoond](https://avatars.discourse-cdn.com/v4/letter/g/c57346/32.png) [@Ghoond](https://discourse.nodered.org/u/Ghoond)
#### Post date: [27 September 2021 03:21 UTC](https://discourse.nodered.org/t/how-to-send-a-data-from-php-script-to-node-red-dashboard/51554/1 "2021-09-27T03:21:46Z")

</div>

Hi everyone,

So i've been working on a project about IoT, and currently im using arduino for my project, especially ESP32-Cam for monitoring plants. And since im new using Node-Red is there are a way to send a data from PHP Script. I installed my ESP32-Cam with opencv to detect color value, for reference im using [ESP32-CAM Web Server with OpenCV.js: Color Detection and Tracking | Random Nerd Tutorials](https://randomnerdtutorials.com/esp32-cam-opencv-js-color-detection-tracking/) for the color detection. In the code

```auto
let BP = rgbaPlanes.get(2); // SELECTED COLOR PLANE
let GP = rgbaPlanes.get(1);
let RP = rgbaPlanes.get(0);

```

the codes above are for the data of color value, and i want to send it to node-red dashboard.  
If someone who has done a similar project, would you kindly share your knowledge with me and the community.  
Thankyou for your time to reply my question.

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [27 September 2021 08:13 UTC](https://discourse.nodered.org/t/how-to-send-a-data-from-php-script-to-node-red-dashboard/51554/2 "2021-09-27T08:13:59Z")

</div>

Use MQTT to send the data from the arduino to node-red. There is an JSON library you can use. [https://arduinojson.org](https://arduinojson.org) and you should use the [Arduino Client for MQTT](https://pubsubclient.knolleary.net)

Why are you usng a PHP script?

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [27 September 2021 11:28 UTC](https://discourse.nodered.org/t/how-to-send-a-data-from-php-script-to-node-red-dashboard/51554/3 "2021-09-27T11:28:26Z")

</div>

If you really need to keep using PHP, you have a number of options.

The traditional route is to use PHP to provide a REST API that you can query from Node-RED and so pass the data to your Dashboard.

However, you could use MQTT with PHP which would be a good solution. Or you could push data to Node-RED using an HTTP node or even use websockets.

---

<div class="post-metadata">

### Author: ![Ghoond](https://avatars.discourse-cdn.com/v4/letter/g/c57346/32.png) [@Ghoond](https://discourse.nodered.org/u/Ghoond)
#### Post date: [27 September 2021 12:19 UTC](https://discourse.nodered.org/t/how-to-send-a-data-from-php-script-to-node-red-dashboard/51554/4 "2021-09-27T12:19:00Z")

</div>

Oh im sorry, i forgot that im also using MQTT to send the data

---

<div class="post-metadata">

### Author: ![Ghoond](https://avatars.discourse-cdn.com/v4/letter/g/c57346/32.png) [@Ghoond](https://discourse.nodered.org/u/Ghoond)
#### Post date: [27 September 2021 12:20 UTC](https://discourse.nodered.org/t/how-to-send-a-data-from-php-script-to-node-red-dashboard/51554/5 "2021-09-27T12:20:50Z")

</div>

the code above are inside of PHP script sir, the main process are on arduino, but the webcam footage are shown on custom website

---

<div class="post-metadata">

### Author: ![Ghoond](https://avatars.discourse-cdn.com/v4/letter/g/c57346/32.png) [@Ghoond](https://discourse.nodered.org/u/Ghoond)
#### Post date: [27 September 2021 12:42 UTC](https://discourse.nodered.org/t/how-to-send-a-data-from-php-script-to-node-red-dashboard/51554/6 "2021-09-27T12:42:47Z")

</div>

So when using MQTT do i have to send it to the dashboard using the publish.client or something else?

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [27 September 2021 12:49 UTC](https://discourse.nodered.org/t/how-to-send-a-data-from-php-script-to-node-red-dashboard/51554/7 "2021-09-27T12:49:33Z")

</div>

No, you just add an MQTT -in node to your flow and send the output to your Dashboard.

---

<div class="post-metadata">

### Author: ![Ghoond](https://avatars.discourse-cdn.com/v4/letter/g/c57346/32.png) [@Ghoond](https://discourse.nodered.org/u/Ghoond)
#### Post date: [27 September 2021 14:37 UTC](https://discourse.nodered.org/t/how-to-send-a-data-from-php-script-to-node-red-dashboard/51554/8 "2021-09-27T14:37:11Z")

</div>

Yes, i understand about that sir, what i meant is, do i have to just put the client.publish code inside the script so that the camera can send the color value to node-red, or do i have to use other method

---

<div class="post-metadata">

### Author: ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)
#### Post date: [27 September 2021 17:08 UTC](https://discourse.nodered.org/t/how-to-send-a-data-from-php-script-to-node-red-dashboard/51554/9 "2021-09-27T17:08:09Z")

</div>

If it's any help - here's a function I wrote a year or so ago to publish data & reports from a Wemos D1 Mini (being used as a controller for a weather station) via MQTT to a MQTT-In node in Node-RED.

Some of the include statements needed at the top of the Arduino code.

```auto
#include <PubSubClient.h>
#include <ArduinoJson.h>

```

```auto
void publish_situation(String message)
{
    StaticJsonDocument<256> doc;

    doc["nodeID"] = thisNodeID;
    doc["report"] = "situation";
    doc["status"] = message;
    doc["ssid"] = WiFi.SSID();
    doc["rssi"] = WiFi.RSSI();

    char buffer[256];
    size_t n = serializeJson(doc, buffer);

    char topic[30];
    strcpy(topic, mqtt_situation_topic);
    strcat(topic, "/");
    strcat(topic, thisNodeID);

    mqtt_client.publish(topic, buffer, n);
}
//------------ End of publish_mqtt()

```

This is how I call it in 'main'.

```auto
           publish_situation("Sending report");

```

And this is in an 'include' file to define the topic.

```auto
const char *mqtt_situation_topic = "homeDevice/situation";

```

I'm using the brilliant library... bblanchon/ArduinoJson@^6.16.1  
Make sure you install version-6 as it has loads of improvements over version-5.

I have a number of nodes that send data to Node-RED. Using the above code the MQTT publish topic is...

> ```
> homeDevice/situation/<thisNodeID> e.g. homeDevice/situation/node41
> 
> ```

---

<div class="post-metadata">

### Author: ![Ghoond](https://avatars.discourse-cdn.com/v4/letter/g/c57346/32.png) [@Ghoond](https://discourse.nodered.org/u/Ghoond)
#### Post date: [28 September 2021 09:25 UTC](https://discourse.nodered.org/t/how-to-send-a-data-from-php-script-to-node-red-dashboard/51554/10 "2021-09-28T09:25:20Z")

</div>

Can i upload the code to my esp32-cam with opencv installed?

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [28 September 2021 10:38 UTC](https://discourse.nodered.org/t/how-to-send-a-data-from-php-script-to-node-red-dashboard/51554/11 "2021-09-28T10:38:19Z")

</div>

> [@Ghoond](#):
>
> Can i upload the code to my esp32-cam with opencv

No. The ESP32-cam is a microcontroller not a micro computer. That means it only runs one program but it runs t fast.

You would have to hack the OpenCV code and add in the MQTT code to do this.

---

<div class="post-metadata">

### Author: ![Ghoond](https://avatars.discourse-cdn.com/v4/letter/g/c57346/32.png) [@Ghoond](https://discourse.nodered.org/u/Ghoond)
#### Post date: [30 September 2021 03:43 UTC](https://discourse.nodered.org/t/how-to-send-a-data-from-php-script-to-node-red-dashboard/51554/12 "2021-09-30T03:43:19Z")

</div>

actually sir, its like color tracking but the website that i referred called it " ESP32-CAM Web Server with OpenCV.js: Color Detection and Tracking" so the opencv is located inside the website. once the camera is turned on the website also turn on

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [30 September 2021 07:59 UTC](https://discourse.nodered.org/t/how-to-send-a-data-from-php-script-to-node-red-dashboard/51554/13 "2021-09-30T07:59:11Z")

</div>

While there is a small web server which runs in the browser, that code starts off stored on the esp32-cam and is sent to the browser when the esp32-cam is powered on. The browser code has a script that loads the opencv.js code from `https://docs.opencv.org/master/opencv.js`.

If you read the web page you refer to, you will find an explainaton of what part of the code is sent to the browser.

But this still means that if you want to add the MQTT/JSON code, that code needs to exist on the esp32-cam so you will have to change (hack) the code that is run on the esp32-cam to add that code in.

---

<div class="post-metadata">

### Author: ![Ghoond](https://avatars.discourse-cdn.com/v4/letter/g/c57346/32.png) [@Ghoond](https://discourse.nodered.org/u/Ghoond)
#### Post date: [30 September 2021 09:48 UTC](https://discourse.nodered.org/t/how-to-send-a-data-from-php-script-to-node-red-dashboard/51554/14 "2021-09-30T09:48:49Z")

</div>

Ok sir, so this means i need to search on how to send JSON from Arduino to Node-Red via MQTT

---

<div class="post-metadata">

### Author: ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)
#### Post date: [30 September 2021 11:08 UTC](https://discourse.nodered.org/t/how-to-send-a-data-from-php-script-to-node-red-dashboard/51554/15 "2021-09-30T11:08:19Z")

</div>

Did you try the example that @dynamicdave shared ?

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [29 November 2021 11:08 UTC](https://discourse.nodered.org/t/how-to-send-a-data-from-php-script-to-node-red-dashboard/51554/16 "2021-11-29T11:08:30Z")

</div>

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