Hi,
I am Using ABwifi to turn the phone's wifi on and then to scan for access points. When the phones wifi is turned off ABwifi throws an error.
The code is:
I get the following error:
I get the following error:
The WiFi does get turned on so it seems the problem is with wifi_FoundReadings the call back and there are no errors thrown within the try/catch structures/
In tried the statement
As the StartWifi supposedly returns a boolean result however the program then did not execute the wifi.GetNewReadingWifi statement.
Am I using the functions incorrectly or is there a bug? What can I try?
I am Using ABwifi to turn the phone's wifi on and then to scan for access points. When the phones wifi is turned off ABwifi throws an error.
The code is:
B4X:
#Region Project Attributes
#ApplicationLabel: efence
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region
'#Extends: android.support.v7.app.AppCompatActivity
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#Extends: android.support.v7.app.AppCompatActivity
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim badge As Int
Dim wifiBitmap As Bitmap
' Comms '
Dim Sock1 As Socket 'WiFi Socket to get embedded fence data
Dim AStreams As AsyncStreams
Dim Conv As ByteConverter
Dim cmdNoglbl As Int
Dim msg As String
Dim wifi As ABWifi
Dim wifiML As MLwifi
Dim wifiList As List
Dim wifiFences As List
' Timers
Dim Const nSamples = 512 As Int
Dim Const blockSize = 64 As Int
Dim const fs = 1500000 / 4 As Float
Dim const T = 1/fs * 1000000 As Float
Dim Const t1Interval = 200 As Float
Dim Const ipAddress = "20.0.0.1" As String
Dim fieldStr As String
Dim fieldByte(90) As Byte
Dim fieldFloat(15) As Float
Dim fieldFloatBlock(blockSize) As Float
Dim waveFloat(nSamples) As Float
Dim blockNum As Int
'Dim f As RandomAccessFile
Dim t1 As Timer
Dim timeOutTimer As Timer
Dim timerNetPing As Timer
Dim timeOutFlag As Boolean
Dim timeOutTime As Float
Dim timeSec As Float
Dim Const tAdHoc = 40 As Float
Dim Const tGetLog = 0.5 As Float
Dim Const tGetLastWF = 3 As Float
Dim Const tGraph = 0.5 As Float
Dim timeBase As Float
Dim timeBasePct As Float
Dim timProgress As Float
Dim conversationCancel As Boolean
Type logRec_t(dateF As Float, timeF As Float, serialNo As String, peakVoltsMax As Float, _
peakVoltsMin As Float, peakVoltsMaxAvg As Float, peakVoltsMaxStd As Float, _
peakVoltsMean As Float, peakVoltsStdDev As Float, peakIMax As Float, _
peakIMin As Float, peakIMaxAvg As Float, peakIMaxStd As Float, _
peakIMean As Float, peakIStdDev As Float, riseTimeAvg As Float, _
riseTimeStdDev As Float, ipTime As Float, recStatus As String, empty As Boolean)
Type eFenceLocCurrent_t(eFenceSn As String, LctnDesc As String, LocGPS As String, Empty As Boolean)
Dim logRecCurrent As logRec_t
Dim eFenceLocCurrent As eFenceLocCurrent_t
End Sub
Sub Globals
Private lblStatus As Label
Private lblTitle As Label
Private lblIPP As Label
Private lblPkVoltsAvg As Label
Private lblPkVoltsMean As Label
Private lblPkVoltsSD As Label
Private lblRiseTime As Label
Private lblS1 As Label
Private lblS2 As Label
Private lblS3 As Label
Private lblS4 As Label
Private lblS5 As Label
Private lblS6 As Label
Private lblDateTime As Label
Private lblS7 As Label
Private lbPkVoltsMeanSD As Label
Private pnlGraph As Panel
Private tglBtnZoom As ToggleButton
Private btnRefresh As Button
' Private CircleProgressBar1 As CircleProgressBar
Private ACToolBarLight1 As ACToolBarLight
Private ToolbarHelper As ACActionBar
Private sm As SlidingMenu
Private ListView1 As ListView
Private acNewBtn As ACFlatButton
Private btnCreateLocation As Button
Private ACitem As ACMenuItem
End Sub
Sub Activity_Create(FirstTime As Boolean)
logRecCurrent.Initialize
eFenceLocCurrent.Initialize
badge = 0
If FirstTime Then
wifiBitmap = LoadBitmap(File.DirAssets, "WiFi.png")
'Progress timer initialize
t1.Initialize("t1", t1Interval)
t1.Enabled = False
timeBasePct = tAdHoc + tGetLog + tGetLastWF + tGraph
timeOutTimer.Initialize("timeOut", 1000)
timeOutFlag = False
timerNetPing.Initialize("timerNetPingCallback", 2000)
If dataBasefcn.dbStartup = 0 Then
Log("DB Startup Failed")
End If
End If
Activity.LoadLayout("main")
Activity.Title = "eFence"
ToolbarHelper.Initialize
ACToolBarLight1.Title = "eFence"
ACToolBarLight1.SubTitle = ""
ACToolBarLight1.Color = 0xFF001364
ToolbarHelper.ShowUpIndicator = True 'set to true to show the up arrow
ToolbarHelper.UpIndicatorDrawable = BitmapToBitmapDrawable(LoadBitmap(File.DirAssets, "hamburger.png"))
ACToolBarLight1.InitMenuListener
sm.Initialize("sm")
Dim offset As Int = 85dip
sm.BehindOffset = offset
sm.Mode = sm.LEFT
Dim lftMenu As Panel
lftMenu.Initialize("")
sm.Menu.AddView(lftMenu, 0, 0, 100%x - offset, 100%y)
lftMenu.LoadLayout("Left")
ListView1.Top = 50dip
ListView1.TwoLinesLayout.ItemHeight = 60dip
ListView1.TwoLinesLayout.Label.TextSize = 20
ListView1.TwoLinesLayout.SecondLabel.TextSize = 12
ListView1.AddTwoLines("Fence List", "Open the list of fences")
ListView1.AddTwoLines("View Trends", "View voltage & current tends")
ListView1.AddTwoLines("Fault List", "List dates & durations of faults")
ListView1.AddTwoLines("Health Report", "Health Summary of all fences")
ListView1.AddTwoLines("Database Tasks", "View and Edit Data Base")
lblStatus.Padding = Array As Int(5dip, 3dip, 0dip, 5dip)
lblTitle.Padding= Array As Int(2dip, 3dip, 0dip, 2dip)
lblPkVoltsAvg.Padding= Array As Int(2dip, 3dip, 7dip, 2dip)
lblPkVoltsMean.Padding= Array As Int(2dip, 3dip, 7dip, 2dip)
lblPkVoltsSD.Padding= Array As Int(2dip, 3dip, 7dip, 2dip)
lblDateTime.Padding= Array As Int(2dip, 3dip, 7dip, 2dip)
lbPkVoltsMeanSD.Padding= Array As Int(2dip, 3dip, 7dip, 2dip)
lblRiseTime.Padding= Array As Int(2dip, 3dip, 7dip, 2dip)
lblIPP.Padding= Array As Int(2dip, 3dip, 7dip, 2dip)
DateTime.SetTimeZone(0)
DateTime.DateFormat = "yy/MM/dd hh:mm:ss"
'Initialize the WiFi Socket
lblStatus.Text = " No Connection"
Sock1.Initialize("Sock1")
Try
wifi.Initialize("wifi")
Catch
Log(LastException)
End Try
wifiList.Initialize
wifiFences.Initialize
Try
wifi.StartWifi
Catch
Log(LastException)
End Try
'Scan for AP's
Try
wifi.GetNewReadingWifi
Catch
Log(LastException)
End Try
End Sub
Sub wifi_FoundReadings(readings As List)
Dim i As Int
Dim Matcher1 As Matcher
Dim Matcher2 As Matcher
Dim regExPattern As String
Dim regExPattern2 As String
Dim reading As ABWifiReading
Try
wifi.StopWifi
Catch
Log(LastException)
End Try
wifiList.Clear
wifiFences.Clear
wifiList.AddAllAt(0, readings)
regExPattern = "^WIFI-EF\d{5}"
regExPattern2 = "^WiredSSID"
For i = 0 To readings.Size - 1
reading = readings.Get(i)
Matcher1 = Regex.Matcher(regExPattern, reading.SSID)
If Matcher1.Find = True Then
wifiFences.Add(reading)
End If
' This is used for debugging with the genimotion emulator which does not report the WiFiSSID.
Matcher2 = Regex.Matcher(regExPattern2, reading.SSID)
If Matcher2.Find = True Then
Sock1.Initialize("Sock1")
Sock1.Connect(ipAddress, 8899, 3000)
Return
End If
wifiFences.SortType("Level", False)
Next
'Open the eFence table manager
mngFenceLoc.mngFenceLocMode = 2
StartActivity(mngFenceLoc)
Wait For CanContinue
socketConnect
End Sub
I get the following error:
I get the following error:
java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.wifi.WIFI_STATE_CHANGED flg=0x8000010 (has extras) } in com.AB.ABWifi.ABWifi$1@420feca8
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:860)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:5751)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.AB.ABWifi.ABWifi$1.onReceive(ABWifi.java:132)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:845)
... 9 more
The WiFi does get turned on so it seems the problem is with wifi_FoundReadings the call back and there are no errors thrown within the try/catch structures/
In tried the statement
B4X:
Wait For wifi.StartWifi
As the StartWifi supposedly returns a boolean result however the program then did not execute the wifi.GetNewReadingWifi statement.
Am I using the functions incorrectly or is there a bug? What can I try?