Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script to bind rfcomm device to remote Bluetooth device #146

Merged
merged 4 commits into from
Oct 8, 2021

Conversation

708yamaguchi
Copy link
Collaborator

I add script to bind rfcomm device to remote bluetooth device.

By binding rfcomm device, we can connect bluetooth device via rosserial.
https://github.com/sktometometo/M5Stack_Bluetooth_rosserial_example

Usage

Save the bluetooth device MAC address to file like (/var/lib/robot/rfcomm_devices.yaml)

- name: device1
  address: XX:XX:XX:XX:XX:XX
- name: device2
  address: YY:YY:YY:YY:YY:YY

Then, run this program.
If you use PR2,

roslaunch jsk_pr2_startup pr2_rfcomm_bind.launch machine:=c2  # bluetooth dongle is now in c2

management

Currently, I start the above launch file by upstart.

The config file is in /etc/upstart/jsk-rfcomm-bind.conf in pr2.

To check how many devices are bound to rfcomm, use rfcomm command.

ssh pr2
ssh c2
rfcomm

@knorth55
Copy link
Owner

knorth55 commented Oct 8, 2021

does this script monitor the bluetooth connection and automatically connect the device when its exists?

@708yamaguchi
Copy link
Collaborator Author

708yamaguchi commented Oct 8, 2021

does this script monitor the bluetooth connection and automatically connect the device when its exists?

No.
This node only binds rfcomm file (e.g. /dev/rfcomm0) and bluetooth device (MAC address like AA:BB:CC:DD:EE:FF) before establishing the connection.

So my usage is like the following:

1. Bind rfcomm file and bluetooth device by `rfcomm_bind.py` when robot starts
2. Establish a connection to bluetooth device by `rosrun rosserial_python serial_node.py port:=/dev/rfcomm*`

FYI (rfcomm bind):

bind <dev> [bdaddr] [channel]
This binds the RFCOMM device to a remote Bluetooth device. The command did not establish a connection to the remote device, it only creates the binding. The connection will be established right after an application tries to open the RFCOMM device. If no channel number is specified, it uses the channel number 1. If the Bluetooth address is also left out, it tries to read the data from the config file.

https://linux.die.net/man/1/rfcomm

@knorth55 knorth55 merged commit b043ceb into knorth55:pr1040 Oct 8, 2021
@knorth55
Copy link
Owner

knorth55 commented Oct 8, 2021

so you mean that you manually start the upstart like sudo initctl start jsk-rfcomm-bind?

@knorth55
Copy link
Owner

knorth55 commented Oct 8, 2021

also please

  1. open this PR to jsk-ros-pkg/jsk_robot.
  2. open new PR for Fetch

@708yamaguchi
Copy link
Collaborator Author

I am sorry for confusing you.

so you mean that you manually start the upstart like sudo initctl start jsk-rfcomm-bind?

No, jsk-rfcomm-bind automatically starts after robot-is-on.
This is because rfcomm bind works regardless of existance of the bluetooth devices.

So
If there is no bluetooth device,

  • rfcomm bind works
  • rosrun rosserial_python serial_node.py does not work.

If bluetooth device appears after rfcomm bind, rosrun rosserial_python serial_node.py works.

also please
open this PR to jsk-ros-pkg/jsk_robot.
open new PR for Fetch

OK.
I do that.

@knorth55
Copy link
Owner

knorth55 commented Oct 9, 2021

I see, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted https://hacktoberfest.digitalocean.com
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants