2

This is actually a very simple question, but I'm lost at the moment.

This is actually with a beaglebone black. But I suppose the problem might translate to RPi too.

I was using a beaglebone black for a school project. It controls a bunch of motors and actuators,etc. We wrote everything in C++, and made libraries of functions. When a main program calls them, the functions run just fine.

Recently we have been told to demo our progress so far. The main program is nowhere near done, so we were thinking of some sort of web interface that can execute the complied C++ program on command. We were hoping to get the server hosted on the board, and access it via LAN from other PCs. But I've never done this before and have no idea where to start. Does node.js (with the 'bonescript') going to be of any help? Or is there a simpler way with basic HTML?

I only have a few days to figure it out, so I didn't want to waste time looking at the wrong methods.

2
  • 1
    Here is an example to control a led connected to rpi by web, maybe you can adapt it to control/run your program
    – hithwen
    Jan 22, 2014 at 9:32
  • 1
    Can't you just execute the C++ program via ssh?
    – francis
    Jan 22, 2014 at 10:29

3 Answers 3

1

You can add cgi functionality to your c++ programm to deliver a webinterface directly out of your application. just take a look at this tutorial!

if you use a debian based distro you can install the httpd (or if not apache2) service easily

apt-get install httpd

now you can adapt the documentroot in your httpd.conf to the location of your cpp programm..

the node.js approach would work too. you can do that with perl or php allthough.. or with a small java app.

the main topic is CGI - CommonGatewayInterface.

hope it helps..

1

I solved this by writing a file on the Pi using a bit of php in the web page. I am running apache2 on the pi, but any server supporting php would do. The file is placed in /var/tmp and contains whatever you need to convey to your C program. Then, to avoid having to monitor /var/tmp, I just send it a SIGUSR1 when there is anything to read, also from php by exec'ing a script on the pi.

0

I guess (hope) you've figured out by now, but just to mention some alternative, there are interesting shell httpd implementations, maybe performances aren't the best but setup and customizations are easy and fast (if you know shell scripting obviously). Just for example see a webserver in a shell script and avleen/bashttpd.

A CGI shell/lua/perl/whatever.. script calling the C++ command is also a fast solution to implement (as suggest previously in @AlexTape's answer).

Years ago for an embedded project I used the excellent thttpd, ansi C with CGI interface support (works with Php as CGI and using an older Php version, with some more patches, may even be linked), the development though seems to have stopped long time ago, security maybe an issue.

Sometime I'm using lighttpd(+Php as CGI/fast-CGI) on Raspbian.

I'm mentioning Php a lot because is relatively easy to create an extension with C/C++.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.