0

Greetings fellow programmers,

I'm a bit new here, so please be gentle.

Now the problem, I'm currently working on a dynamic web application running on WAGO PLC (750-8202) with embedded linux. Lighttpd is installed on the PLC itself. The goal is to monitor/edit I/O of the PLC from the web app.

After a lot of reasearch I found out I need to use CGI to communicate with my C applications that can return the information from the PLC that I need. I tried some simple hello world codes, but always with an error.

Here's my lighttpd.conf

# Common configuration values.
server.document-root    = "/var/www"
server.username         = "www"
server.groupname        = "www"
server.tag              = "lighttpd"
server.errorlog         = "/var/log/lighttpd/error.log"
accesslog.filename      = "/var/log/lighttpd/access.log"

index-file.names        = ( "index.html", "index.php" )
server.modules          = (
    "mod_access",
    "mod_accesslog",
    "mod_cgi",
    "mod_fastcgi",
    "mod_rewrite",
    "mod_redirect",
    "mod_auth",
    "mod_proxy"
)

include "mode.conf"
include "mime_types.conf"
include "mod_fastcgi.conf"
include "auth.conf"
include "redirect_test.conf"

$HTTP["url"] =~ "/cgi-bin/" {
        cgi.assign = ( "" => "" )
}

cgi.assign      = (
        ".cgi"  => ""
)
url.rewrite-once = (
  # Codesys3 webvisu forces the browser to come out with POST requests to the root context.
  # Move that to the /webvisu/ context so it goes through the proxy 8000.
  "^/WebVisuV3.bin" => "/webvisu/WebVisuV3.bin",
  # Redirect all http[s]://<ip>/rest/ URL's to the RESTful API Example "/rest/index.php'  
  "^(?:.*)/rest/(.*)" => "/rest/index.php/$1"
)

# Transfer all http[s]://<ip>/webvisu/ URL's to the proxy server on port 8000.
# That is, all codesys webvisu traffic goes through the proxy.
#$HTTP["url"] =~ "^/webvisu/.*" {
#    proxy.server = ("" => (( "host" => "127.0.0.1", "port" => proxy_port )) )
#}

# Activate proxy server on port 8000. Sends all requests from the browser to
# the codesys webserver (localhost:8080).
$SERVER["socket"] == "127.0.0.1:" + proxy_port {
    url.rewrite-once = (
        "^/webvisu/$" => "/webvisu.htm",
        "^/webvisu/(.*)" => "/$1"
    ),
    proxy.server = ( "" => (( "host" => "127.0.0.1", "port" => 8080 )) )
}

And now a simple application I'm trying out written in C:

#include <stdio.h> 
int main(void) 
{ 
printf("Content-Type: text/plain;charset=us-ascii\n\n");
printf("Hello world\n\n");  
return 0; 
}

I call my application like this:

http://192.168.1.2/cgi-bin/foo.cgi

And only get a blank page. If I check error log, it gives me this error:

(mod_cgi.c.1341) cleaning up CGI: process died with signal 6 

Can anyone point out where I'm making some kind of mistake? Or am I doing it all wrong? Is there some other, better way to communicate with C apps? I lost several days trying to figure it out and now I'm really let down. Any kind of help will be greatly appreciated.

Thanks a lot in advance and have a nice day!

4
  • Signal 6 is SIGABRT, which can mean too much to tell without further information. Did you try to comment out the proxy stuff? Did you compile foo.cgi with the correct compiler for your silicone? Did you try a simple shell script (if a shell is available, of course) with just the lines #!/bin/sh followed by echo Hello World! in it? Commented Apr 29, 2017 at 1:00
  • I tried a simple shell script you suggested and it worked. Tried commenting out the proxy stuff with no result, so I'm still stuck with my C script. I compiled the cgi programme with 'gcc foo.c -o foo.cgi' Commented Apr 29, 2017 at 14:26
  • 1
    You got me on the right track, I used wrong compiler, now it works perfectly. Thanks a lot! Closing this thread now. Commented Apr 29, 2017 at 15:33
  • you can, and should, answer you question yourself. Other people might have the same problem. And yes, I will upvote that answer if the grammar and spelling isn't too bad. Commented Apr 29, 2017 at 16:50

1 Answer 1

1

Thanks to deamentiaemundi, I got it working. I was using wrong compiler, the PLC has an ARM processor and codes need to be compiled using the tools provided by Wago - ptxdist.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.