Im running a localhost webserver on my raspbian that displays index.php which is located in /var/www/html. index.php:
Code: Select all
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Embedded OS</title>
</head>
<body>
<h2>Raspberry Pi 2: Driver</h2>
<form method="post" enctype="multipart/form-data" action="">
<input type="radio" name="driver" value="led_on">Leds On
<input type="radio" name="driver" value="led_off">Leds Off
<input type="radio" name="driver" value="led_stat">Led Stats
<input type="radio" name="driver" value="alt">Alt Read
<input type="radio" name="driver" value="temp">Temperature
<input type="radio" name="driver" value="light">Lightsensor
<input type="submit" name="submit" value="Submit">
</form>
<?php
if(isset($_POST['submit']))
{
echo "submit pressed\n";
if($_POST['driver'] == "temp")
{
exec('sudo /home/pi/Downloads/bcm2835/temp', $value);
print_r($value);
}
else
{
echo "none selected\n";
}
}
?>
</body>
</html>
Code: Select all
#include <bcm2835.h>
#include <stdio.h>
int main(int argc, char **argv)
{
if (!bcm2835_init())
return 1;
char buffer[4];
buffer[0] = 50;
int i,temp;
bcm2835_spi_begin();
bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);
bcm2835_spi_setDataMode(BCM2835_SPI_MODE3); //rising edge
bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_65536); //clock frequency
bcm2835_spi_chipSelect(BCM2835_SPI_CS1); //chip select 1
bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS1, LOW); //activate chip select 0
buffer[0]=buffer[1]=buffer[2]=buffer[3]=0;
//read de id
buffer[0] = 0x58;
bcm2835_spi_transfern(buffer,2);
printf("id:%02X\n",buffer[1]);
//read temperature
while(1)
{
buffer[0] = 0x50;
bcm2835_spi_transfern(buffer,3);
temp = buffer[1];
temp = temp<<8;
temp = temp + buffer[2];
temp = temp>>3;
temp = temp/16;
printf("temp:%d\n",temp);
delay(500);
break;
}
bcm2835_spi_end();
bcm2835_close();
return 0;
}
When I select the temperature radio button and press on the submit button, it returns an empty array instead of some values. So I took a look inside the error.log from apache2 which said:
Code: Select all
bcm2835_init: Unable to open /dev/gpiomem: Permission denied
Code: Select all
sudo chown root.gpio /dev/gpiomem
sudo chmod g+rw /dev/gpiomem
Code: Select all
root@raspberrypi:~# ls -la /dev/gpiomem
crwxr-x--- 1 root gpio 244, 0 Aug 23 11:56 /dev/gpiomem
This is what the little program should return:
Thanks for reading.id:C3
temp:35