×
Namespaces

Variants
Actions
(Difference between revisions)

Checking network state in Symbian Web Runtime

From Nokia Developer Wiki
Jump to: navigation, search
dekuykin (Talk | contribs)
kiran10182 (Talk | contribs)
m
Line 407: Line 407:
  
 
==Postconditions==
 
==Postconditions==
After starting the snippet information about network state exists on display:
+
* After starting the snippet information about network state exists on display:
 +
  SIGNAL STRENGTH: progress bar indicating a signal strength.<br>
 +
  NAME: network name of current network.<br>
 +
  STATE: registration status of the device.<br>
  
SIGNAL STRENGTH: progress bar indicating a signal strength.<br>
+
* Shown information is refreshed every 0,5 seconds.
NAME: network name of current network.<br>
+
STATE: registration status of the device.<br>
+
  
Shown information is refreshed every 0,5 seconds.
 
 
==Supplementary material==
 
==Supplementary material==
 
+
You can see source file and executable application in attached zip archive. Archive is available for download at [[Media:Checking_network_state_in_WRT.zip|Checking_network_state_in_WRT.zip]]
You can see source file and executable application in attached zip archive. Archive is available for download at [[ Media:Checking_network_state_in_WRT.zip]]
+
  
 
[[Category:Web Runtime (WRT)]][[Category:Code Examples]]
 
[[Category:Web Runtime (WRT)]][[Category:Code Examples]]

Revision as of 21:14, 10 December 2008


Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic
CompatibilityArticle
Keywords: SystemInfo.networkname, SystemInfo.networkregistrationstatus, SystemInfo.signalbars
Created: (24 Nov 2008)
Last edited: kiran10182 (10 Dec 2008)


Overview

This code snippet shows how to obtain information about network which is currently available for using by device. This information includes: - network name; - signal strength; - network registration status. The code snippet uses JavaScript WRT SystemInfo Service API. To get required informations these properties are used: SystemInfo.networkname - for getting network name; SystemInfo.networkregistrationstatus - for getting current registration status; SystemInfo.signalbars - for getting signal strength.

To get access to System Info API embedded object application/x-systeminfo-widget is used.

Source file: NetworkState.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
"http://www.w3.org/TR/html4/strict.dtd">
 
<html>
<head>
<title>
Network State
</title>
 
<script type="text/javascript" src="networkState.js">
</script>
 
<link href="networkState.css" rel="stylesheet" type="text/css">
 
</head>
 
<body id="bodyId" class="bodyClass" onLoad="setup();">
 
<embed type="application/x-systeminfo-widget" hidden="yes"></embed>
 
<div id="mainDiv" class="mainDiv">
<br>
<table class="mainTable">
<tr>
<td class="name">
SIGNAL STRENGTH
</td>
<td class="value" id="progressbarContainer">
<table class="strengthTable" id="strengthTable">
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="name">
NETWORK
</td>
<td id = "networkName" class="value">
</td>
</tr>
<tr>
<td class="name">
STATE
</td>
<td id="networkState" class="value">
</td>
</tr>
</table>
</div>
 
</body>
 
</html>

Source file: networkState.css

.bodyClass {
background-color: white;
width: 100%;
height: 100%;
padding: 5px;
margin: 0px;
text-align: center;
vertical-align: middle;
}
 
.mainTable, .strengthTable {
color: black;
background-color: white;
border: inset 3px silver;
border-collapse: collapse;
padding: 3px;
margin: 3px;
text-align: center;
vertical-align: middle;
width: 70%;
}
 
.strengthTable {
border: 1px solid gray;
width: 90%;
padding: 0px;
margin: 0px;
height: 50px;
}
 
.white, .green, .gray {
border: dotted 1px gray;
padding: 0px;
margin: 0px;
background-color: white;
border-collapse: collapse;
}
 
.name {
font-weight: bold;
color: black;
padding: 3px;
margin: 0px;
border: solid 1px silver;
border-collapse: collapse;
text-align: center;
vertical-align: middle;
width: 80%;
}
 
.value {
font-weight: bold;
color: black;
padding: 3px;
margin: 0px;
border: solid 1px silver;
border-collapse: collapse;
text-align: center;
vertical-align: middle;
width: 20%;
}
 
.green {
background-color: green;
}
 
.gray {
background-color: #FF9966;
}
 
.mainDiv {
text-align: center;
vertical-align: middle;
}

Source file: networkState.js

// networkState.js
 
// Global variable capturing the reference to System Info object.
var sytemObject;
/**
* Function is called during loading of snippet.
* Initializes so global variable.
* Starts a loop which apdates information about network state.
*/

function setup() {
try {
// Take access to System Info API
sytemObject = document.embeds[0];
} catch (e) {
alert( "Setup error: " + e );
}
// Interval of refreshing information in milliseconds
var interval = 500;
// Set interval for updating network information and data on display
setInterval( updateNetworkData, interval );
}
 
