Html POST..php question?

Hi all,i'm kinda new to NR,i want to send a signal from my gpio input (rasp pi)to a server with a simple php page(header,main,footer).that will display what gpio was triggered,so when the gpio input goes to pulldown send a http POST to my webpage and display it until it goes back to pullup(to 0)
i can't figure out how to receive the HTML POST on my server and display it...can someone throw me a bone ,or is there a better way to accomplish this(i know a i have to create another php file and include it in the main.php to dislay it i just don't know how to go about coding it)

My reading of the question is that you are asking how to do something on the server, which is not node-red based. So I am not sure where the node-red content of the question is.

pretty much cause i don't know how to test my flow until i figure out the other part,i looked online for a couple of days now for a solution i was hoping someone may have encountered the same problem and could give me a hint..

your question lists php which isn’t a subject for the Node-RED forum

There are lots of places to look for php help such as on stackoverflow. Have you tried a internet search such as https://duckduckgo.com/?q=php+recieve+http+post

Is there a reason why you want to do this on your server in PHP? From the rest of your question I understand you don’t have much experience with PHP, as this topic is where most beginner tutorials start with. Depending on the wider use case, an alternative would be to create that page using the Dashboard. Take a look at node-red-dashboard for example.

You can't simply browse to the PHP file to view anything since your PHP file will only have the proper input when the POST occurs. This is what I've always done:

<?php
  mail('yourself@yourself.com', 'PHP POST received', print_r($_POST, true));
?>

POST contents will be in $_POST, print_r() dumps a variable's contents, and mail() to mail it to yourself. Your server must be properly configured to send email obviously.

Look at the different functions in the PHP manual, e.g. https://www.php.net/manual/en/function.print-r.php

Also, if you are wanting to get values to display on a PHP page on-demand when that page is loaded, you should have your PHP page request (GET) from your Node-RED instance instead of having Node-RED POST to your PHP page. You can use the cURL functions in PHP to GET or POST from PHP.

If you're insisting on keeping the PHP web server and want to get values from node-red you could do something like...

Gpio -> change node store value of gpio in flow.store

Http in node (create end point) -> change node to set msg.payload to value of flow.store -> http out node

Or...

Have node-red publish values to an mqtt broker then have your server subscribe to the topics & present the values on a PHP page.

There are many solutions but tbh,. You'd be better off getting something going with the
node-red-dashboard

1 Like

guys what i want is pretty simple ,when a gpio is triggered show an alarm on the screen until the alarm is cancelled(and timestamp it)
dashboard seems to not be simple at all
and i really don't want to host the webpage on the rasp pi since i wanna use up to 64 gpios (i wanna have only node red running on it)

so dont use dashboard.

Use MQTT or create an endpoint in node-red as I suggested.

How else would you get values from one web server to another?

sure you could update a database or update files but thats pretty old school.

You are pretty much limited by your imagination.

What have you tried so far? Have you got the GPio stored in context? Have you tried creating an end point and accessing it from your PHP? Have you get an MQTT broker available to publish to?

thanks Steve,i'l store it in context and access it from the server
il post the flow once i get it running

1 Like