BLE: sending data to device



  • Hello.

    i'm asking myself if this is the way to send data to a BLE device:

    void BLESerialDevice::writeData(const QByteArray& data) {
    
        // get 20 bytes (?) to send
        dataSending = data.left(20);
        dataLeftToSend = data.right(data.size()-20);
    
        m_service->writeCharacteristic(writeCharacteristic, dataSending, QLowEnergyService::WriteWithResponse);
    }
    
    void BLESerialDevice::mycharacteristicWritten(const QLowEnergyCharacteristic &info, const QByteArray &value) {
        // checks removed (compare value to dataSending, etc)
    
        // write next 20 bytes
        writeData(dataLeftToSend);
    }
    
    ...
    
    // get data and write it out
    void doSendData() {
        QByteArray data = getSomeData();
        MyBLESerialDevice.writeData(data);
    }
    

    sending data with this method transmits all the bytes, only the data-rate if pretty low:

    sent  2429 bytes  in  9243  ms  =  ~263 bytes per seconds
    

    trying to send it in a tight loop would drop data...

    void BLESerialDevice::writeData(const QByteArray& data) {
        int i = 0;
        while (true) {
            dataSending = data.mid(i, 20);
    
            if (dataSending.isEmpty()) break;
    
            m_service->writeCharacteristic(writeCharacteristic, dataSending, QLowEnergyService::WriteWithResponse); 
    
            i += 20;
        };
    }
    

    so i wonder:
    is this (first code-snippet) the way to send data to a BLE device?
    how would the preferred way to write data be?
    how could the data-rate be improved?

    thanks for comments and recommendations
    io



  • @i.n.g.o.
    Hi, the First version is, roughly, the way I do it currently too. You‘re actually faster, because I‘m bound to a Modbus type of protocol that take 8 byte away for a head and Tail.
    😔



  • BLE is not designed to fast data transferring.

    PS: Also many things depends on type of your remote device: who did FW (maybe it has bugs or sleeps), what is a characteristic's properties, what is a HW vendor (TI, NORDIC and etc).



  • thanks for the comments!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.