Android Question Bluetooth and java.io.IOException

Discussion in 'Android Questions' started by Isac, Oct 6, 2014.

  1. Isac

    Isac Active Member Licensed User

    how to update the signal rssi every 1000ms?
    I tried this way but always update the same value.

    Code:
    Sub Service_Start (StartingIntent As Intent)
    Timer1.Initialize(
    "t",1000)
    Timer1.Enabled=
    True
    If StartingIntent.Action = "android.bluetooth.device.action.FOUND" Then
    rssi = StartingIntent.GetExtra(
    "android.bluetooth.device.extra.RSSI")
    Log("rssi: " & rssi)
    End If

    End Sub

    Sub  Timer1_Tick
    Log("Timer1: " & rssi)
    End Sub



    What refers to this error?
    java.io.IOException: , socket might closed or timeout, read ret: -1read failed

    thanks
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You only receive the rssi once when the intent arrives. You need to keep searching for devices if you want to monitor the rssi.
     
  3. Isac

    Isac Active Member Licensed User

    hello,

    I modified the event Sub btnSearch ForDevices_Click with the timer to make it automatic, but does not go very well because intercepts all devices.
    I would like to intercept only a device and monitor only one chosen
    Thank you for your help

    Code:
    'Activity module
    Sub Process_Globals
        
    Dim admin As BluetoothAdmin
        
    Dim serial1 As Serial
        
    Dim foundDevices As List
        
    Type NameAndMac (Name As StringMac As String)
        
    Dim connectedDevice As NameAndMac
        
    Dim t As Timer
    End Sub
     
    Sub Globals
        
    Dim btnSearchForDevices As Button
        
    Dim btnAllowConnection As Button
    End Sub
     
    Sub Activity_Create(FirstTime As Boolean)
        
    If FirstTime Then
            admin.Initialize(
    "admin")
            serial1.Initialize(
    "serial1")
        
    End If
        
    Activity.LoadLayout("1")
        t.Initialize(
    "t",5000)
        t.Enabled=
    True
    End Sub
     
    Sub Activity_Resume
    '    btnSearchForDevices.Enabled = False
        btnAllowConnection.Enabled = False
        
    If admin.IsEnabled = False Then
            
    If admin.Enable = False Then
                
    ToastMessageShow("Error enabling Bluetooth adapter."True)
            
    Else
                
    ToastMessageShow("Enabling Bluetooth adapter..."False)
                
    'the StateChanged event will be soon raised
            End If
        
    Else
            Admin_StateChanged(admin.STATE_ON, 
    0)
        
    End If
    End Sub
     
    Sub Admin_StateChanged (NewState As Int, OldState As Int)
    '    btnSearchForDevices.Enabled = (NewState = admin.STATE_ON)
        btnAllowConnection.Enabled = btnSearchForDevices.Enabled
    End Sub
     
    Sub Activity_Pause (UserClosed As Boolean)
    '    If UserClosed = True Then
    '        serial1.Disconnect
    '    End If
    End Sub
     
    'Sub btnSearchForDevices_Click
    Sub t_Tick
      
       foundDevices.Initialize
       
    If   admin.StartDiscovery= False Then
            
    ToastMessageShow("Error starting discovery process."True)
        
    Else
            
    ProgressDialogShow("Searching for devices...")  
        
    End If
     
      
        
    End Sub
    'End Sub
     
    Sub Admin_DiscoveryFinished
        
    ProgressDialogHide
        
    If foundDevices.Size = 0 Then
            
    ToastMessageShow("No device found."True)
        
    Else
            
    Dim l As List
            l.Initialize
            
    For i = 0 To foundDevices.Size - 1
                
    Dim nm As NameAndMac
                nm = foundDevices.Get(i)
                l.Add(nm.Name)
            
    Next
            
    Dim res As Int
            res = 
    InputList(l, "Choose device to connect", -1)
            
    If res <> DialogResponse.CANCEL Then
                connectedDevice = foundDevices.Get(res)
                
    ProgressDialogShow("Trying to connect to: " & connectedDevice.Name & " (" & connectedDevice.Mac & ")")
                serial1.Connect(connectedDevice.Mac)
            
    End If
        
    End If
    End Sub
     
    Sub Admin_DeviceFound (Name As String, MacAddress As String)
        
    Log(Name & ":" & MacAddress)
        
    Dim nm As NameAndMac
        nm.Name = Name
        nm.Mac = MacAddress
        foundDevices.Add(nm)
        
    ProgressDialogShow("Searching for devices (~ device found)...".Replace("~", foundDevices.Size))
    End Sub
     
    Sub btnAllowConnection_Click
        
    'this intent makes the device discoverable for 300 seconds.
        Dim i As Intent
        i.Initialize(
    "android.bluetooth.adapter.action.REQUEST_DISCOVERABLE""")
        i.PutExtra(
    "android.bluetooth.adapter.extra.DISCOVERABLE_DURATION"300)
        
    StartActivity(i)
      
        serial1.Listen
    End Sub
     
    Sub Serial1_Connected (Success As Boolean)
        
    ProgressDialogHide
        
    Log("connected: " & Success)
        
    If Success = False Then
            
    Log(LastException.Message)
            
    ToastMessageShow("Connessione Errata: " & LastException.Message, True)
        
    Else
        
    Msgbox("OK","Active")
        
    End If
    End Sub
     
    Last edited: Oct 7, 2014
  4. Erel

    Erel Administrator Staff Member Licensed User

    You cannot monitor a single device. You will need to restart the discovery process each time.

    This API is not designed for RSSI tracking.
     
  5. Isac

    Isac Active Member Licensed User

    Can you tell me where to find the API for my project?
    Where can I watch?


    Thank you very much
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    I don't think that there is any other relevant API.
     
  7. Isac

    Isac Active Member Licensed User

    Where do you look for the API?

    thank you
     
  8. Erel

    Erel Administrator Staff Member Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice