jeelabs / esp-link

esp8266 wifi-serial bridge, outbound TCP, and arduino/AVR/LPC/NXP programmer
Other
2.82k stars 720 forks source link

Last will message not retaining, TCP packet missing retain flag, it's not implemented #392

Closed Rotario closed 4 years ago

Rotario commented 6 years ago

Hi, I've been using the library and it works really well!

Sending messages with retain works perfectly however when the mqtt.lwt method is used, the message does not retain. The retain flag works fine over EL Client connection, and on ESP link the debug page even shows that retain is flagged. However doing some packet sniffing, the actual TCP packet is missing the retain flag. The 04 byte highlighted below should instead be 24 I believe so that retain is flagged. This relates to the flag here, but I've had a look and I can't see where the issue is: https://github.com/jeelabs/esp-link/blob/fe4f565fe83f05e402cc8d8ca3ceefbc39692a1f/mqtt/mqtt_msg.c#L320

I will have a look and try to fix it but I've never built this firmware from source before!

``

    0x0000:  4500 004e 000a 0000 8006 a9b7 c0a8 07b6     E..N............

    0x0010:  c0a8 07e2 74a2 075b 0000 1970 d907 7154     ....t..[...p..qT

    0x0020:  5018 0860 555d 0000 1024 0004 4d51 5454    P..`U]...$..MQTT

    0x0030:  *04*06 003c 0006 6e69 6365 3033 000d 2f73   ...<..nice03../s

    0x0040:  7461 7475 732f 3635 3433 3200 0130         status/65432..0

``

Thanks, Rowan

Rotario commented 6 years ago

OK, think I've found the issue: even though the variable header flags are set correctly, fini_message is called with the retain flag 0 https://github.com/jeelabs/esp-link/blob/fe4f565fe83f05e402cc8d8ca3ceefbc39692a1f/mqtt/mqtt_msg.c#L340

The variable header struct is set up but never used????

fini message method: https://github.com/jeelabs/esp-link/blob/4dcd61714b88c56ca293c2ab3cba86cfb05920db/mqtt/mqtt_msg.c#L104

Rotario commented 4 years ago

Fixed with 99661ca18ae3c3df3a22c00468260ba22f6e5680