Answers.Body: <p><code>rfcomm</code> is an old and deprecated tool, so I'm not going to try to figure out what exactly is going on. I suspect that it has to do with the fact that it treats the connection as a TTY and it is sending extra characters to the EV3 that messes up the communication protocol. I tried adding:</p>
  
  <pre><code>import tty
  
  ...
  
  tty.setraw(f.fileno())
  </code></pre>
  
  <p>to the program to fix this, but it does not seem to work.</p>
  
  <p>Instead, I would recommend just using Bluetooth sockets in your python program instead of using the <code>rfcomm</code> command line tool. Here is a working example:</p>
  
  <pre><code>#!/usr/bin/env python3
  
  import time
  
  import bluetooth
  
  # change to *your* EV3 Bluetooth address
  BDADDR = "00:16:53:00:00:00"
  PORT = 1
  
  # beep with 1% volume at 500 hz for .5 seconds
  BEEP_CODE = b'\x0f\x00\x00\x00\x80\x00\x00\x94\x01\x81\x01\x82\x0b\x02\x82\xf4\x01'
  
  sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
  sock.connect((BDADDR, PORT))
  sock.send(BEEP_CODE)
  time.sleep(1.7)
  sock.send(BEEP_CODE)
  sock.close()
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-08T11:35:22.027Z
Answers.Text: This worked for me. However, i am still looking for a solution which makes it possible to use the matlab packages, which seem to require serial communication. Thanks!
Answers.UserDisplayName: harfe
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-03T16:06:43.377Z
Answers.LastActivityDate: 2018-05-03T16:06:43.377Z
Answers.UserDisplayName: David Lechner
Body: <p><strong>Short description</strong>:</p>
  
  <p>I want to send commands via Bluetooth to an EV3 brick from a Linux computer.
  I use python to send bytecodes via Bluetooth and not any EV3-specific software
  Pairing the device was successful.
  If i send a "beep" command directly after establishing a connection, i can hear a beep from the brick.
  However, if i wait longer before i send the command, e.g. 2 seconds, then i can hear no beep.
  Any ideas how i could fix this behavior and be able to send commands many seconds after i established a connection?</p>
  
  <p><strong>Longer description</strong>:</p>
  
  <p>Assuming the devices are already paired and Bluetooth enabled on the EV3 brick, i use the following setup:</p>
  
  <p>To create /dev/rfcomm0, run </p>
  
  <pre><code>sudo rfcomm bind 0 &lt;MAC-adress of the EV3&gt;
  </code></pre>
  
  <p>Then, execute the following python script as root:</p>
  
  <pre><code>import time
  beep_code=[0x0f,0x00,0x00,0x00,0x80,0x00,0x00,0x94,0x01,0x81,0x1,0x82,0x0b,0x02,0x82,0xf4,0x01]
  # beep with 1% at 500 hz for .5 seconds
  b=bytearray(beepcode)
  f=open("/dev/rfcomm0","w+b",0)
  f.write(b)
  f.flush()
  time.sleep(1.7)
  f.write(b)
  f.flush()
  </code></pre>
  
  <p>I got the bytecode for the command from <a href="https://bricks.stackexchange.com/questions/6692/no-response-when-controlling-the-mindstorms-ev3-brick-over-bluetooth?rq=1">here</a>.
  The result is that i can hear only one beep, instead of the expected two beeps.
  If i make the waiting time shorter, e.g. 1 second, i can hear two beeps.</p>
  
  <p>I use a computer running Kubuntu (Linux kernel 4.4).
  The firmware version of the brick is V1.09H,
  the hardware version is V0.60</p>
  
  <p>Maybe i did something wrong with my Bluetooth setup on Linux, but the Bluetooth connection was successful for</p>
  
  <p>Some comments and observations:</p>
  
  <ul>
  <li>very similar behavior can be observed when connecting using the Matlab support package for EV3 and Bluetooth</li>
  <li>similar behavior can be observed when using a motor (using Matlab)</li>
  <li>sometimes it works (i.e. i hear two beeps) with a waiting time of 1.7 seconds, sometimes it fails for a shorter time (e.g. 1.5 seconds), so it is not completely deterministic</li>
  <li>starting the connection with <code>open()</code> takes a few seconds, so it would not be possible to re-open /dev/rfcomm0 for every command</li>
  <li>i cannot circumvent the problem by sending a command every 0.5 seconds. In this case, the brick still does not produce beep tones after roughly 1.7 seconds (starting from when the fopen() command finished). So it is not just a simple timeout if there is no data.</li>
  <li>on the EV3 brick the Bluetooth connection is marked as "connected" until f.close() is executed or the python script has completed. The same connection status can be observed using bluetoothctl on Linux.</li>
  </ul>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-04-28T00:26:35.820Z
