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

Function onConfiguration

samples/Basic_WebSkeletonApp_LTS/app/webserver.cpp:12–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10}
11
12void onConfiguration(HttpRequest& request, HttpResponse& response)
13{
14 if(request.method == HTTP_POST) {
15 debugf("Update config");
16 // Update config
17 if(request.getBodyStream() == nullptr) {
18 debugf("NULL bodyBuf");
19 return;
20 } else {
21 StaticJsonBuffer<ConfigJsonBufferSize> jsonBuffer;
22 JsonObject& root = jsonBuffer.parseObject(*request.getBodyStream());
23 root.prettyPrintTo(Serial); //Uncomment it for debugging
24
25 if(root["StaSSID"].success()) // Settings
26 {
27 uint8_t PrevStaEnable = ActiveConfig.StaEnable;
28
29 ActiveConfig.StaSSID = String((const char*)root["StaSSID"]);
30 ActiveConfig.StaPassword = String((const char*)root["StaPassword"]);
31 ActiveConfig.StaEnable = root["StaEnable"];
32
33 if(PrevStaEnable && ActiveConfig.StaEnable) {
34 WifiStation.enable(true);
35 WifiAccessPoint.enable(false);
36 WifiStation.config(ActiveConfig.StaSSID, ActiveConfig.StaPassword);
37 } else if(ActiveConfig.StaEnable) {
38 WifiStation.enable(true, true);
39 WifiAccessPoint.enable(false, true);
40 WifiStation.config(ActiveConfig.StaSSID, ActiveConfig.StaPassword);
41 } else {
42 WifiStation.enable(false, true);
43 WifiAccessPoint.enable(true, true);
44 WifiAccessPoint.config("TyTherm", "ENTERYOURPASSWD", AUTH_WPA2_PSK);
45 }
46 }
47 }
48 saveConfig(ActiveConfig);
49 } else {
50 response.setCache(86400, true); // It's important to use cache for better performance.
51 response.sendFile("config.html");
52 }
53}
54
55void onConfigurationJson(HttpRequest& request, HttpResponse& response)
56{

Callers

nothing calls this directly

Calls 7

getBodyStreamMethod · 0.80
setCacheMethod · 0.80
saveConfigFunction · 0.70
StringClass · 0.50
enableMethod · 0.45
configMethod · 0.45
sendFileMethod · 0.45

Tested by

no test coverage detected