2 Replies Latest reply on Aug 5, 2013 2:17 AM by Dmitry Soldatenkov

    RhoMobile Bluetooth Scanner

      I'm trying to connect to a bluetooth scanner using RhoMobile based on the examples from the API docs. I'm using a Google Nexus One running Android 2.3.6 and have a Socket CHS 7X scanner. For a baseline, if I install the bluetooth wedge software on the device I can connect to the scanner and scan information but I'd prefer to not have to use the wedge. I've also tried the scanner in both SPP and HID modes. My code at the moment is pretty simple.

       

      def index

          if Rho::BluetoothManager.is_bluetooth_available()

            Rho::BluetoothManager.create_session(Rho::BluetoothManager::ROLE_CLIENT, url_for( :action => :connection_callback))

          end

        end

       

        def connection_callback

          puts "Connection callback"

          if @params['status'] == Rho::BluetoothManager::OK

             $connected_device = @params['connected_device_name']

             Rho::BluetoothSession.set_callback($connected_device, url_for( :action => :session_callback))

             send_string('Hello friend !')

          end

        end

       

        def session_callback

          puts "Session callback"

           if @params['event_type'] == Rho::BluetoothSession::SESSION_INPUT_DATA_RECEIVED

              while Rho::BluetoothSession.get_status($connected_device) > 0

                str = Rho::BluetoothSession.read_string($connected_device)

                # use received string

                puts "String: " + str

              end

           end

        end

       

      It makes it to the first callback however the status is ERROR and not OK. Looking at the logs this is what I see.

       

      I/APP     (  760): I 09/26/2012 22:01:02:061 000002f8 RhoBluetoothDeviceListActivity| onCreate()

      I/APP     (  760): I 09/26/2012 22:01:02:085 000002f8 RhoBluetoothDeviceListActivity|    no any paired device found !

      D/RhodesService(  760): +++ onStartCommand

      I/RhodesService(  760): handleCommand: startId=4, source=com.rhomobile.rhodes.BaseActivity

      D/RhodesService(  760): New activity was created

      I/ActivityManager(   96): Displayed com.rhomobile.xmobile/com.rhomobile.rhodes.bluetooth.RhoBluetoothDeviceListActivity: +335ms

      I/APP     (  760): I 09/26/2012 22:01:02:379 000002f8       RhodesActivity| onStop

      D/dalvikvm(  552): GC_EXPLICIT freed 12K, 49% free 2773K/5379K, external 1625K/2137K, paused 55ms

      I/APP     (  760): I 09/26/2012 22:01:09:402 000002f8 RhoBluetoothDeviceListActivity| doDiscovery()

      E/BluetoothEventLoop.cpp(   96): event_filter: Received signal org.bluez.Adapter:PropertyChanged from /org/bluez/218/hci0

      V/BluetoothEventRedirector(  790): Received android.bluetooth.adapter.action.DISCOVERY_STARTED

      E/BluetoothEventLoop.cpp(   96): event_filter: Received signal org.bluez.Adapter:DeviceFound from /org/bluez/218/hci0

      D/BluetoothService(   96): updateDeviceServiceChannelCache(00:C0:1B:0F:EE:81)

      V/BluetoothEventRedirector(  790): Received android.bluetooth.device.action.FOUND

      I/APP     (  760): I 09/26/2012 22:01:10:481 000002f8 RhoBluetoothDeviceListActivity| found devices (exclude already bonded :

      I/APP     (  760): I 09/26/2012 22:01:10:511 000002f8 RhoBluetoothDeviceListActivity|        - name[Socket CHS 7x [0FEE81]] adress[00:C0:1B:0F:EE:81]

      E/BluetoothEventLoop.cpp(   96): event_filter: Received signal org.bluez.Adapter:DeviceFound from /org/bluez/218/hci0

      D/BluetoothService(   96): updateDeviceServiceChannelCache(00:C0:1B:0F:EE:81)

      V/BluetoothEventRedirector(  790): Received android.bluetooth.device.action.FOUND

      I/APP     (  760): I 09/26/2012 22:01:10:565 000002f8 RhoBluetoothDeviceListActivity| found devices (exclude already bonded :

      I/APP     (  760): I 09/26/2012 22:01:10:568 000002f8 RhoBluetoothDeviceListActivity|        - name[Socket CHS 7x [0FEE81]] adress[00:C0:1B:0F:EE:81]

      E/BluetoothEventLoop.cpp(   96): event_filter: Received signal org.bluez.Adapter:DeviceFound from /org/bluez/218/hci0

      D/BluetoothService(   96): updateDeviceServiceChannelCache(90:27:E4:FF:EB:23)

      V/BluetoothEventRedirector(  790): Received android.bluetooth.device.action.FOUND

      I/APP     (  760): I 09/26/2012 22:01:15:754 000002f8 RhoBluetoothDeviceListActivity| found devices (exclude already bonded :

      I/APP     (  760): I 09/26/2012 22:01:15:769 000002f8 RhoBluetoothDeviceListActivity|        - name[Mac mini] adress[90:27:E4:FF:EB:23]

      E/BluetoothEventLoop.cpp(   96): event_filter: Received signal org.bluez.Adapter:PropertyChanged from /org/bluez/218/hci0

      V/BluetoothEventRedirector(  790): Received android.bluetooth.adapter.action.DISCOVERY_FINISHED

      E/BluetoothService.cpp(   96): stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session)

      I/APP     (  760): I 09/26/2012 22:01:22:768 000002f8 RhoBluetoothDeviceListActivity| item selected - address[00:C0:1B:0F:EE:81]

      I/APP     (  760): I 09/26/2012 22:01:22:801 000002f8       RhodesActivity| onStart

      I/APP     (  760): I 09/26/2012 22:01:22:801 000002f8    RhodesApplication| New UiState: MainActivityStarted

      I/APP     (  760): I 09/26/2012 22:01:22:802 000002f8       RhodesActivity| onResume

      I/APP     (  760): I 09/26/2012 22:01:23:027 000002f8 RhoBluetoothDeviceListActivity| onDestroy()

      E/BluetoothService.cpp(   96): stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session)

      I/APP     (  760): I 09/26/2012 22:01:23:051 000002f8 RhoBluetoothManagerNew| onDeviceListActivityFinished()

      I/APP     (  760): I 09/26/2012 22:01:23:053 000002f8  RhoBluetoothSession| connect() to: Socket CHS 7x [0FEE81]

      I/APP     (  760): I 09/26/2012 22:01:23:067 000002f8  RhoBluetoothSession| setState() 1 -> 2

      I/APP     (  760): I 09/26/2012 22:01:23:090 0000035e  RhoBluetoothSession| BEGIN mConnectThread

      E/BluetoothService.cpp(   96): stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session)

      E/BluetoothEventLoop.cpp(   96): event_filter: Received signal org.bluez.Adapter:DeviceCreated from /org/bluez/218/hci0

      E/BluetoothEventLoop.cpp(   96): event_filter: Received signal org.bluez.Adapter:PropertyChanged from /org/bluez/218/hci0

      E/BluetoothEventLoop.cpp(   96): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/218/hci0/dev_00_C0_1B_0F_EE_81

      E/BluetoothEventLoop.cpp(   96): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/218/hci0/dev_00_C0_1B_0F_EE_81

      D/BluetoothService(   96): updateDeviceServiceChannelCache(00:C0:1B:0F:EE:81)

      D/BluetoothService(   96):  uuid(application): 00001101-0000-1000-8000-00805f9b34fb 1

      D/BluetoothService(   96): Making callback for 00001101-0000-1000-8000-00805f9b34fb with result 1

      V/BluetoothEventRedirector(  790): Received android.bleutooth.device.action.UUID

      I/BluetoothEventLoop.cpp(   96): agent_event_filter: Received method org.bluez.Agent:OutOfBandAvailable

      V/BluetoothEventRedirector(  790): Received android.bleutooth.device.action.UUID

      D/dalvikvm(  178): GC_CONCURRENT freed 387K, 48% free 3140K/6023K, external 1625K/2137K, paused 7ms+2ms

      D/dalvikvm(  634): GC_EXPLICIT freed 2K, 44% free 3626K/6471K, external 1625K/2137K, paused 105ms

      E/BluetoothEventLoop.cpp(   96): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/218/hci0/dev_00_C0_1B_0F_EE_81

      D/BluetoothService(   96): 00:C0:1B:0F:EE:81 bond state 10 -> 12 (0)

      V/BluetoothEventRedirector(  790): Received android.bluetooth.device.action.BOND_STATE_CHANGED

      I/BluetoothEventLoop.cpp(   96): agent_event_filter: Received method org.bluez.Agent:OutOfBandAvailable

      I/APP     (  760): I 09/26/2012 22:01:31:139 0000035e  RhoBluetoothSession| connectionFailed()

      I/APP     (  760): I 09/26/2012 22:01:31:140 0000035e  RhoBluetoothSession| setState() 2 -> 0

      I/APP     (  760): I 09/26/2012 22:01:31:141 0000035e  RhoBluetoothSession|      STATE_NONE

      I/APP     (  760): I 09/26/2012 22:01:31:141 0000035e RhoBluetoothManagerNew| onSessionDisconnected()

      I/APP     (  760): I 09/26/2012 22:01:31:143 000002f8 RhoBluetoothManagerNew| fireCreateSessionCallback(status[ERROR], connected_device_name[])

      I/APP     (  760): I 09/26/2012 22:01:31:149 0000035e RhoBluetoothManagerNew| TOAST: Unable to connect device

      I/APP     (  760): I 09/26/2012 22:01:31:150 0000035e  RhoBluetoothSession| start()

      I/APP     (  760): I 09/26/2012 22:01:31:151 0000035e  RhoBluetoothSession| CAMCEL mConnectThread

      I/APP     (  760): I 09/26/2012 22:01:31:152 0000035e  RhoBluetoothSession| setState() 0 -> 1

      I/APP     (  760): I 09/26/2012 22:01:31:154 00000304           HttpServer| Process URI: '/app/Bluetooth/connection_callback'

      I/APP     (  760): I 09/26/2012 22:01:31:156 00000304                  APP| RHO serve: /app/Bluetooth/connection_callback

      I/APP     (  760): I 09/26/2012 22:01:31:161 00000304                  APP| Params: {"status"=>"ERROR", "connected_device_name"=>""}

      I/APP     (  760): I 09/26/2012 22:01:31:162 0000035e  RhoBluetoothSession|      STATE_LISTEN

      I/APP     (  760): I 09/26/2012 22:01:31:163 0000035e  RhoBluetoothSession| END mConnectThread

      I/APP     (  760): I 09/26/2012 22:01:31:164 00000304                  APP| Connection callback

       

      Anyone seen this issue before and found a solution? I'm super new to RhoMobile so I'm sure I could just be missing a simple step somewhere.

       

      On another note, is there a list of Bluetooth scanners that people have had luck getting to work without a wedge?

       

      Thanks,

      Chris

        • Re: RhoMobile Bluetooth Scanner
          selva raj

          We are also facing the same issue with create connection

           

          I/APP     (  760): I 09/26/2012 22:01:31:139 0000035e  RhoBluetoothSession| connectionFailed()

          I/APP     (  760): I 09/26/2012 22:01:31:140 0000035e  RhoBluetoothSession| setState() 2 -> 0

          I/APP     (  760): I 09/26/2012 22:01:31:141 0000035e  RhoBluetoothSession|      STATE_NONE

          I/APP     (  760): I 09/26/2012 22:01:31:141 0000035e RhoBluetoothManagerNew| onSessionDisconnected()

          I/APP     (  760): I 09/26/2012 22:01:31:143 000002f8 RhoBluetoothManagerNew| fireCreateSessionCallback(status[ERROR], connected_device_name[])

          I/APP     (  760): I 09/26/2012 22:01:31:149 0000035e RhoBluetoothManagerNew| TOAST: Unable to connect device

           

          Thanks

          • Re: RhoMobile Bluetooth Scanner

            You should pair your devices before connect from Rhodes app.