Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Bluetooth low Energy: Sensor Data is split up using QByteArray

Bluetooth low Energy: Sensor Data is split up using QByteArray

Scheduled Pinned Locked Moved Solved General and Desktop
bluetooth low esensor readingsbytearraycontainers
7 Posts 3 Posters 795 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TUStudi
    wrote on 22 Feb 2020, 11:50 last edited by
    #1

    Hello guys,

    I am creating a Desktop Application for sending data from a sensor to the pc using Qt Bluetooth Low Energy. Using Arduino I am sending 12 bytes of data in every one second. The data I am sending every second consist of traxial acceleration and gyroscope data.
    Every time, when the data changes, the application gets notified via SLOT:

    void MainWindow::updateData(const QLowEnergyCharacteristic &c,const QByteArray &value){
       ui->dataList->addItem(value);
       ui->dataList->scrollToBottom();
    }
    

    The problem is, that the data is split up in several parts (up to 3 lines that are displayed every second in my listwidget but i expect only one line with the whole data).

    For example I expect to receive 12345678912345678912 in one line, but the data is split up to
    123456789123
    456789
    12

    What could be the problem? Maybe my data container the QByteArray has some limitations? Because on another app from the manufacturer of the development board I am using to send the data, the data are sent like expected (one line every second).

    P C 2 Replies Last reply 22 Feb 2020, 14:25
    0
    • T Offline
      T Offline
      TUStudi
      wrote on 22 Feb 2020, 19:22 last edited by
      #7

      Okay, I have solved the problem with a workaround: In the code for my development board I added a new line character after every value.
      Then, in my Qt code I check every time the SLOT is called if the value does have a new line char.
      Either the value is saved in another variable until it receives a value with a new line character or it is output immediately (if it has a new line character).

      static QString newValue= "";
      
      void MainWindow::updateData(const QLowEnergyCharacteristic &c,const QByteArray &value)
      {
          newValue = newValue + (QString)value;
          if (newValue.contains("\n") || newValue.contains("\r")){
                  ui->dataList->addItem(newValue.simplified());
                  ui->dataList->scrollToBottom();
              newValue = "";
          }
      }
      
      1 Reply Last reply
      0
      • T TUStudi
        22 Feb 2020, 11:50

        Hello guys,

        I am creating a Desktop Application for sending data from a sensor to the pc using Qt Bluetooth Low Energy. Using Arduino I am sending 12 bytes of data in every one second. The data I am sending every second consist of traxial acceleration and gyroscope data.
        Every time, when the data changes, the application gets notified via SLOT:

        void MainWindow::updateData(const QLowEnergyCharacteristic &c,const QByteArray &value){
           ui->dataList->addItem(value);
           ui->dataList->scrollToBottom();
        }
        

        The problem is, that the data is split up in several parts (up to 3 lines that are displayed every second in my listwidget but i expect only one line with the whole data).

        For example I expect to receive 12345678912345678912 in one line, but the data is split up to
        123456789123
        456789
        12

        What could be the problem? Maybe my data container the QByteArray has some limitations? Because on another app from the manufacturer of the development board I am using to send the data, the data are sent like expected (one line every second).

        P Offline
        P Offline
        Pl45m4
        wrote on 22 Feb 2020, 14:25 last edited by Pl45m4
        #2

        @TUStudi said in Bluetooth low Energy: Sensor Data is split up using QByteArray:

        For example I expect to receive 12345678912345678912 in one line, but the data is split up to
        123456789123
        456789
        12

        Are these three lines one item or is the data split into three items?
        What happens, if you resize your window? Maybe it's just a word wrap issue.

        Does your data contain newline characters (e.g. \n = 10 = 0x0A)?


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        T 1 Reply Last reply 22 Feb 2020, 14:55
        0
        • P Pl45m4
          22 Feb 2020, 14:25

          @TUStudi said in Bluetooth low Energy: Sensor Data is split up using QByteArray:

          For example I expect to receive 12345678912345678912 in one line, but the data is split up to
          123456789123
          456789
          12

          Are these three lines one item or is the data split into three items?
          What happens, if you resize your window? Maybe it's just a word wrap issue.

          Does your data contain newline characters (e.g. \n = 10 = 0x0A)?

          T Offline
          T Offline
          TUStudi
          wrote on 22 Feb 2020, 14:55 last edited by
          #3

          Are these three lines one item or is the data split into three items?
          What happens, if you resize your window? Maybe it's just a word wrap issue.

          Does your data contain newline characters (e.g. \n = 10 = 0x0A)?

          @Pl45m4 Thanks for your response.
          No, these three lines should be one item. because on my development board, where the data comes from, I made a test by sending the "123456789123" every second so I expect my GUI Application in Qt to print 123456789123 in one line as one item but it is sending it in 2 or 3 parts as I mentioned above.
          I tried to resize the window and the list Widget but it seems that this is not the problem.
          Before adding the items to the List I tried to figure out the size of the value that I receives from the QByteArray and it seems that the data is split up the in ByteArray because the output of value.size() of 12345678912345678912 should be 20 but the output is

          // output of  value.size()
          12
          6
          2
          

          whch is in total 20. So I think maybe the problem is the QByteArray? I don't think that it is the code of my development board because as I mentioned before on another app from the manufacturer the data are not split up..
          An no I do not have any new line characters.

          P 1 Reply Last reply 22 Feb 2020, 15:35
          0
          • T TUStudi
            22 Feb 2020, 14:55

            Are these three lines one item or is the data split into three items?
            What happens, if you resize your window? Maybe it's just a word wrap issue.

            Does your data contain newline characters (e.g. \n = 10 = 0x0A)?

            @Pl45m4 Thanks for your response.
            No, these three lines should be one item. because on my development board, where the data comes from, I made a test by sending the "123456789123" every second so I expect my GUI Application in Qt to print 123456789123 in one line as one item but it is sending it in 2 or 3 parts as I mentioned above.
            I tried to resize the window and the list Widget but it seems that this is not the problem.
            Before adding the items to the List I tried to figure out the size of the value that I receives from the QByteArray and it seems that the data is split up the in ByteArray because the output of value.size() of 12345678912345678912 should be 20 but the output is

            // output of  value.size()
            12
            6
            2
            

            whch is in total 20. So I think maybe the problem is the QByteArray? I don't think that it is the code of my development board because as I mentioned before on another app from the manufacturer the data are not split up..
            An no I do not have any new line characters.

            P Offline
            P Offline
            Pl45m4
            wrote on 22 Feb 2020, 15:35 last edited by
            #4

            @TUStudi said in Bluetooth low Energy: Sensor Data is split up using QByteArray:

            the output is
            // output of value.size()
            12
            6
            2

            This contradicts

            @TUStudi said in Bluetooth low Energy: Sensor Data is split up using QByteArray:

            No, these three lines should be one item

            with this.

            You said the update-slot is called every second. So you add a new item (containing value) to your QListWidget. If you debug value.size() in this slot and it returns 12, 6, 2 it can not be one item (because a ByteArray has just one size)?!
            So your update slot got called multiple times


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            0
            • T TUStudi
              22 Feb 2020, 11:50

              Hello guys,

              I am creating a Desktop Application for sending data from a sensor to the pc using Qt Bluetooth Low Energy. Using Arduino I am sending 12 bytes of data in every one second. The data I am sending every second consist of traxial acceleration and gyroscope data.
              Every time, when the data changes, the application gets notified via SLOT:

              void MainWindow::updateData(const QLowEnergyCharacteristic &c,const QByteArray &value){
                 ui->dataList->addItem(value);
                 ui->dataList->scrollToBottom();
              }
              

              The problem is, that the data is split up in several parts (up to 3 lines that are displayed every second in my listwidget but i expect only one line with the whole data).

              For example I expect to receive 12345678912345678912 in one line, but the data is split up to
              123456789123
              456789
              12

              What could be the problem? Maybe my data container the QByteArray has some limitations? Because on another app from the manufacturer of the development board I am using to send the data, the data are sent like expected (one line every second).

              C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 22 Feb 2020, 15:46 last edited by
              #5

              @TUStudi said in Bluetooth low Energy: Sensor Data is split up using QByteArray:

              Every time, when the data changes, the application gets notified via SLOT:

              Do oyu call this slot? From where is it called?

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              T 1 Reply Last reply 22 Feb 2020, 16:21
              0
              • C Christian Ehrlicher
                22 Feb 2020, 15:46

                @TUStudi said in Bluetooth low Energy: Sensor Data is split up using QByteArray:

                Every time, when the data changes, the application gets notified via SLOT:

                Do oyu call this slot? From where is it called?

                T Offline
                T Offline
                TUStudi
                wrote on 22 Feb 2020, 16:21 last edited by TUStudi
                #6

                @Christian-Ehrlicher

                void MainWindow::on_callCharacteristic_clicked()
                {
                    readChar = uartService->characteristic(QBluetoothUuid(QUuid("6e400003-b5a3-f393-e0a9-e50e24dcca9e")));
                    QLowEnergyDescriptor  descript = readChar.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
                    uartService->writeDescriptor(descript, QByteArray::fromHex("0100"));
                
                    connect(uartService, SIGNAL(characteristicChanged(QLowEnergyCharacteristic,QByteArray)),
                            this, SLOT(updateData(QLowEnergyCharacteristic,QByteArray)));
                }
                

                When a button is clicked in the GUI this method is called. And as @Pl45m4 outlined the update slot is calling multiple times (sorry for the confusing description):

                void MainWindow::updateData(const QLowEnergyCharacteristic &c,const QByteArray &value){
                   ui->dataList->addItem(value);
                   ui->dataList->scrollToBottom();
                }
                

                So every time the characteristic c changes (means whenever there is a new sensor value) this SLOT is called.
                Here is the output from my QT GUI App:

                5dd78fbe-4b72-4556-9746-5658dd6fc8cc-image.png

                and I expect this (the whole time):

                c730c708-3ed6-4bff-bca0-7f041818463b-image.png

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  TUStudi
                  wrote on 22 Feb 2020, 19:22 last edited by
                  #7

                  Okay, I have solved the problem with a workaround: In the code for my development board I added a new line character after every value.
                  Then, in my Qt code I check every time the SLOT is called if the value does have a new line char.
                  Either the value is saved in another variable until it receives a value with a new line character or it is output immediately (if it has a new line character).

                  static QString newValue= "";
                  
                  void MainWindow::updateData(const QLowEnergyCharacteristic &c,const QByteArray &value)
                  {
                      newValue = newValue + (QString)value;
                      if (newValue.contains("\n") || newValue.contains("\r")){
                              ui->dataList->addItem(newValue.simplified());
                              ui->dataList->scrollToBottom();
                          newValue = "";
                      }
                  }
                  
                  1 Reply Last reply
                  0

                  7/7

                  22 Feb 2020, 19:22

                  • Login

                  • Login or register to search.
                  7 out of 7
                  • First post
                    7/7
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved