I am trying to connect a wearable device to processing IDE using Bluetooth connection. Before anything, I have to say that I have made it work on Windows OS, but I am struggling to do it with Linux Mint.Trying to make it work I have made things worse, so I am going to try to explain myself as clear as possible.
FIRST PROBLEM
At the beginning, I was able to connect from processing to the rfcomm0 port but it only sent me bytes with 255 content. For example, if I sent a command such as myPort.write(0x03) to get the streaming sample of my wearable device, it didnt do it, it just sent me a byte with 255. In the same program but running in windows I got all the data that I asked to the device, so it has to be a problem with the rfcomm0 port. My /etc/bluetooth looked like this:
rfcomm0 {
# Automatically bind the device at startup
bind yes;
# Bluetooth address of the device
device 00:06:66:42:10:44;
# RFCOMM channel for the connection
channel 1;
# Description of the connection
comment "Example Bluetooth device";
}
The device was already paired, so doing rfcomm bind 0 00:06:66:42:10:44 and running processing as administrator I was able to connect to the port (although not receiving the right data as I said). I am really new on serial ports but my guess is that maybe the channel number 1 was not the right one. How can I know which channel is the one that I need to use?
SECOND PROBLEM
Trying to fix it, I used rfcomm release rfcomm0, changed the rfcomm0 file setting channel 0 (to test a different one) and after binding again (rfcomm bind 0 00:06:66:42:10:44 0, to make sure it connects to other channel) and running processing I keep getting this error when I try to connect:
Error opening serial port /dev/rfcomm0: Port not found
The file for this port it actually exists. I have set the permission mask of the file to /dev/rfcomm0 to crw-rw-rw- 1 root dialout 216, 0 Apr 30 17:04 /dev/rfcomm0 just in case that was the problem but no luck.
When I use the command rfcomm it gives me this:
rfcomm0: 00:06:66:42:10:44 channel 0 clean
So...any help?
Best regards
EDIT
The second problem occurs only when I connect the rfcomm to the channel0. So:
-Channel 0 -> Port not found
-Channel 1 -> Bytes with 255.
-Channel X -> Nothing.
Just to remember, the same code in Windows works fine.
Edit 2
Ok, It seems I am getting something...the wearable device only send me information bytes when I send messages from the method DRAW() buuuut this kind of sucks because I need to do it from the setup method (sending a message to StartStreaming from the draw method does not make sense, it would be sending this message all the time).
Edit 3
It seems to be some time issues...if I do this on the setup function:
for(int i = 0; i < 50; i++){
delay(200);
getSampleRate();
}
I just get 4-5 times answers package...I really have no idea whats happening.
This is the whole code:
void setup()
{
size(windowW, windowH);
smooth();
// List all the available serial ports:
println(Serial.list());
try {
myPort = new Serial(this, Serial.list()[0], 115200);
} catch (Exception e) {
println(e.getMessage());
connectionError = true;
}
delay(2000);
/*
for(int i = 0; i < 50000; i++){
delay(200);
getSampleRate();
}
*/
}
void draw(){
background(255);
}
// Called whenever there is something available to read
void serialEvent(Serial port) {
int bytesAvailable = myPort.available();
for(int i = 0; i < bytesAvailable; i++){
println("Byte:", port.read());
}
}
FINAL EDIT
Well, after researching a lot and testing I think the problem is just about the port connection using bluetooth in Linux. I have tried the same code in Windows and MAC and everything runs great...