Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private pEvent As PhoneEvents
Public wifiManager As WiFiConnect
End Sub
Sub Globals
Private edtIp As EditText
Private btnConnect As Button
Private lblReading As Label
Private lblConnectedState As Label
Private lblLedRed As Label
Private lblLedYellow As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
wifiManager.Initialize
pEvent.Initialize("PhoneEvent")
edtIp.Text = "192.168.4.1"
lblLedYellow.Color = Colors.Gray
lblLedRed.Color = Colors.Gray
End Sub
Public Sub StateChanged
If Starter.connected Then
lblConnectedState.Color = Colors.Green
Else
lblConnectedState.Color = Colors.Gray
End If
End Sub
Sub Activity_Resume
StateChanged
End Sub
Sub btnConnect_Click
If wifiManager.getWifiState <> wifiManager.WIFI_STATE_ENABLED Then
wifiManager.setWifiEnabled(True)
End If
If wifiManager.IsWiFiEnabled Then
Dim strWifi As String = wifiManager.getSSID
Log("wifiManager.getSSID = " & strWifi)
Log("wifiManager.getIpAddress = " & wifiManager.getIpAddress)
'If strWifi.EqualsIgnoreCase("myWifi") = False Then
If Not(wifiManager.getIpAddress.StartsWith("192.168.4.")) Then
'wifiManager.DisconnectCurrentSSID
'wifiManager.connectToSSID(wifiManager.WIFI_WPA, "myWifi", "12345678")
wifiManager.SwitchSSID("myWifi", wifiManager.WIFI_WPA, "12345678")
Else
CallSub2(Starter, "Connect", edtIp.Text)
End If
End If
End Sub
Private Sub PhoneEvent_ConnectivityChanged (NetworkType As String, State As String, Intent As Intent)
Log("ConnectivityChanged: " & NetworkType & ", state = " & State)
If State="CONNECTED" Then
If NetworkType = "WIFI" Then
If wifiManager.IsWiFiEnabled Then
Dim strWifi As String = wifiManager.getSSID
'If strWifi.EqualsIgnoreCase("myWifi") = False Then
If Not(wifiManager.getIpAddress.StartsWith("192.168.4.")) Then
'wifiManager.DisconnectCurrentSSID
'wifiManager.connectToSSID(wifiManager.WIFI_WPA, "myWifi", "12345678")
wifiManager.SwitchSSID("myWifi", wifiManager.WIFI_WPA, "12345678")
Else
Log("WiFiConnect")
CallSub2(Starter, "Connect", edtIp.Text)
End If
End If
End If
End If
End Sub
Sub Activity_Pause (UserClosed As Boolean)
Starter.socket.Close
End Sub