| 10 | } |
| 11 | |
| 12 | void 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 | |
| 55 | void onConfigurationJson(HttpRequest& request, HttpResponse& response) |
| 56 | { |
nothing calls this directly
no test coverage detected