MCPcopy Create free account
hub / github.com/SmingHub/Sming / onIndex

Function onIndex

samples/HttpServer_AJAX/app/application.cpp:18–31  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16const uint8_t inputs[] = {5, 2};
17
18void onIndex(HttpRequest& request, HttpResponse& response)
19{
20 TemplateFileStream* tmpl = new TemplateFileStream("index.html");
21 auto& vars = tmpl->variables();
22 String gpioList;
23 for(unsigned i = 0; i < ARRAY_SIZE(inputs); ++i) {
24 String s = F("<span id=\"gpio{id}\" class=\"label label-default\">GPIO{gpio}</span> ");
25 s.replace("{id}", String(i));
26 s.replace("{gpio}", String(inputs[i]));
27 gpioList += s;
28 }
29 vars["gpio_list"] = gpioList;
30 response.sendNamedStream(tmpl); // this template object will be deleted automatically
31}
32
33void onFile(HttpRequest& request, HttpResponse& response)
34{

Callers

nothing calls this directly

Calls 4

sendNamedStreamMethod · 0.80
FFunction · 0.50
StringClass · 0.50
replaceMethod · 0.45

Tested by

no test coverage detected