downunderthunder
Posts: 12
Joined: Tue Jul 10, 2012 7:29 pm

web interface for invoking C-Code?

Sun Mar 31, 2013 3:15 pm

Hi,
for the near future I'm planing to use the Rpi's GPIOS. Therefore I would like to use plain C for programming! Is there a web interface available to make C-Code executable via the internet?
Or should I rather learn python then using e.g. the web2py-interface that I just installed on my Rpi!
regards
Olli

User avatar
SN
Posts: 1014
Joined: Mon Feb 13, 2012 8:06 pm
Location: Romiley, UK
Contact: Website

Re: web interface for invoking C-Code?

Sun Mar 31, 2013 3:38 pm

nothing to stop you having some cgi scripts (typically in a cgi-bin directory) that execute a compiled C code binary - you can have that C code generate HTML if you wish but it could be clunky
Steve N – binatone mk4->intellivision->zx81->spectrum->cbm64->cpc6128->520stfm->pc->raspi ?

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: web interface for invoking C-Code?

Mon Apr 01, 2013 8:33 am

downunderthunder wrote:Hi,
for the near future I'm planing to use the Rpi's GPIOS. Therefore I would like to use plain C for programming! Is there a web interface available to make C-Code executable via the internet?
Or should I rather learn python then using e.g. the web2py-interface that I just installed on my Rpi!
regards
Olli
The web interface is usually called a "web server". Typically this is something called Apache or Nginx. They both have standard ways to call C programs in response to a URL being sent to them. CGI (Common Gateway Interface) is the generic term for programs executed by web servers, so start searching for that. CGI programs can be written in almost any language - C/C++, BASIC, PHP, Python, Perl, shell, etc. etc. etc.

-Gordon
--
Gordons projects: https://projects.drogon.net/

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: web interface for invoking C-Code?

Mon Apr 01, 2013 12:45 pm

You could just code a simple web server in C, as part of your program, it's not that hard, i coded one in ASM, see here: http://www.raspberrypi.org/phpBB3/viewt ... 19#p320919

But it would be simpler in C.
Batteries not included, Some assembly required.

perapera
Posts: 1
Joined: Tue Nov 26, 2013 1:12 am

Re: web interface for invoking C-Code?

Tue Nov 26, 2013 1:18 am

You can use CppWeb library to write CGI applications in C++ language. I've used it on FriendlyARM devices with Linux and CNU C++ compiler.

You can download library here: http://sourceforge.net/projects/cppweb/

This web developement framework is light-weight, highly portable and resulting CGI application has great performance executing on embedded systems.

alamsyah
Posts: 2
Joined: Tue Dec 03, 2013 2:55 am

Re: web interface for invoking C-Code?

Tue Dec 03, 2013 3:06 am

Hi Gordon,
I need script by geany how to get data from IP ethernet, i wanto to build Datalogger input from ethernet port then store fo SDcard or USB

drodri
Posts: 4
Joined: Thu Jan 02, 2014 12:59 pm
Location: Madrid, Spain
Contact: Website

Re: web interface for invoking C-Code?

Mon Jan 13, 2014 12:01 pm

Hi,

As a summary of the previous posts, I will like to contribute with the following ideas:

As DexOS points out, it is not difficult to integrate a simple web server into your application. Check for example the following tutorial that implements a simple form to switch on/off a led connected with GPIO: http://docs.biicode.com/en/latest/hardw ... erver.html
This example uses biicode (cross building from a linux box), to easily configure and build from sources the required libraries (ptypes and gpio). Embedding the web server into your application is ok for simple web applications, and only if there are no security concerns, as such servers are limited in functionality. The good part is that you don't have to install or configure a web server, so this approach might be ok if you just need to display some info in web or handle a few simple forms, over a local network.

If you need something open to the world, or more web functionality (uploading files multi-part, accessing both static and dynamic contents...) then, the way to go is certainly a full server as Apache or Nginx, plus developing your cgi code with http://sourceforge.net/projects/cppweb/.
Note that CGI apps are called at each HTTP request, and finished when the HTTP request is completed. If you want to maintain the application running, you have to use FastCGI. You have CWServer for sessionful calls in cppweb.

As for real control applications, lets say a heater, that continously checks temperature and acts accordingly, those application have obviously to continuosly run indepently of the web access. For such tasks I would build a two layer system: In the backend I would have my application (a standard binary) running, that could be accessed by some simple way, which could be the embedded http server above or even simpler, secured by firewall, only accessible within the raspberry. Then, for the web front end, an Nginx is used (configured properly) for full functionality and security, and for those requests that goes to the control app, the minimum http client code is executed to connect to the control application.
This might sound complex, but is is the only way to clearly address both problems: having a secure and robust web access, and being able to indendently build and manage a control application.

Good luck!

Return to “C/C++”