This page shows how to use the WiFi interface.
<!DOCTYPE html> <html> <head> <script> // apSsid and apKey below will be used for connection to an access point. // apSsid and apKey should be updated to existing ones to perform // connection successfully. var apSsid = "ARRIS-WIFI-demo"; var apKey = "123456789"; var networkConfig; var operationManager; var wifiDeviceId; var wifiDevice; var accessPoints; var scanOperationId; function setStatus(status, append) { if (!append) { document.getElementById("status").innerHTML = status; } else { document.getElementById("status").innerHTML += "<br>" + status; } } function updateAps(status) { document.getElementById("aps").innerHTML += "<br>" + status; } function onOperationResult(event) { switch (event.operation.state) { case operationManager.OPERATION_PENDING: setStatus("Operation " + event.operation.id + " is PENDING."); return; case operationManager.OPERATION_FAILED: setStatus("Operation " + event.operation.id + " FAILED (" + event.operation.errorCode + "): " + errorCodeToString(event.operation.errorCode)); operationManager.releaseOperation(event.operation.id); return; case operationManager.OPERATION_COMPLETED: setStatus("Operation " + event.operation.id + " COMPLETED."); break; } switch (event.operation.userData) { case "Scan": if (event.result == wifiDevice.OP_RESULT_AP_INFO) { onScanDone(); } break; case "Connect": setStatus("Connected"); operationManager.releaseOperation(event.operation.id); onConnected(); break; case "Disconnect": setStatus("Disconnected"); operationManager.releaseOperation(event.operation.id); scan(); break; } } function onScanDone() { accessPoints = wifiDevice.getAccessPointInfoResult(scanOperationId); operationManager.releaseOperation(scanOperationId); for (var i in accessPoints) { var ap = accessPoints[i].ssid; if (ap == apSsid) { ap = "<b>" + ap + "</b>"; } updateAps(ap); if (accessPoints[i].ssid == apSsid) { var opId = operationManager.createOperation("Connect"); wifiDevice.connect(opId, accessPoints[i], apKey); } } } function onConnected() { var statistics = wifiDevice.getStatistics(); setStatus("bytesSent: " + statistics.bytesSent); setStatus("bytesReceived: " + statistics.bytesReceived, true); } function scan() { scanOperationId = operationManager.createOperation("Scan"); wifiDevice.scan(scanOperationId, ""); } function isConnected() { return networkConfig.getGenericDeviceInfo(wifiDeviceId).hasLink; } function onLoad() { networkConfig = toi.netService.getConfiguration(); try { operationManager = networkConfig.getOperationManager(); operationManager.addEventListener(operationManager.ON_OPERATION_RESULT, onOperationResult); var wifiDevices = networkConfig.getNetworkDevices( toi.consts.ToiNetConfiguration.NET_DEVICE_TYPE_WIFI); if (wifiDevices.length > 0) { // Use the first interface wifiDeviceId = wifiDevices[0]; wifiDevice = networkConfig.getWifiDevice(wifiDeviceId); if (!isConnected()) { scan(); } else { var operationId = operationManager.createOperation("Disconnect"); wifiDevice.disconnect(operationId); } } else { setStatus("No WiFi interfaces found."); } } catch (e) { operationManager.releaseOperation(scanOperationId); } } </script> </head> <body onLoad="onLoad();"> <embed type="application/x-kreatv-toi" hidden="true" /> <div style="margin-top: 20px;"> <p style="text-align: left" id="status">Loading...</p> <p style="text-align: left" id="aps">Access points:</p> </div> </body> </html>