How to build string for ethercard webpage, arduino

976 Views Asked by At

How do i build a suitable string from an array of data values, that the ethercard library will accept to serve as a webpage? From the examples i have the below thus far, but i want to use an variable number of array elements (up to the limit of the packet buffer size).

static word homePage() {
  bfill= ether.tcpOffset();
  bfill.emit_p(PSTR(
    "HTTP/1.0 200 OK\r\n"
    "Content-Type: text/plain\r\n"
    "Pragma: no-cache\r\n"
    "\r\n"
    "$D\n"
    "$D\n"
    "$D\n"
    "$D\n"
    ), 
    data[0],data[1],data[2],data[3]
  );
  return bfill.position();
}

void loop() {
  if (ether.packetLoop(ether.packetReceive())) {
    ether.httpServerReply(homePage());
  }
}

I guess a side question is where do i learn about c strings, duh. (php guy).

1

There are 1 best solutions below

1
On

static char strbuf[STR_BUFFER_SIZE+1];

bfill.emit_raw(strbuf, strlen(strbuf));