# Packet loss when transmitting using Bluetooth

**URL:** https://discourse.processing.org/t/packet-loss-when-transmitting-using-bluetooth/45754
**Category:** Electronics (Arduino, etc.)
**Created:** [February 13, 2025, 3:44pm UTC](https://discourse.processing.org/t/packet-loss-when-transmitting-using-bluetooth/45754 "2025-02-13T15:44:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![cola](https://avatars.discourse-cdn.com/v4/letter/c/77aa72/32.png) [@cola](https://discourse.processing.org/u/cola)
#### Post date: [February 13, 2025, 3:44pm UTC](https://discourse.processing.org/t/packet-loss-when-transmitting-using-bluetooth/45754/1 "2025-02-13T15:44:28Z")

</div>

I use the Bluetooth serial port to transmit data. There is data output but it cannot be output in real time. Because multiple data packets are transmitted, is it because my unpacking process affects the drawing? Here is my parsing code:

```auto
if(CES_Pkt_ID==CES_CMDIF_PKT_ECG_ID){
              ces_pkt_ecg_bytes[0] = CES_Pkt_Data_Counter[0];//ECG
              ces_pkt_ecg_bytes[1] = CES_Pkt_Data_Counter[1];
              ces_pkt_ecg_bytes[2] = CES_Pkt_Data_Counter[2];//Filterecg
              ces_pkt_ecg_bytes[3] = CES_Pkt_Data_Counter[3];
              
              ces_pkt_HR_bytes[0] = CES_Pkt_Data_Counter[4];// HR
              ces_pkt_HR_bytes[1] = CES_Pkt_Data_Counter[5];
              
              ces_pkt_resp_bytes[0] = CES_Pkt_Data_Counter[6];//RESP
              ces_pkt_resp_bytes[1] = CES_Pkt_Data_Counter[7];
              ces_pkt_resp_bytes[2] = CES_Pkt_Data_Counter[8];//FilterRESP
              ces_pkt_resp_bytes[3] = CES_Pkt_Data_Counter[9];
              
              ces_pkt_RR_bytes[0] = CES_Pkt_Data_Counter[10];//RR
              ces_pkt_RR_bytes[1] = CES_Pkt_Data_Counter[11];
              
              int data1 = ces_pkt_ecg_bytes[0] | ces_pkt_ecg_bytes[1]<<8; //reversePacket(CES_Pkt_ECG_Counter, CES_Pkt_ECG_Counter.length-1);
              data1 <<= 16;
              data1 >>= 16;
              rawecg = data1; // ecg,resp, hr,filecg,filresp, rr;  
              
              int data2 = ces_pkt_ecg_bytes[2] | ces_pkt_ecg_bytes[3]<<8; //reversePacket(CES_Pkt_ECG_Counter, CES_Pkt_ECG_Counter.length-1);
              data2 <<= 16;
              data2 >>= 16;
              ecg = data2; // ecg,resp, hr,filecg,filresp, rr;  
              
              int data3 = ces_pkt_HR_bytes[0] | ces_pkt_HR_bytes[1]<<8; //reversePacket(CES_Pkt_ECG_Counter, CES_Pkt_ECG_Counter.length-1);
              data3 <<= 16;
              data3 >>= 16;
              hr = data3; // ecg,resp, hr,filecg,filresp, rr;  
              
              int data4 = ces_pkt_resp_bytes[0] | ces_pkt_resp_bytes[1]<<8; //reversePacket(CES_Pkt_ECG_Counter, CES_Pkt_ECG_Counter.length-1);
              data4 <<= 16;
              data4 >>= 16;
              rawresp = data4; // ecg,resp, hr,filecg,filresp, rr;  
              
              int data5 = ces_pkt_resp_bytes[2] | ces_pkt_resp_bytes[3]<<8; //reversePacket(CES_Pkt_ECG_Counter, CES_Pkt_ECG_Counter.length-1);
              data5 <<= 16;
              data5 >>= 16;
              resp = data5; // ecg,resp, hr,filecg,filresp, rr;  
              
              int data6 = ces_pkt_RR_bytes[0] | ces_pkt_RR_bytes[1]<<8; //reversePacket(CES_Pkt_ECG_Counter, CES_Pkt_ECG_Counter.length-1);
              data6 <<= 16;
              data6 >>= 16;
              rr = data6; // ecg,resp, hr,filecg,filresp, rr;  
              
              ECGLabelText.setText(hr+ " ");
              RESPLabelText.setText(rr + " ");
        }
        else if(CES_Pkt_ID==CES_CMDIF_PKT_GSR_ID){
              ces_pkt_gsr_bytes[0] = CES_Pkt_Data_Counter[0];//gsr
              ces_pkt_gsr_bytes[1] = CES_Pkt_Data_Counter[1];
              
              int data = ces_pkt_gsr_bytes[0] | ces_pkt_gsr_bytes[1]<<8; //reversePacket(CES_Pkt_ECG_Counter, CES_Pkt_ECG_Counter.length-1);
              data <<= 16;
              data >>= 16;
              gsr = data; // ecg,resp, hr,filecg,filresp, rr;  
        }
        // Assigning the values for the graph buffers

        //time = time+1;
        //xdata[arrayIndex] = time;
        ecgdata[arrayIndex] = (float)ecg;
        arrayIndex++;
        respdata[arrayIndex1] = (float) resp;
        arrayIndex1++;
        //filter_GSRdata=GSR.filteredConductance((float) gsr);
        gsrdata[arrayIndex2] = (float) gsr;
        arrayIndex2++;
        
       
        
        if (arrayIndex == pSize)
        {  
          arrayIndex = 0;
          //time = 0; 
        }
        if (arrayIndex1 == pSize)
        {  
          arrayIndex1 = 0;
        }
        if (arrayIndex2 == pSize)
        {  
          arrayIndex2 = 0;
        }

```

---

<div class="post-metadata">

### Author: ![RichardDL](https://avatars.discourse-cdn.com/v4/letter/r/f475e1/32.png) [@RichardDL](https://discourse.processing.org/u/RichardDL)
#### Post date: [February 24, 2025, 9:11pm UTC](https://discourse.processing.org/t/packet-loss-when-transmitting-using-bluetooth/45754/2 "2025-02-24T21:11:34Z")

</div>

Hi @cola, Please would you give an outline description or diagram of the system. What is sending over bluetooth? what triggers the send, and where is that code running? Are messages going both ways?

---

<div class="post-metadata">

### Author: ![cola](https://avatars.discourse-cdn.com/v4/letter/c/77aa72/32.png) [@cola](https://discourse.processing.org/u/cola)
#### Post date: [February 27, 2025, 2:18am UTC](https://discourse.processing.org/t/packet-loss-when-transmitting-using-bluetooth/45754/3 "2025-02-27T02:18:21Z")

</div>

I have solve my problem. Since my data analysis is performed in one thread, the thread is blocked. Although there is data, the data will be lost and the drawing will not be smooth.
