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. QtWebSocket sending binary data with msgpack to ESP32 mcu
Forum Updated to NodeBB v4.3 + New Features

QtWebSocket sending binary data with msgpack to ESP32 mcu

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 3 Posters 1.1k Views 1 Watching
  • 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.
  • K Offline
    K Offline
    Kris Revi
    wrote on last edited by
    #1

    Setup


    Qt Running

    QtWebSockets/QWebSocket
    msgpack ported by (https://github.com/romixlab/qmsgpack)

    ESP32 Running

    WebSocketsServer
    msgpack ported by (https://github.com/hideakitai/MsgPack)

    Outputs


    Qt

    [SOCKET][BINARY][ "colorPicker" ] QVariant(int, 0)
    Binary Data :  "\x81\xAB""colorPicker\x00"
    Binary Length :  14
    

    ESP32

    [HEXDUMP] Address: 0x3FFD4D9C len: 0xE (14)
    [0x3FFD4D9C] 0x00000000: 81 AB 63 6F 6C 6F 72 50 69 63 6B 65 72 00 
    Binary : ��colorPicker
    Payload Length : 14
    

    everything is correct except it wont give me the 0 in colorPicker 0 it just says colorPicker if i send it a 1 or 2 or 3 or any other number i get colorPicker 1 and it works but for some reason 0 just escapes :S

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      How are you showing that data ? I may be wrong but I think you are hitting the usual termination character handling issue. QByteArray is binary data but if you handle its content as string it will be cut at the termination char.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      K 2 Replies Last reply
      2
      • SGaistS SGaist

        Hi,

        How are you showing that data ? I may be wrong but I think you are hitting the usual termination character handling issue. QByteArray is binary data but if you handle its content as string it will be cut at the termination char.

        K Offline
        K Offline
        Kris Revi
        wrote on last edited by
        #3

        @SGaist

        void MainWindow::on_comboBoxSelectStrip_activated(int index)
        {
            qDebug() << "[SelectedStrip][Currently] : " << index;
            sendBinary("selectedstrip", index);
        }
        
        void MainWindow::sendBinary(QString text, QVariant args)
        {
            _MsgPackMap.clear();
            _MsgPackMap.insert(text, args);
            _MsgPackArray = MsgPack::pack(_MsgPackMap);
            _socket.sendBinaryToStrip(_MsgPackArray);
        }
        
        void Socket::sendBinaryToStrip(const QByteArray data)
        {
            m_webSocket.sendBinaryMessage(data);
            qDebug() << "Binary Data : " << data;
            qDebug() << "Binary Length : " << data.size();
        }
        
        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          So how long is the binary length with 0 and with 1?
          Also what is _MsgPackMap?

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

          K 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            So how long is the binary length with 0 and with 1?
            Also what is _MsgPackMap?

            K Offline
            K Offline
            Kris Revi
            wrote on last edited by Kris Revi
            #5

            @Christian-Ehrlicher

            to quote the website of msgpack It's like JSON. but fast and small.

            the variable itself is QVariantMap _MsgPackMap;

            let me check the length and get back to you!

            Edit

            selectedStrip = 0

            [SelectedStrip][Currently] :  0
            Binary Data :  "\x81\xADselectedstrip\x00"
            Binary Length :  16
            

            selectedStrip = 1

            [SelectedStrip][Currently] :  1
            Binary Data :  "\x81\xADselectedstrip\x01"
            Binary Length :  16
            
            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Looks like a problem on the receiver side:

              int main(int argc, char **argv)
              {
                QCoreApplication app(argc, argv);
                QVariantMap  v0, v1;
                v0.insert("selectedstrip", 0);
                v1.insert("selectedstrip", 1);
                qDebug() <<  MsgPack::pack(v0);
                qDebug() <<  MsgPack::pack(v1);
                return 0;
              }
              

              -->
              "\x81\xADselectedstrip\x00"
              "\x81\xADselectedstrip\x01"

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

              K 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                Looks like a problem on the receiver side:

                int main(int argc, char **argv)
                {
                  QCoreApplication app(argc, argv);
                  QVariantMap  v0, v1;
                  v0.insert("selectedstrip", 0);
                  v1.insert("selectedstrip", 1);
                  qDebug() <<  MsgPack::pack(v0);
                  qDebug() <<  MsgPack::pack(v1);
                  return 0;
                }
                

                -->
                "\x81\xADselectedstrip\x00"
                "\x81\xADselectedstrip\x01"

                K Offline
                K Offline
                Kris Revi
                wrote on last edited by
                #7

                @Christian-Ehrlicher

                so on the ESP32 side i printed out msgpack unpacked data and the payload from arduinowebsocket and NONE of them prints out anything when "selectedStrip = 0"

                            if ( mIndata["selectedstrip"] )
                            {
                                Serial.print("selectedstrip : ");
                                Serial.print((int)mIndata["selectedstrip"]);
                                Serial.println(" ");
                                Serial.print("Payload : ");
                                for ( int i = 0; i < length; i++ )
                                    Serial.print(payload[i]);
                                Serial.println(" ");
                
                                _selectedStrip = mIndata["selectedstrip"];
                            }
                
                selectedstrip : 1
                Payload : 129173115101108101991161011001151161141051121 
                selectedstrip : 2
                Payload : 129173115101108101991161011001151161141051122 
                selectedstrip : 3
                Payload : 129173115101108101991161011001151161141051123 
                selectedstrip : 4
                Payload : 129173115101108101991161011001151161141051124 
                

                so i would guess the problem is the arduinowebsocket? or am i wrong?

                1 Reply Last reply
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Kris-Revi said in QtWebSocket sending binary data with msgpack to ESP32 mcu:

                  is the arduinowebsocket?

                  Looks like - QWebSocket::sendBinaryMessage() works correct I would guess.

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

                  K 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Hi,

                    How are you showing that data ? I may be wrong but I think you are hitting the usual termination character handling issue. QByteArray is binary data but if you handle its content as string it will be cut at the termination char.

                    K Offline
                    K Offline
                    Kris Revi
                    wrote on last edited by
                    #9

                    @Christian-Ehrlicher as @SGaist said

                    @SGaist said in QtWebSocket sending binary data with msgpack to ESP32 mcu:

                    QByteArray is binary data but if you handle its content as string it will be cut at the termination char.

                    on the ESP32 side i do this

                    MsgPack::Unpacker unpacker;
                    MsgPack::map_t<String, int> mIndata;
                    
                    1 Reply Last reply
                    0
                    • Christian EhrlicherC Christian Ehrlicher

                      @Kris-Revi said in QtWebSocket sending binary data with msgpack to ESP32 mcu:

                      is the arduinowebsocket?

                      Looks like - QWebSocket::sendBinaryMessage() works correct I would guess.

                      K Offline
                      K Offline
                      Kris Revi
                      wrote on last edited by
                      #10

                      @Christian-Ehrlicher so i printed the payload inside if ( mIndata["selectedstrip"] ) { } moved it outside of that and got a result on "selectedStrip = 0"

                      1

                      selectedstrip : 1 
                      Payload : 1291731141011136810111810599101731101021111
                      

                      0

                      Payload : 129173115101108101991161011001151161141051120
                      

                      notice that msgpack does not print on 0 only payload

                      1 Reply Last reply
                      0
                      • Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        I don't really know how binary data is encoded in websocket (if at all) but what you can do is to create a simple receiver with Qt websocket to see if it properly arrives there and can be decoded.

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

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @Kris-Revi said in QtWebSocket sending binary data with msgpack to ESP32 mcu:

                          if ( mIndata["selectedstrip"] )

                          You know that this if is going to fail if the the value associated with selectedstrip equals 0 ?

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          K 1 Reply Last reply
                          1
                          • SGaistS SGaist

                            @Kris-Revi said in QtWebSocket sending binary data with msgpack to ESP32 mcu:

                            if ( mIndata["selectedstrip"] )

                            You know that this if is going to fail if the the value associated with selectedstrip equals 0 ?

                            K Offline
                            K Offline
                            Kris Revi
                            wrote on last edited by
                            #13

                            @SGaist OH SHIT! i never thought of that xD

                            1 Reply Last reply
                            0

                            • Login

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