Thanks for the supplementary information, Alex.
However, although the gem is now working, I am struggling to get the full NMEA sentence emitted by the GPS BT dongle. I always get part of the NMEA sentences, not getting a full sentence.
Example given in screenshot attached.
My controller code :
require 'rho/rhocontroller'
require 'helpers/browser_helper'
require 'rho/rhobluetooth'
require 'nmea_plus'
class GagantestController < Rho::RhoController
include BrowserHelper
#@layout = 'Gagantest/layout'
$device_name = ''
$connected_device = ''
$current_status = 'Not connected'
$str = ''
$lat=''
$lon=''
$fxtime=''
# $message=nil
$msgvalid=''
$msgdatatype=''
$msgintdatatype=''
$msgallrecd=''
def index
puts 'GagantestController.index'
$device_name = Rho::BluetoothManager.get_device_name()
#puts "$device_name=" + $device_name.to_s
WebView.execute_js('setStatus("'+$current_status+'");')
WebView.execute_js('setConnectedDeviceName("'+$connected_device+'");')
WebView.execute_js('setStr("'+$str+'");')
render
end
def start_bluetooth
if Rho::BluetoothManager.is_bluetooth_available()
$current_status = 'Connected!'
WebView.execute_js('setStatus("'+$current_status+'");')
Rho::BluetoothManager.create_session(Rho::BluetoothManager::ROLE_CLIENT, url_for( :action => :connection_callback))
#WebView.refresh
else
Alert.show_popup('Bluetooth not available')
WebView.navigate (url_for :action => :index)
end
end
def connection_callback
if @params['status'] == Rho::BluetoothManager::OK
$connected_device = @params['connected_device_name']
WebView.execute_js('setConnectedDeviceName("'+$connected_device+'");')
Rho::BluetoothSession.set_callback($connected_device, url_for( :action => :session_callback))
WebView.navigate (url_for :action => :index)
else
Alert.show_popup('Could not connect!')
WebView.navigate (url_for :action => :index)
end
end
def session_callback
if @params['event_type'] == Rho::BluetoothSession::SESSION_INPUT_DATA_RECEIVED ##&& @params['connected_device_name']==$connected_device
while Rho::BluetoothSession.get_status($connected_device) > 0
if @params['event_type'] == Rho::BluetoothSession::SESSION_DISCONNECT
$connected_device_name = ''
$current_status = 'Disconnected'
WebView.execute_js('setStatus("'+$current_status+'");')
WebView.execute_js('setConnectedDeviceName("'+$connected_device+'");')
WebView.execute_js('setStr("'+$str+'");')
Alert.show_popup('Connection lost!')
WebView.navigate (url_for :action => :index)
end
$str = Rho::BluetoothSession.read_string($connected_device)
WebView.execute_js('setStr("'+$str+'");')
#here
# end
# if "GPGLL" == message.data_type
# $lat=message.latitude
# $lon=message.longitude
# $fxtime=message.fix_time
# break
# close_all
# end
end
else
$connected_device = ''
$current_status = 'Not connected'
#$str = ''
WebView.execute_js('setStatus("'+$current_status+'");')
WebView.execute_js('setConnectedDeviceName("'+$connected_device+'");')
WebView.execute_js('setStr("'+$str+'");')
Alert.show_popup('Connection lost!')
WebView.navigate (url_for :action => :index)
end
WebView.execute_js('setStr("'+$str+'");')
WebView.navigate (url_for :action => :index)
end
def close_all
Rho::BluetoothSession.disconnect($connected_device)
Rho::BluetoothManager.off_bluetooth()
$connected_device = ''
$current_status = 'Not connected'
#$str = ''
WebView.execute_js('setStatus("'+$current_status+'");')
WebView.execute_js('setConnectedDeviceName("'+$connected_device+'");')
WebView.execute_js('setStr("'+$str+'");')
Alert.show_popup('Disconnected!')
WebView.navigate (url_for :action => :index)
end
end
Where did I do wrong? Any suggestions?