Comments.Text: I know the problem is already solved, but there is a new firmware version which I think is 1.10E. Updating could also help.
Comments.UserDisplayName: mindstormsboi
Tags: <ev3><mindstorms><programming><bluetooth><remote-control>
Title: EV3 does not react to Bluetooth commands after 1.7 seconds
UserDisplayName: harfe
ThreadText: # EV3 does not react to Bluetooth commands after 1.7 seconds
  
  (Asked by: username_0 on 2018-05-03)
  
  **Short description**:
  
  I want to send commands via Bluetooth to an EV3 brick from a Linux computer.
  I use python to send bytecodes via Bluetooth and not any EV3-specific software
  Pairing the device was successful.
  If i send a "beep" command directly after establishing a connection, i can hear a beep from the brick.
  However, if i wait longer before i send the command, e.g. 2 seconds, then i can hear no beep.
  Any ideas how i could fix this behavior and be able to send commands many seconds after i established a connection?
  
  **Longer description**:
  
  Assuming the devices are already paired and Bluetooth enabled on the EV3 brick, i use the following setup:
  
  To create /dev/rfcomm0, run
  
  ```
  sudo rfcomm bind 0 <MAC-adress of the EV3>
  
  ```
  
  Then, execute the following python script as root:
  
  ```
  import time
  beep_code=[0x0f,0x00,0x00,0x00,0x80,0x00,0x00,0x94,0x01,0x81,0x1,0x82,0x0b,0x02,0x82,0xf4,0x01]
  # beep with 1% at 500 hz for .5 seconds
  b=bytearray(beepcode)
  f=open("/dev/rfcomm0","w+b",0)
  f.write(b)
  f.flush()
  time.sleep(1.7)
  f.write(b)
  f.flush()
  
  ```
  
  I got the bytecode for the command from [here](https://bricks.stackexchange.com/questions/6692/no-response-when-controlling-the-mindstorms-ev3-brick-over-bluetooth?rq=1).
  The result is that i can hear only one beep, instead of the expected two beeps.
  If i make the waiting time shorter, e.g. 1 second, i can hear two beeps.
  
  I use a computer running Kubuntu (Linux kernel 4.4).
  The firmware version of the brick is V1.09H,
  the hardware version is V0.60
  
  Maybe i did something wrong with my Bluetooth setup on Linux, but the Bluetooth connection was successful for
  
  Some comments and observations:
  
  * very similar behavior can be observed when connecting using the Matlab support package for EV3 and Bluetooth
  * similar behavior can be observed when using a motor (using Matlab)
  * sometimes it works (i.e. i hear two beeps) with a waiting time of 1.7 seconds, sometimes it fails for a shorter time (e.g. 1.5 seconds), so it is not completely deterministic
  * starting the connection with `open()` takes a few seconds, so it would not be possible to re-open /dev/rfcomm0 for every command
  * i cannot circumvent the problem by sending a command every 0.5 seconds. In this case, the brick still does not produce beep tones after roughly 1.7 seconds (starting from when the fopen() command finished). So it is not just a simple timeout if there is no data.
  * on the EV3 brick the Bluetooth connection is marked as "connected" until f.close() is executed or the python script has completed. The same connection status can be observed using bluetoothctl on Linux.
  
  **Tags:** ev3, mindstorms, programming, bluetooth, remote-control
  
  > **Comments:**
  > **username_1**: I know the problem is already solved, but there is a new firmware version which I think is 1.10E. Updating could also help.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2018-05-03. Score: 1 | Accepted answer
  
  `rfcomm` is an old and deprecated tool, so I'm not going to try to figure out what exactly is going on. I suspect that it has to do with the fact that it treats the connection as a TTY and it is sending extra characters to the EV3 that messes up the communication protocol. I tried adding:
  
  ```
  import tty
  
  ...
  
  tty.setraw(f.fileno())
  
  ```
  
  to the program to fix this, but it does not seem to work.
  
  Instead, I would recommend just using Bluetooth sockets in your python program instead of using the `rfcomm` command line tool. Here is a working example:
  
  ```
  #!/usr/bin/env python3
  
  import time
  
  import bluetooth
  
  # change to *your* EV3 Bluetooth address
  BDADDR = "00:16:53:00:00:00"
  PORT = 1
  
  # beep with 1% volume at 500 hz for .5 seconds
  BEEP_CODE = b'\x0f\x00\x00\x00\x80\x00\x00\x94\x01\x81\x01\x82\x0b\x02\x82\xf4\x01'
  
  sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
  sock.connect((BDADDR, PORT))
  sock.send(BEEP_CODE)
  time.sleep(1.7)
  sock.send(BEEP_CODE)
  sock.close()
  
  ```
  
  > **Comments:**
  > **username_0**: This worked for me. However, i am still looking for a solution which makes it possible to use the matlab packages, which seem to require serial communication. Thanks!  
  
  ---
  
  