Warning Older Docs! - You are viewing documentation for a previous released version of RhoMobile Suite.

BluetoothSession API

Manages a connection session between your Bluetooth-equipped device and another Bluetooth-equipped device. Click for a short example of using bluetooth, or here for Rhodes-System-Api-Samples – BluetoothChat.

Enabling Bluetooth

You need to enable Bluetooth on the device. Do this by adding that capability to the build.yml file:

capabilities:
  - bluetooth

set_callback

Set the Bluetooth session callback. Returns OK or ERROR.

Rho::BluetoothSession.set_callback(connected_device_name, session_callback_url)
connected_device_name String. The name of the connected Bluetooth device.
session_callback_url url to a callback method. Parameters received in the callback: connected_device_name - name of connected device; event_type - SESSION_INPUT_DATA_RECEIVED or ERROR or SESSION_DISCONNECT

disconnect

Disconnect from the device. Returns OK or ERROR.

Rho::BluetoothSession.disconnect(connected_device_name)
role ROLE_SERVER or ROLE_CLIENT
callback_url url to a callback method called after the Bluetooth session is created or canceled. Parameters received in the callback: status of OK / ERROR / CANCEL, and connected_device_name (the name of the device connected via Bluetooth.
connected_device_name String. The name of the connected Bluetooth device that is to be disconnected.

get_status

Get the session status. Returns the size of the data received by the bluetooth connection (data has not been read or parsed yet); or -1 if error; or 0 if empty (did not receive data).

Rho::BluetoothSession.get_status(connected_device_name)
connected_device_name String. The name of the connected Bluetooth device.

read

Read data from the connected device. Returns an array of bytes.

Rho::BluetoothSession.read(connected_device_name)
connected_device_name String. The name of the connected Bluetooth device that is read from.

write

Write data to the connected device.

Rho::BluetoothSession.write(connected_device_name, data)
connected_device_name String. The name of the connected Bluetooth device that is written to.
data The information to write to the connected device. Array of bytes or fixnum.

read_string

Read string from the connected device. Returns a string.

Rho::BluetoothSession.read_string(connected_device_name)

connected_device_name – name of the connected device.

connected_device_name String. The name of the connected Bluetooth device that is read from.

write_string

Write string to the connected device. Returns OK or ERROR.

Rho::BluetoothSession.write_string(connected_device_name, data)
connected_device_name String. The name of the connected Bluetooth device that is written to.
data The information to write to the connected device. String.
Back to Top