通过蓝牙发送 15 000 字节 Python - Java

Send 15 000 bytes by bluetooth Python - Java

我想使用 RFCOMM 协议通过蓝牙发送 15000 个字符(或 15000 个字节)。

我用它在 python 上发送数据:

from pylab import*
from rtlsdr import*
from bluetooth import*
import sys

#configure device
sdr= RtlSdr()
sdr.sample_rate=double(sys.argv[3])
sdr.gain=double(sys.argv[2])
sdr.center_freq=double(sys.argv[1])
NFFT=50

#Bluetooth connection

server_sock=BluetoothSocket(RFCOMM)
server_sock.bind(("",PORT_ANY))
server_sock.listen(1)

port=server_sock.getsockname()[1]
uuid="94f39d29-7d6d-437d-973b-fba39e49d4ee"
client_sock,client_info=server_sock.accept()

while(1):
        samples=sdr.read_samples(256*1024)
        result=psd(samples,NFFT, Fs=sdr.sample_rate/1e6,    Fc=sdr.center_freq*1e6/1e6)
        tab_freq=(result[1]/1e6) 
        value_freq=str(tab_freq)[1:-1]
        value_list=[format(float(v), ".10f") for v in value_freq.split()]
        value_freq2= "\n".join(value_list)
        tab_pxx=result[0]
        value_pxx=str(tab_pxx)[1:-1]
        client_sock.send(value_freq2+'\n'+'\n'.join(value_pxx.split()))

这是为了获取有关 java 的数据:

public void run() {
            byte[] buffer = new byte[1048576]; // 20 bits
            int bytes;
            String strRx = "";

            while (running) {
                try {
                    bytes = connectedInputStream.read(buffer);
                    final String strReceived_freq = new String(buffer,0, bytes);
                    final String strReceived_pxx = new String(buffer,(bytes/2)+1, bytes);
                    //final int samples_sdr=new Integer(buffer,0,bytes);
                    final String strByteCnt = String.valueOf(bytes) + " bytes received.\n";

                    runOnUiThread(new Runnable(){

                        @Override
                        public void run() {
                                Pxx_value.setText(strReceived_pxx+"\n");    // get data PXX
                                freq_value.setText(strReceived_freq+"\n"); // get data freq

                            // plot value
                          /*  for (int i=0; i<nb_points; i++)
                            {
                                freq[i]=Double.parseDouble(strReceived_freq);
                                pxx[i]=Double.parseDouble(strReceived_pxx);
                                series.appendData(new DataPoint(freq[i],pxx[i]), true,500);
                            }*/

                        }});

问题,在 33 点 (NFFT) 之后,我无法发送更多数据,所以我的代码正在重写并擦除我最后的数据...

我该如何解决?

感谢您的帮助!

终于找到原因了。 Raspberry PI 配备蓝牙 4.1,每个数据包长度 最多可以发送 33 个字节。如果你想获得更多,你需要升级你的蓝牙版本(蓝牙 4.2 最多可以发送 257 字节的数据包长度)。

来源:http://www.cypress.com/file/224826/download