function updateNetworkData() {
// Get signal level
var level = 0;
level = sytemObject.signalbars;
 
if (level == undefined) {
level = 0;
}
// Check if level incorrect
if (level < 0) {
level = 0;
}
if (level > 7) {
level = 7;
}
// Get network name
var networkName = sytemObject.networkname;
 
if (networkName == undefined) {
networkName = "Unknown";
}
 
// Get network registartion status of the device
var networkRegistrationStatus = sytemObject.networkregistrationstatus;
// Variable indicating network registration status
var statusText = "";
 
// Check network registration status value
// See JavaScript WRT SystemInfo Service API documentation
// for meaning of used constants
if (networkRegistrationStatus != undefined) {
switch (networkRegistrationStatus) {
case 0:
statusText = "Unknown";
break;
case 1:
case 2:
case 3:
statusText = "Not registered";
break;
case 4:
statusText = "Registered, network busy";
break;
case 5:
statusText = "Registered on home network";
break;
case 6:
statusText = "Registration denied";
break;
case 7:
statusText = "Registered on visited network (roaming)";
break;
default:
statusText = "Unknown";
break;
}
} else {
statusText = "Undefined";
}
 
// Configure view of table which is used for bar showing.
var levelTable = document.getElementById('strengthTable');
// Get width of application window
var windowWidth = screen.availWidth;
// Get height of application window
var windowHeight = screen.availHeight;
// Width of element which progress bar consists of
var barElementWidth;
// Height of element which progress bar consists of
var barElementHeight;
 
// Progress bar consists of 7 columns:
// one column for one signal level
var progressbarColumnsCount = 7;
 
// Row count in table which forms the progress bar
var tableRowCount = 7;
 
// Width of progress bar = windowWidth / 2
barElementWidth =
Math.round( ( windowWidth / 2 ) / progressbarColumnsCount );
 
// Height of progress bar =
// min( windowHeight / 2, barElementWidth*tan(30) )
// tan(30) = 0.578
var tan30 = 0.6;
if (windowHeight > (barElementWidth * tan30 * 2 * tableRowCount)) {
barElementHeight = Math.round(barElementWidth * tan30);
} else {
barElementHeight =
Math.round(( windowHeight / 2 ) / tableRowCount);
}
 
// Variable rowString is used for forming table row HTML code
var rowString = "";
// Auxiliary variable: table row number from end of table
var counter = 1;
// Fill table containing progress bar
for (var j = level; j > 0; j--) {
rowString = "";
for (var i = 1; i < counter; i++) {
rowString = rowString + "<td class=\"white\" width=\"" +
barElementWidth + "px\" height=\"" +
barElementHeight + "px\"></td>";
}
 
for (var i = counter; i <= level; i++) {
rowString = rowString + "<td class=\"green\" width=\"" +
barElementWidth + "px\" height=\"" +
barElementHeight + "px\" bgcolor=\"green\"></td>";
}
 
for (var i = level+1; i <= tableRowCount; i++) {
rowString = rowString + "<td class=\"gray\" width=\"" +
barElementWidth + "px\" height=\"" +
barElementHeight + "px\"></td>";
}
levelTable.rows[tableRowCount - counter].innerHTML = rowString;
counter++;
}
 
// Fill table rows which are not used for displaying progress bar.
for (var line = 0; line < tableRowCount - level; line++) {
rowString = "";
for (var column = 0; column < tableRowCount - line - 1; column++) {
rowString = rowString + "<td class=\"white\" width=\"" +
barElementWidth + "px\" height=\"" +
barElementHeight + "px\"></td>";
}
 
for(var column = tableRowCount - line - 1; column < tableRowCount;
column++) {
rowString = rowString + "<td class=\"gray\" width=\"" +
barElementWidth + "px\" height=\"" +
barElementHeight + "px\"></td>";
}
levelTable.rows[line].innerHTML = rowString;
}
 
// TD which contains network name indication
var networkNameLabel = document.getElementById('networkName');
// Update network name is indicated
networkNameLabel.innerHTML = networkName;
// TD which contains network state indication
var stateLabel = document.getElementById('networkState');
// Update network state indication
stateLabel.innerHTML = statusText;
// Set position of progress bar to center of table cell
var progressBarContainer =
document.getElementById('progressbarContainer');
progressBarContainer.align = "center";
progressBarContainer.valign = "middle";
progressBarContainer.Style.textAlign = "center";
}

Postconditions

  • After starting the snippet information about network state exists on display:
  SIGNAL STRENGTH: progress bar indicating a signal strength.
NAME: network name of current network.
STATE: registration status of the device.
  • Shown information is refreshed every 0,5 seconds.

Supplementary material

You can see source file and executable application in attached zip archive. Archive is available for download at Checking_network_state_in_WRT.zip

161 page views in the last 30 days.
×