title: Bluetooth RFCOMM connection Linux
body: <p>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. </p>
  
  <p><strong>FIRST PROBLEM</strong></p>
  
  <p>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:</p>
  
  <pre><code>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";
  }
  </code></pre>
  
  <p>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. <strong>How can I know which channel is the one that I need to use?</strong></p>
  
  <p><strong>SECOND PROBLEM</strong></p>
  
  <p>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:</p>
  
  <pre><code>Error opening serial port /dev/rfcomm0: Port not found
  </code></pre>
  
  <p>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. </p>
  
  <p>When I use the command rfcomm it gives me this:</p>
  
  <pre><code>rfcomm0: 00:06:66:42:10:44 channel 0 clean
  </code></pre>
  
  <p>So...any help?</p>
  
  <p>Best regards</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The second problem occurs only when I connect the rfcomm to the channel0. So:</p>
  
  <pre><code>-Channel 0 -&gt; Port not found
  -Channel 1 -&gt; Bytes with 255.
  -Channel X -&gt; Nothing.
  </code></pre>
  
  <p>Just to remember, the same code in Windows works fine.</p>
  
  <p><strong>Edit 2</strong></p>
  
  <p>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).</p>
  
  <p><strong>Edit 3</strong></p>
  
  <p>It seems to be some time issues...if I do this on the setup function:</p>
  
  <pre><code>  for(int i = 0; i &lt; 50; i++){
      delay(200);
      getSampleRate();
    }
  </code></pre>
  
  <p>I just get 4-5 times answers package...I really have no idea whats happening.</p>
  
  <p>This is the whole code:</p>
  
  <pre><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 &lt; 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 &lt; bytesAvailable; i++){
      println("Byte:", port.read());
    } 
  }
  </code></pre>
  
  <p><strong>FINAL EDIT</strong></p>
  
  <p>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...</p>