Arjun Alap Sapkota
Arjun Alap Sapkota

Reputation: 21

Controlling GPIO pins with cgi scripts

I am trying to control GPIO pins over the web. I have apache server installed on my raspberry-pi(Raspbian wheezy) and I have created a web page with Html and javascript. What I want to do is to control the gpio pins when a user clicks a button on a page. I have bash script on a .cgi file in /usr/lib/cgi-bin directory and I made certain arrangements on apache configuration file so that it can access the file on that location.

Here is the .cgi file content:

#!/bin/bash
gpio -g mode 7 out
gpio -g write 7 1

echo "Status: 204 No Content"
echo "Content-type: text/html"
echo ""

changes to the conf file of apache: /etc/apache2/sites-enabled/000-default

<Directory "/usr/lib/cgi-bin">
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
            AddHandler cgi-script .cgi                     // I added this line
    </Directory>

but when I click button on the page it shows no response. I have also made the .cgi file executable with this command:

sudo chmod a+x setu.cgi

page code: head section:

<head>
<script language="JavaScript" type="text/JavaScript">
function setu()
{
  document.location="cgi-bin/setu.cgi";
}

function clearall(event)
{
   document.location="cgi-bin/clearall.cgi";
}
</script>
</head>

body section:

<form name="form1" method="post" action="">
<p align="center">&nbsp;</p>
<p align="center">
  <input name="up" type="button" id="up" value="UP" onmousedown="setu()"      onmouseup="clearall(event)" >


<p align="center">&nbsp;</p>
</form>

Any help on this topic would be great.

Upvotes: 2

Views: 1775

Answers (1)

Jakwobo
Jakwobo

Reputation: 45

Enable mod_cgi module for apache2

sudo a2enmod mod_cgi

Depending on what architecture your processor is it will enable cgi or cgid module
Worked for me.

Upvotes: 0

Related Questions