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

Function onConfiguration

samples/MeteoControl/app/webserver.cpp:22–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20}
21
22void onConfiguration(HttpRequest& request, HttpResponse& response)
23{
24 MeteoConfig cfg = loadConfig();
25 if(request.method == HTTP_POST) {
26 debugf("Update config");
27 // Update config
28 if(request.getPostParameter("SSID").length() > 0) // Network
29 {
30 cfg.NetworkSSID = request.getPostParameter("SSID");
31 cfg.NetworkPassword = request.getPostParameter("Password");
32 }
33 if(request.getPostParameter("TZ").length() > 0) // Correction
34 {
35 cfg.AddT = request.getPostParameter("T").toFloat();
36 cfg.AddRH = request.getPostParameter("RH").toFloat();
37 cfg.AddTZ = request.getPostParameter("TZ").toFloat();
38 }
39 if(request.getPostParameter("Trigger").length() > 0) // Trigger
40 {
41 cfg.Trigger = (TriggerType)request.getPostParameter("Trigger").toInt();
42 cfg.RangeMin = request.getPostParameter("RMin").toFloat();
43 cfg.RangeMax = request.getPostParameter("RMax").toFloat();
44 }
45 saveConfig(cfg);
46 startWebClock(); // Apply time zone settings
47 response.headers[HTTP_HEADER_LOCATION] = "/";
48 }
49
50 debugf("Send template");
51 TemplateFileStream* tmpl = new TemplateFileStream("config.html");
52 auto& vars = tmpl->variables();
53 vars["SSID"] = cfg.NetworkSSID;
54 vars["T"] = String(cfg.AddT, 2);
55 vars["RH"] = String(cfg.AddRH, 2);
56 vars["TZ"] = String(cfg.AddTZ, 2);
57 vars["Trigger"] = String((int)cfg.Trigger);
58 vars["RMin"] = String(cfg.RangeMin, 2);
59 vars["RMax"] = String(cfg.RangeMax, 2);
60 response.sendNamedStream(tmpl);
61}
62
63void onFile(HttpRequest& request, HttpResponse& response)
64{

Callers

nothing calls this directly

Calls 8

startWebClockFunction · 0.85
sendNamedStreamMethod · 0.80
loadConfigFunction · 0.70
saveConfigFunction · 0.70
StringClass · 0.50
lengthMethod · 0.45
toFloatMethod · 0.45
toIntMethod · 0.45

Tested by

no test coverage detected