Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12589 Discussions

How to make a filename.cgi file?

Altera_Forum
Honored Contributor II
1,141 Views

hi hippo and everyone: 

 

i want to control led on 1C20 through boa webserver 

i use a example in forum 

but HTTP 400 appear when i click the buton in IE 

why? thank! 

****************uclinux_led_cgi.c**********************# include <stdio.h># include <string.h># include <stdlib.h># include <C:\altera\kits\nios2\bin\eclipse\workspace\alt_1c20_kernel\build\include\nios2_system.h

 

void main(void) 

np_pio *pio = na_led_pio;  

pio->np_piodirection = 3; 

pio->np_piodata = 0; 

 

int content_length=0; 

char *cgiinput ; 

 

unsigned char mydata=0; 

pio->np_piodata = 0x00; 

 

printf("Content-type: text/html\n"); 

printf("\n"); 

 

if ( !(content_length = atoi(getenv("CONTENT_LENGTH"))) ) { 

printf("No Content-Length was sent with the POST request.\n") ; 

exit(1) ; 

 

if ( !(cgiinput=(char *)malloc(content_length+1)) ) { 

printf("Could not allocate memory for cgiinput.\n") ; 

exit(1) ; 

 

if (!fread(cgiinput, content_length, 1, stdin)) { 

printf("Could not read CGI input from STDIN.\n") ; 

exit(1) ; 

 

cgiinput[content_length]=&#39;\0&#39; ; 

 

if (strstr(cgiinput, "LED1")) mydata |= 1; 

if (strstr(cgiinput, "LED2")) mydata |= 2; 

if (strstr(cgiinput, "LED3")) mydata |= 4; 

if (strstr(cgiinput, "LED4")) mydata |= 8; 

if (strstr(cgiinput, "LED5")) mydata |= 16; 

if (strstr(cgiinput, "LED6")) mydata |= 32; 

if (strstr(cgiinput, "LED7")) mydata |= 64; 

if (strstr(cgiinput, "LED8")) mydata |= 128; 

 

pio->np_piodata = mydata; 

 

printf("<html><head><title>CGI\n"); 

printf("Test</title><body>\n"); 

printf("<h1>LEDs set</h1>"); 

printf("\n"); 

printf("</body></html>\n"); 

 

exit(0); 

****************Makefile*************************# # configurable options# - set DEBUG = 1 to turn on debugging support#  

DEBUG = 1 

PROJ_NAME = uclinux_led_cgi 

INSTALL_DIR =  

PROGS := $(PROJ_NAME).exe 

CFLAGS += 

# # You should not need to modify anything beyond this point#  

TOPDIR = ./ 

include $(TOPDIR)/Rules.mak 

 

ifeq &#39;$(DEBUG)&#39; &#39;1&#39; 

PROGS += $(PROGS:.exe=.gdb) 

endif 

 

all: $(PROGS) 

 

.PHONY: clean 

clean: 

-rm -f *.[oad] *.elf *.gdb *.bin *.exe 

 

.PHONY: install 

install: all 

ifeq "$(INSTALL_DIR)" "" 

$(error No installation directory specified) 

endif 

mkdir -p $(INSTALL_DIR)/bin 

install -v $(filter %.exe, $(PROGS)) $(INSTALL_DIR)/bin 

 

******************index.html******************* 

<FORM METHOD="POST" 

 

ACTION="http://10.0.0.51/cgi-bin/uclinux_led_cgi.cgi"> 

 

1<INPUT TYPE="checkbox" NAME="LED1" VALUE="led1" CHECKED> 

 

2<INPUT TYPE="checkbox" NAME="LED2" VALUE="led2"> 

 

3<INPUT TYPE="checkbox" NAME="LED3" VALUE="led3"> 

 

4<INPUT TYPE="checkbox" NAME="LED4" VALUE="led4"> 

 

5<INPUT TYPE="checkbox" NAME="LED5" VALUE="led5"> 

 

6<INPUT TYPE="checkbox" NAME="LED6" VALUE="led6"> 

 

7<INPUT TYPE="checkbox" NAME="LED7" VALUE="led7"> 

 

8<INPUT TYPE="checkbox" NAME="LED8" VALUE="led8"> 

 

 

 

 

 

<INPUT TYPE="submit" value="OK"> 

 

</FORM> 

 

***************************************** 

i do it as follow: 

1>create make target .. in uclinux_led_cgi application 

2>build make target .. in uclinux_led_cgi application 

3>build project 

4>copy uclinux_led_cgi.exe in uclinux_led_cgi folder 

5>paste it in home/httpd/cgi-bin in alt_1c20_filesystem 

6>change it into uclinux_led_cgi.cgi.exe 

7>paste index.html in home/httpd 

8>build project in in alt_1c20_filesystem 

9>upload romfs.bin 

 

ifconfig eth0 10.0.0.51 

 

i can see the index page in IE 

but HTTP 400 appear when i click button in index page 

 

I try out CGI program with GET method 

It works!
0 Kudos
0 Replies
Reply