Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.arch.embedded > #27419

lwip/httpd: how to return dynamic data [was Re: Embedded Ethernet]

From pozz <pozzugno@gmail.com>
Newsgroups comp.arch.embedded
Subject lwip/httpd: how to return dynamic data [was Re: Embedded Ethernet]
Date 2017-11-13 12:11 +0100
Organization A noiseless patient Spider
Message-ID <oubukg$qja$1@dont-email.me> (permalink)
References <oq3bj1$btg$1@dont-email.me> <os27k4$eq3$1@dont-email.me> <os2b4f$a09$1@dont-email.me> <os2kn9$gqd$1@dont-email.me> <os39ab$gs2$1@dont-email.me>

Show all headers | View raw


Il 16/10/2017 23:45, David Brown ha scritto:
[...]
>> The other question. What about dynamic content? The example seems show 
>> only static content.
>>
> 
> I handled that with JSON files.  So my static index.html file has 
> (static) javascript, using jQuery, that regularly polls the board 
> webserver for a file "data.json".  This is generated dynamically 
> (basically just a big snprintf statement with the required data added), 
> and the javascript running on the client then puts the data in the right 
> places in the html.

I'm trying to do exactly this: jQuery, polling, JSON data requests.
However I'm a little confused how to manage dynamic content with lwip 
and its httpd server.

I think dynamic content can be generated in a simple way by setting 
LWIP_HTTPD_CUSTOM_FILES and defining the function fs_open_custom() that 
snprintf() to a static string and set file content to that string.

int fs_open_custom(struct fs_file *file, const char *name) {
  if (!strcmp(name, "/data.json")) {
     static char json_data[1024];
     unsigned int idx = 0;

     idx += snprintf(&json_data[idx], sizeof(json_data) - idx, "{");

     idx += snprintf(&json_data[idx], sizeof(json_data) - idx,
         ...);

     idx += snprintf(&json_data[idx], sizeof(json_data) - idx, "}");

     return 1;
   }
   return 0;
}

The only problem is I can't access to query string params in 
fs_open_custom(). For example, I could have "/data.json?array=1" or 
"/data.json?array=23" or similar things.


Another problem is with CGI. After setting LWIP_HTTPD_CGI_SSI, I can 
define the CGI callback:

