0

I currently have a basic website hosted by my Raspberry Pi. What I am trying to do is control digital outputs via HTML form buttons. Currently it works while I am on the LAN as the button form action is set to the local IP of the Arduino. I am struggling to figure out how to control these outputs from another network or from my phone.

Am I on the right track to think I need to pass the on/off commands to something like a php script hosted on the RPi and have the php script generate the Post request?

Does anyone have an example to get me pointed in the right direction?

Thanks in advance

8
  • If you want to be able to access your RPi from outside your LAN, you need to configure your router to relay connections to your RPi when it gets a request from outside. You may also need to make appropriate changes to your Pi's firewall settings. If your ISP doesn't provide you with a static IP, you can use on of the many free Dynamic DNS services like DuckDNS. Commented Feb 1, 2016 at 16:41
  • Thank you for your response. I do have that all set up. I think I need to reword my question. Commented Feb 1, 2016 at 23:25
  • I need to create a php script that is hosted on the RPI. I need that php script to accept a HTML button value (1 or 0) and send a GET request to my arduino. I can send that GET request directly via the HTML form to the Uno (192.168.1.9) but once I call upon the website outside of my network the GET request still goes to 192.168.1.9, but that does not work for obvious reasons. I guess what it boils down to is I need help creating a php script that will take a HTML form button input and create a GET request for the Arduino. Thanks a lot for the help. Commented Feb 1, 2016 at 23:30
  • Accept the button value, decide what to do, then make the GET request using maybe cURL? Show us what you have tried so far. Commented Feb 2, 2016 at 2:08
  • In index.html I have - <iframe name="hiddenFrame" class="hide"></iframe> <form action="overrides.php" method="POST" target="hiddenFrame"> <input type="radio" name="r1" value="1" checked> On<br> <input type="radio" name="r1" value="0"> Off<br> <input type="submit" value="Submit"> </form> Commented Feb 3, 2016 at 1:39

1 Answer 1

1

You can control Arduino GPIO using RPi hosted website.

What you need to learn:

  • I2C/Serial/SPI communication between Arduino & RPi (Sample Tutorial (I2C))
  • CGI enables to execute programs written in C/C++, Python, etc redirect print/println/cout as web-response as well as you can execute system commands to manipulate communication bus, gpio and system calls. To know more about CGI, click here. (Get started with CGI)
    • You can call CGI program from URL just like you call webpage: ("192.168.1.0/cgi-bin/HelloWorld" , for RPi "/usr/lib/cgi-bin/" is folder where CGI programs are stored while "HelloWorld" is your executable).

As an example, assume that you want to turn on-off Arduino's on-board led D13 via webpage hosted on RPi. Webpage contains two buttons, On and Off. When "On" pressed (clicked), call C/C++ or Python code written to command Arduino via I2C. Define a common protocol to follow so that bytes sent by C/C++ or Python can be understand by Arduino. Like, if Arduino receives 1 from master (RPi), it should turn on D13 led and turn off for 0.

Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.