On Wed, Jan 22, 2014 at 6:23 AM,  <[email protected]> wrote:
> This is actually a very basic question, but I'm kind of lost right now.
> I was working on a school project with the Beagle bone black. It controls a
> bunch of motors and sensors, etc. We essentially wrote everything in C++ and
> made them into libraries of functions. They work when a main program calls
> the libraries and the function needed.
>
> Recently we have been asked to demo our progress so far, that too in just a
> few days. The main program is far from over, so we were thinking of making a
> very basic web interface that is just going to call the functions. I
> personally never did this yet, so have no idea what should I be looking at.
> Node.js and Javascript ('bonescript') seems to be a popular tutorial around,
> but can they be used to call C++ libraries? Is it possible to host a webpage
> on the board so that we can open up the page in another PC over LAN?
>
If you are skilled C/C++ programmers, why don't you use C CGI-programs
as Web interface?

Below a simple program for toggling the user led 0. Works perfectly on
my BBW with debian and apache. The main problem are the unix
user-rights, because Apache runs as user www-data and therefore the
CGI-binaries have no rights to change something on the system.
So, before running such a program via Web-server, you have to adapt
the user rights, in my case I did as root (after every reboot):
root@arm:~# echo none > /sys/class/leds/beaglebone\:green\:usr0/trigger
to stop the heart beat
root@arm:~# chmod 666 /sys/class/leds/beaglebone\:green\:usr0/brightness
to change permissions.

Simple options to call C binaries are PHP, perl, bash, ....
A simple php script for callling "ls" is below as well



#include <string.h>
#include <stdio.h>
#include <stdlib.h>

int main() {
char c[10]=" ";
printf ("Content-type: text/html\n\n"); /*do not delete this line*/
printf ("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\
<html>\n <body bgcolor='#E6E6FA'>\n");
FILE *fp;
fp=fopen("/sys/class/leds/beaglebone:green:usr0/brightness","r");
if (!fp)
{
fprintf(stderr, "Unable to open File");
return(1);
}
c[0] = getc(fp); /*read the first char*/
fclose(fp);
fp=fopen("/sys/class/leds/beaglebone:green:usr0/brightness","w");
if (strcmp(c, "0") == 0) fprintf(fp,"255");
else fprintf(fp,"0");
fclose(fp);
printf ("<a href='led'>toggle the user led 0</a><br></html>\n");
printf ("</body></html>\n");
       exit(0);
}


And a php example:
<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html> <body bgcolor='#E6E6FA'>
<?php
$output = shell_exec('ls -lart');
echo "<pre>".$output."</pre>";
?>
</body></html>

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to