EV3 does not react to Bluetooth commands after 1.7 seconds
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()