Hello,
Thanks for your reply, but I still couldn’t make it work.
I’ve been using the cgi_redirectto() function you mentioned, but I don’t think it even gets to that point. I’m using DHCP so I don’t know my IP address in advance, and I’m using a function (similar to the one in the Browseled example) to generate the link for the redirectto. And each time this function is invoked I print the address that is generated, but when I run my program nothing appears, so I presume the method is never invoked.
I think that the program doesn’t recognize the .cgi actions from my .ssi site and thus can’t call the handler functions.
I was thinking about posting my whole code here in the forum, I know it’s an ugly thing to do, but you’ll probably spot my mistake, I just can’t figure out what’s wrong.
The code for the ssi site:
Web Server Test
[ ](/upAction.cgi)
[ ](/leftAction.cgi)
[ ](/rightAction.cgi)
[ ](/downAction.cgi)
Action:
LED1 frequency: ms on/off
LED2 frequency: ms on/off
The code for the program:
#class auto
#use "RCM54xxW.lib"
#define DS2 0
#define DS3 1
#define DS2_BIT 2
#define DS3_BIT 3
/***********************************
* Configuration *
***********************************/
#define FAT_BLOCK
#define FAT_USE_FORWARDSLASH
#define HTTP_NO_FLASHSPEC
#define USE_DHCP
#define TCPCONFIG 1
#define _PRIMARY_STATIC_IP "192.168.1.120"
#define WIFI_USE_WPA
#define WIFI_AES_ENABLED
#define IFC_WIFI_SSID "HRBH"
#define IFC_WIFI_ENCRYPTION IFPARAM_WIFI_ENCR_TKIP
#define IFC_WIFI_WPA_PSK_PASSPHRASE "gretzky6"
#define WIFI_VERBOSE_PASSPHRASE
#define TCP_BUF_SIZE 2048
#define HTTP_MAXSERVERS 1
#define MAX_TCP_SOCKET_BUFFERS 1
/********************************
* End of configuration section *
********************************/
#define REDIRECTTO myurl()
#memmap xmem
#use "fat.lib"
#use "dcrtcp.lib"
#use "http.lib"
SSPEC_MIMETABLE_START
SSPEC_MIME_FUNC(".ssi", "text/html", shtml_handler),
SSPEC_MIME( ".html", "text/html"),
SSPEC_MIME( ".png", "image/png"),
SSPEC_MIME( ".bmp", "image/bmp"),
SSPEC_MIME( ".cgi", ""),
SSPEC_MIMETABLE_END
char direction[15];
char cf1[10];
char cf2[10];
int f1;
int f2;
char *myurl() {
static char URL[64];
char tmpstr[32];
long ipval;
ifconfig(IF_DEFAULT, IFG_IPADDR, &ipval, IFS_END);
sprintf(URL, "http://%s/A/index.ssi", inet_ntoa(tmpstr, ipval));
printf("
My URL: %s", URL);
return URL;
}
void pbledon(int led)
{
if(led == DS2)
BitWrPortI(PBDR, &PBDRShadow, 0, DS2_BIT);
else
BitWrPortI(PBDR, &PBDRShadow, 0, DS3_BIT);
}
void pbledoff(int led)
{
if(led == DS2)
BitWrPortI(PBDR, &PBDRShadow, 1, DS2_BIT);
else
BitWrPortI(PBDR, &PBDRShadow, 1, DS3_BIT);
}
int upAction(HttpState* state)
{
strcpy(direction, "up");
if (f1 <= 500) {
f1 += 50;
}
cgi_redirectto(state,REDIRECTTO);
return 0;
}
int leftAction(HttpState* state)
{
strcpy(direction, "left");
if (f2 <= 500) {
f2 += 50;
}
cgi_redirectto(state,REDIRECTTO);
return 0;
}
int rightAction(HttpState* state)
{
strcpy(direction, "right");
if (f2 >= 100) {
f2 -= 50;
}
cgi_redirectto(state,REDIRECTTO);
return 0;
}
int downAction(HttpState* state)
{
strcpy(direction, "down");
if (f1 >= 100) {
f1 -= 50;
}
cgi_redirectto(state,REDIRECTTO);
return 0;
}
void main()
{
int rc;
char buf[20];
int myspec;
strcpy(direction, "n/a");
f1 = 300;
f2 = 300;
brdInit();
sspec_addCGI("/upAction.cgi", upAction, SERVER_HTTP);
sspec_addCGI("/downAction.cgi", downAction, SERVER_HTTP);
sspec_addCGI("/leftAction.cgi", leftAction, SERVER_HTTP);
sspec_addCGI("/rightAction.cgi", rightAction, SERVER_HTTP);
sspec_addvariable("direction", direction, PTR16, "%s", SERVER_HTTP);
sspec_addvariable("cf1", cf1, PTR16, "%s", SERVER_HTTP);
sspec_addvariable("cf2", cf2, PTR16, "%s", SERVER_HTTP);
printf("Initializing filesystem...
");
rc = sspec_automount(SSPEC_MOUNT_ANY, NULL, NULL, NULL);
if (rc)
printf("Failed to initialize, rc=%d
Proceeding anyway...
", rc);
printf ("Configuring interface for DHCP
");
ifconfig(IF_WIFI0, IFS_DHCP, 3, IFS_END);
sock_init_or_exit(1);
http_init();
http_set_path("/A/", "index.ssi");
tcp_reserveport(80);
printf("Your IP://%s/
", inet_ntoa(buf, MY_ADDR(IF_DEFAULT)));
printf("
Press any key to bring down the server cleanly.
");
while (1) {
http_handler();
if (kbhit())
{
fat_UnmountDevice(sspec_fatregistered(0)->dev);
exit(0);
}
sprintf(cf1, "%d", f1);
sprintf(cf2, "%d", f2);
costate
{
pbledon(DS2);
waitfor(DelayMs(f1));
pbledoff(DS2);
waitfor(DelayMs(f1));
}
costate
{
pbledon(DS3);
waitfor(DelayMs(f2));
pbledoff(DS3);
waitfor(DelayMs(f2));
}
}
}
The main idea of the program is to flash the LEDs of the board and change the frequency in case one of the buttons is pushed (buttons up and down control one LED and buttons left and right control the other led). The index.ssi file and the images used in the site are copied on the FAT file system. And the most interesting part (at least for me :p) is that the value of my variables (direction, cf1, cf2) are displayed, they are recognized, but the .cgi actions don’t work.
Sorry for this mess
but I’m desperate.
Thanks,
Square