void httpd_cgi_handler(const char* uri, int iNumParams, char **pcParam,
     char **pcValue)
{
   if (!strcmp(uri, "/led.cgi")) {
     if ((iNumParams >= 1) &&
           !strcmp(pcParam[0], "status")) {
       if (!strcmp(pcValue[0], "on") led_on();
       if (!strcmp(pcValue[0], "off") led_off();
   }
}

Here there's another problem. How to return dynamic data to a CGI 
request, for example a result code, maybe in JSON format?
httpd_cgi_handler() doesn't return any data.

I could leave "/led.cgi" outside the static files and manage it as a 
custom file. However fs_open_custom() is called *before* 
httpd_cgi_handler(), so it's impossible to return a status code that 
depends on the CGI processing result.

Any help?

Back to comp.arch.embedded | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Embedded Ethernet pozz <pozzugno@gmail.com> - 2017-09-22 17:52 +0200
  Re: Embedded Ethernet mmm <m.colandrea@libero.it> - 2017-09-22 18:00 +0200
  Re: Embedded Ethernet David Brown <david.brown@hesbynett.no> - 2017-09-22 20:27 +0200
    Re: Embedded Ethernet pozz <pozzugno@gmail.com> - 2017-11-17 10:25 +0100
      Re: Embedded Ethernet Theo Markettos <theom+news@chiark.greenend.org.uk> - 2017-11-17 10:39 +0000
        Re: Embedded Ethernet pozz <pozzugno@gmail.com> - 2017-11-17 12:25 +0100
      Re: Embedded Ethernet "Boudewijn Dijkstra" <sp4mtr4p.boudewijn@indes.com> - 2017-11-17 11:36 +0100
        Re: Embedded Ethernet pozz <pozzugno@gmail.com> - 2017-11-17 12:54 +0100
      Re: Embedded Ethernet David Brown <david.brown@hesbynett.no> - 2017-11-17 15:23 +0100
      Re: Embedded Ethernet Mikko OH2HVJ <mikko.syrjalahti@nospam.fi> - 2017-11-18 11:29 +0200
  Re: Embedded Ethernet Joe Chisolm <jchisolm6@earthlink.net> - 2017-09-22 13:31 -0500
    Re: Embedded Ethernet pozz <pozzugno@gmail.com> - 2017-09-23 00:01 +0200
      Re: Embedded Ethernet raimond.dragomir@gmail.com - 2017-09-22 22:38 -0700
        Re: Embedded Ethernet raimond.dragomir@gmail.com - 2017-09-22 22:41 -0700
      Re: Embedded Ethernet David Brown <david.brown@hesbynett.no> - 2017-09-23 12:02 +0200
        Re: Embedded Ethernet Phil Hobbs <pcdhSpamMeSenseless@electrooptical.net> - 2017-09-23 06:32 -0400
          Re: Embedded Ethernet Dimiter_Popoff <dp@tgi-sci.com> - 2017-09-23 15:31 +0300
            Re: Embedded Ethernet Phil Hobbs <pcdhSpamMeSenseless@electrooptical.net> - 2017-09-25 13:07 -0400
              Re: Embedded Ethernet Robert Wessel <robertwessel2@yahoo.com> - 2017-09-25 15:31 -0500
                Re: Embedded Ethernet Dimiter_Popoff <dp@tgi-sci.com> - 2017-09-27 01:50 +0300
          Re: Embedded Ethernet Les Cargill <lcargill99@comcast.com> - 2017-09-28 20:07 -0500
        Re: Embedded Ethernet upsidedown@downunder.com - 2017-09-23 14:48 +0300
        Re: Embedded Ethernet Les Cargill <lcargill99@comcast.com> - 2017-09-28 20:06 -0500
          Re: Embedded Ethernet Joe Chisolm <jchisolm6@earthlink.net> - 2017-09-29 09:41 -0500
          Re: Embedded Ethernet upsidedown@downunder.com - 2017-09-30 18:49 +0300
        Re: Embedded Ethernet pozz <pozzugno@gmail.com> - 2017-10-12 11:26 +0200
          Re: Embedded Ethernet David Brown <david.brown@hesbynett.no> - 2017-10-12 12:46 +0200
          Re: Embedded Ethernet Joe Chisolm <jchisolm6@earthlink.net> - 2017-10-12 10:49 -0500
      Re: Embedded Ethernet Grant Edwards <invalid@invalid.invalid> - 2017-09-23 20:40 +0000
        Re: Embedded Ethernet Joe Chisolm <jchisolm6@earthlink.net> - 2017-09-23 19:24 -0500
          Re: Embedded Ethernet David Brown <david.brown@hesbynett.no> - 2017-09-24 13:28 +0200
  Re: Embedded Ethernet Les Cargill <lcargill99@comcast.com> - 2017-09-22 21:12 -0500
  Re: Embedded Ethernet Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2017-09-24 11:01 +0300
  Re: Embedded Ethernet pozz <pozzugno@gmail.com> - 2017-10-16 14:10 +0200
    Re: Embedded Ethernet David Brown <david.brown@hesbynett.no> - 2017-10-16 15:10 +0200
      Re: Embedded Ethernet pozz <pozzugno@gmail.com> - 2017-10-16 17:54 +0200
        Re: Embedded Ethernet David Brown <david.brown@hesbynett.no> - 2017-10-16 23:45 +0200
          lwip/httpd: how to return dynamic data [was Re: Embedded Ethernet] pozz <pozzugno@gmail.com> - 2017-11-13 12:11 +0100
            Re: lwip/httpd: how to return dynamic data [was Re: Embedded Ethernet] David Brown <david.brown@hesbynett.no> - 2017-11-13 14:14 +0100

csiph-web