QtWebSocket sending binary data with msgpack to ESP32 mcu
-
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 sayscolorPicker
if i send it a 1 or 2 or 3 or any other number i getcolorPicker 1
and it works but for some reason 0 just escapes :S -
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.
-
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.
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(); }
-
So how long is the binary length with 0 and with 1?
Also what is_MsgPackMap
? -
So how long is the binary length with 0 and with 1?
Also what is_MsgPackMap
?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
-
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" -
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"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?
-
@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.
-
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.
@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;
-
@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.
@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
-
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.
-
@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 ?
-
@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 ?