This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

http_demo cgi_process_data problem

Hello

1-Actually, Im using the http_demo project to control the mcb2300 through some web pages. But Im wondering why the LCD or the LED pages don't work. I can't make the leds blink.
After some debugging, I found out that the program does'nt step into the "do{}...while(dat)" of the cgi function cgi_process_data and I don't no why.

Can someone help me on this matter?

In order to compile the http_demo project, I had to modifiy the function cgi_process_data: Instead of 3 arguments, it takes only 2 arguments according to the function declaration in config.h; I removed the part that depends on the removed argument "code":

void cgi_process_data (U8 *dat, U16 len) {
   /* This function is called by HTTP server to process the returned Data    */
   /* for the CGI Form POST method. It is called on SUBMIT from the browser. */
   U8 passw[12],retyped[12];
   U8 *var,stpassw;

   P2 = 0;
   LEDrun = __TRUE;
   if (len == 0) {
      /* No data or all items (radio, checkbox) are off. */
      LED_out (P2);
      return;
   }
   stpassw = 0;
   var = (U8 *)alloc_mem (40);
   do {
      /* Parse all returned parameters. */
      dat = http_get_var (dat, var, 40);
          PutHexUart0(var, 40);
          sendchar('O');
      if (var[0] != 0) {
         /* Parameter found, returned string is non 0-length. */
         if (str_scomp (var, "led0=on") == __TRUE) {
            P2 |= 0x01;
         }
         else if (str_scomp (var, "led1=on") == __TRUE) {
            P2 |= 0x02;
         }
         else if (str_scomp (var, "led2=on") == __TRUE) {
            P2 |= 0x04;
         }
         else if (str_scomp (var, "led3=on") == __TRUE) {
            P2 |= 0x08;
         }
         else if (str_scomp (var, "led4=on") == __TRUE) {
            P2 |= 0x10;
         }
         else if (str_scomp (var, "led5=on") == __TRUE) {
            P2 |= 0x20;
         }
         else if (str_scomp (var, "led6=on") == __TRUE) {
            P2 |= 0x40;
         }
         else if (str_scomp (var, "led7=on") == __TRUE) {
            P2 |= 0x80;
         }
         else if (str_scomp (var, "ctrl=Browser") == __TRUE) {
            LEDrun = __FALSE;
         }
         else if (str_scomp (var, "pw=") == __TRUE) {
            /* Change password. */
            str_copy (passw, var+3);
            stpassw |= 1;
         }
         else if (str_scomp (var, "pw2=") == __TRUE) {
            /* Retyped password. */
            str_copy (retyped, var+4);
            stpassw |= 2;
         }
         else if (str_scomp (var, "lcd1=") == __TRUE) {
            /* LCD Module Line 1 text. */
            str_copy (lcd_text[0], var+5);
            LCDupdate = __TRUE;
         }
         else if (str_scomp (var, "lcd2=") == __TRUE) {
            /* LCD Module Line 2 text. */
            str_copy (lcd_text[1], var+5);
            LCDupdate = __TRUE;
         }
      }
   }while (dat);
   free_mem ((OS_FRAME *)var);
   LED_out (P2);

   if (stpassw == 0x03) {
      len = strlen ((const S8 *)passw);
      if (mem_comp (passw, retyped, len) == __TRUE) {
         /* OK, both entered passwords the same, change it. */
         str_copy (http_auth_passw, passw);
      }
   }
}

the lcd_cgi and led_cgi are unmodified.
Any Idea?

2-How can I execute some c instructions by clicking on some html buttons put on a page??
Here a page example:

const U8 commands_cgi[] = {
   "t <html><head><title>Button inputs</title>\r\n"
   "t <script language=JavaScript type=\"text/javascript\" src=\"xml_http.js\"></script>\r\n"
   "t <script language=JavaScript type=\"text/javascript\">\r\n"
   "# Define URL and refresh timeout\r\n"
   "t var formUpdate = new periodicObj(\"buttons.cgx\", 300);\r\n"
   "t function periodicUpdate(f, indx) {\r\n"
   "t f.cmd.value=indx; \r\n"
   "t f.submit(); \r\n"
   "t }\r\n"
   "t </script></head>\r\n"
   "i pg_header.inc\r\n"
   "t <form action=\"commands.cgi\" method=\"post\" id=\"form1\" name=\"form1\">\r\n"
   "t <table align=\"center\" border=\"0\" vAlign=\"center\" width=99%><font size=\"3\">\r\n"
   "t <tr bgcolor=#aaccff>\r\n"
   "t  <th width=60%>900 Commands</th>\r\n"
   "t </tr>\r\n"
   "t <tr>\r\n"
   "t      <td height = \"40\">\r\n"
   "t      </td>\r\n"
   "t </tr>\r\n"
   "t <tr>\r\n"
   "t <tr><td align=\"left\">\r\n"
   "c g 0 <input type=text name=cmd value=\"0\" size=2 maxlength=6 >\r\n"
   "t <br /><br /></td></tr>\r\n"
   "t <tr>\r\n"
   "t  <td align=\"left\" width = 30%>\r\n"

   "c g 1        <input id=\"Button1\" type=\"button\" value=\"Move to Front\" onclick=\"submit()\">Â Â Â \r\n"
   "c g 2         <input id=\"Button2\" type=\"button\" value=\"Move to Rear\" onclick=\"periodicUpdate(this.form, 2)\">Â Â \r\n"
   "c g 3         <input id=\"Button3\" type=\"button\" value=\"Move to Printer\" onclick=\"periodicUpdate(this.form, 3)\"\">Â \r\n"
   "c g 4         <input id=\"Button4\" type=\"button\" value=\"Move to Reader\" onclick=\"periodicUpdate(this.form, 4)\"\">Â \r\n"
   "c g 5         <input id=\"Button5\" type=\"button\" value=\"Move to Feeder\" onclick=\"periodicUpdate(this.form, 5)\"\">\r\n"
   "t  </td>\r\n"
   "t </tr>\r\n"
   "t </font></table>\r\n"
   "t </form>\r\n"
   "i pg_footer.inc\r\n"
   ". End of script must be closed with period.\r\n"
};

Thanks for your help!
Thanks in advance

Parents
  • You are NOT ALLOWED to remove any parameter from the cgi_process_data function. This format is used by TCPnet library and you are violating the calling convention for this function. The TCPnet library is prebuilt, the calling convention for the interface functions is known, so you should not modify them. Of course you can modify the interface function body, but not the parameters and return type.

    If you change it anyway (like you did in the above example), do not expect the example to work.

    Take a look at the HTTP_demo example, there are some pages with buttons on it. Check how it is done there and try it in the same way in your code.

Reply
  • You are NOT ALLOWED to remove any parameter from the cgi_process_data function. This format is used by TCPnet library and you are violating the calling convention for this function. The TCPnet library is prebuilt, the calling convention for the interface functions is known, so you should not modify them. Of course you can modify the interface function body, but not the parameters and return type.

    If you change it anyway (like you did in the above example), do not expect the example to work.

    Take a look at the HTTP_demo example, there are some pages with buttons on it. Check how it is done there and try it in the same way in your code.

Children