MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / connect

Method connect

contributed/modClock/main.js:268–322  ·  view source on GitHub ↗
(ssid, password)

Source from the content-addressed store, hash-verified

266 }
267
268 connect(ssid, password) {
269 if (this.connecting > 0) {
270 trace(`Already trying to connect WiFi (passed <${ssid}>)...\n`);
271 return;
272 }
273
274 if (this.rtc.valid)
275 this.display.showTime(this.currentStyle);
276 else
277 this.display.value("conn").blink();
278 this.connecting++;
279 this.connectionWasEstablished = 0;
280
281 trace(`Starting WiFi to connect to <${ssid}>...\n`);
282
283 WiFi.connect({ssid, password});
284 if (this.myWiFi)
285 return;
286
287 this.myWiFi = new WiFi;
288 this.myWiFi.onNotify = msg => {
289 trace(`Wi-Fi msg: ${msg}.\n`);
290 switch (msg) {
291 case WiFi.gotIP:
292 if (!this.connectionWasEstablished) {
293 trace(`WiFi gotIP: ${Net.get("IP")}. Going to connect to the local network.\n`);
294 this.connected();
295 }
296 break;
297
298 case WiFi.disconnected:
299 if (this.connecting)
300 return;
301 this.unconfigServer();
302 this.scanner?.close();
303 delete this.scanner;
304 accessPointList.length = 0;
305 this.connecting = 0;
306
307 this.display.value(this.connecting ? "fail" : "fa-x").blink();
308
309 Timer.set(() => {
310 if (this.connectionWasEstablished) {
311 trace("WiFi disconnected - try reconnect\n");
312 this.connect(ssid, password);
313 }
314 else {
315 trace("WiFi never established - start access point\n");
316 this.configAP(ap_name, AP_PASSWORD);
317 }
318 }, 5_000); // give scanner a chance to finish & don't thrash access point
319 break;
320 }
321 }
322 }
323
324 connected() {
325 this.connecting = 0;

Callers 15

constructorMethod · 0.95
xsbug-log.jsFile · 0.45
DebugBehavior.jsFile · 0.45
onDiscoveredMethod · 0.45
onDiscoveredMethod · 0.45
onDiscoveredMethod · 0.45
onDiscoveredMethod · 0.45
onDiscoveredMethod · 0.45
onDiscoveredMethod · 0.45
onDiscoveredMethod · 0.45
onDiscoveredMethod · 0.45
onDiscoveredMethod · 0.45

Calls 9

connectedMethod · 0.95
unconfigServerMethod · 0.95
configAPMethod · 0.95
showTimeMethod · 0.80
getMethod · 0.65
closeMethod · 0.65
setMethod · 0.65
blinkMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected