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

Function onAjaxConnect

samples/HttpServer_ConfigNetwork/app/application.cpp:144–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

142}
143
144void onAjaxConnect(HttpRequest& request, HttpResponse& response)
145{
146 JsonObjectStream* stream = new JsonObjectStream();
147 JsonObject json = stream->getRoot();
148
149 String curNet = request.getPostParameter("network");
150 String curPass = request.getPostParameter("password");
151
152 bool updating = curNet.length() > 0 && (WifiStation.getSSID() != curNet || WifiStation.getPassword() != curPass);
153 bool connectingNow = WifiStation.getConnectionStatus() == eSCS_Connecting || network.length() > 0;
154
155 if(updating && connectingNow) {
156 debugf("wrong action: %s %s, (updating: %d, connectingNow: %d)", network.c_str(), password.c_str(), updating,
157 connectingNow);
158 json["status"] = (bool)false;
159 json["connected"] = (bool)false;
160 } else {
161 json["status"] = (bool)true;
162 if(updating) {
163 network = curNet;
164 password = curPass;
165 debugf("CONNECT TO: %s %s", network.c_str(), password.c_str());
166 json["connected"] = false;
167 connectionTimer.initializeMs<1200>(makeConnection).startOnce();
168 } else {
169 json["connected"] = WifiStation.isConnected();
170 debugf("Network already selected. Current status: %s", WifiStation.getConnectionStatusName().c_str());
171 }
172 }
173
174 if(!updating && !connectingNow && WifiStation.isConnectionFailed())
175 json["error"] = WifiStation.getConnectionStatusName();
176
177 response.setAllowCrossDomainOrigin("*");
178 response.sendDataStream(stream, MIME_JSON);
179}
180
181void startWebServer()
182{

Callers

nothing calls this directly

Calls 12

getRootMethod · 0.80
startOnceMethod · 0.80
isConnectionFailedMethod · 0.80
lengthMethod · 0.45
getSSIDMethod · 0.45
getPasswordMethod · 0.45
getConnectionStatusMethod · 0.45
c_strMethod · 0.45
isConnectedMethod · 0.45
sendDataStreamMethod · 0.45

Tested by

no test coverage detected