mqtt_udp
mqtt_udp copied to clipboard
Packet examples
feature
Is it possible to add some package examples as specifications? This would be very useful to use in tests to validate package encoding and decoding. Especially due to variable-length quantities (VLQ) and little/big endian conversions. By having a set of package samples as HEX makes it very easy to write tests.
At the moment the only way to test is to have for example the java version test against another language. This is not ideal as it requires that environment to be setup.
Only the basic frame
Data:
Length: 11 / 0x0B (1+5+5)
Topic: topic
[5] (74-6F-70-69-63
)
Payload: bytes
[5] (62-79-74-65-73
)
30-0B-05-74-6F-70-69-63-62-79-74-65-73
With all TTR's
Data:
Length: 11 / 0x0B (1+5+5)
Topic: topic
[5] (74-6F-70-69-63
)
Payload: bytes
[5] (62-79-74-65-73
)
TTR:
-
m
Measured at: 2020-06-01 (1590969600000) -
n
Sequence number: 1 -
p
Sent at: 2020-06-02 (1591056000000) -
s
Md5 Hash
30-0B-05-74-6F-70-69-63-62-79-74-65-73
6D-08-00-00-01-72-6D-2D-88-00
6E-08-00-00-00-00-00-00-00-01
70-08-00-00-01-72-72-53-E4-00
73-10-BC-5C-F2-41-FD-6B-3B-CD-EA-65-7E-C6-89-31-AF-DE
The numbers are all big-endian.
There are cross-tests in test/runner subdir which test each of java/python/lua/c implementations against each other. You can use it as a guideline to test your implementation against any other one, or, for example, test all but java one by removing lines from runAll
function.
def runAll(param):
# Runs waiter which listens for given topic/value, then
# runs talker which PUBLISHes same topic/value, then waits
# for waiter to complete
Waiter("py", "lua", param).test()
Waiter("c", "lua", param).test()
Waiter("lua", "lua", param).test()
Waiter("java", "lua", param).test()
Waiter("py", "py", param).test()
Waiter("c", "py", param).test()
Waiter("lua", "py", param).test()
Waiter("java", "py", param).test()
Waiter("py", "c", param).test()
Waiter("c", "c", param).test()
Waiter("lua", "c", param).test()
Waiter("java", "c", param).test()
Waiter("py", "java", param).test()
Waiter("c", "java", param).test()
Waiter("lua", "java", param).test()
Waiter("java", "java", param).test()
Just remove all lines with java
if you don't want to test against it.
@dzavalishin I don't have any of them :-). Having test messages as Hex, Base64 or just as bin files would be very useful for testing.
So you're implementing MQTT/UDP in some other language? You can use MqttUdpViever.jar as a test bench. There's a binary in tools/viewer (you will need jre for it to run, it's free) and it is able both send messages and monitor traffic.
Please take a look at docs: https://mqtt-udp.readthedocs.io/en/latest/#traffic-viewer
It will work on Windows/MacOS/Linux (tested) and probably FreeBSD too.
I'm far from my main development env right now, sorry, and can't make different binary examples.
Here is packet as generated by lang/c/mqtt_udp_clock:
0x30 0x23 0x00 0x0e 0x24 0x53 0x59 0x53 0x2f 0x6c 0x6f 0x63 0x61 0x6c 0x74 0x69 0x6d 0x65 0x32 0x30 0x32 0x30 0x2f 0x30 0x36 0x2f 0x31 0x31 0x20 0x31 0x33 0x3a 0x31 0x38 0x3a 0x32 0x34 0x6e 0x04 0x00 0x00 0x00 0x00
Hope it will help.
Here is another one: 0x30 0x16 0x00 0x0f 0x4c 0x75 0x61 0x20 0x53 0x65 0x6e 0x64 0x65 0x72 0x20 0x54 0x65 0x73 0x74 0x48 0x65 0x6c 0x6c 0x6f
It is sent with Lua code and must be simplest. There are no TTRs.
I'm implementing it in c#, its already done but I just need to verify if I'm generating the packet correctly and then I'll push it to a public repo.
That's great! What toolchain is used to bulid it?
An is it possible to test it against MqttUdpViewer?
0x30 0x23 0x00 0x0e 0x24 0x53 0x59 0x53 0x2f 0x6c 0x6f 0x63 0x61 0x6c 0x74 0x69 0x6d 0x65 0x32 0x30 0x32 0x30 0x2f 0x30 0x36 0x2f 0x31 0x31 0x20 0x31 0x33 0x3a 0x31 0x38 0x3a 0x32 0x34 0x6e 0x04 0x00 0x00 0x00 0x00
Isn't topic length variable length encoded? It seems that topic in most cases will we within 128 characters? Thanks for this packet as that uncovered at least this bug.
I don't have java on my machine which seems to be required for MqttUdpViewer. Installed java, but the application is not starting. Tried running it in a VM but that is not part of the same network as the host and not receiving the udp packets.
Ok, pushed my .net version here https://github.com/ramonsmits/MqttUdpNet
Got MqttUdpViewer up and running and it is displaying my message but my lib seems to fail on the subscribe packet so will have to diagnose it somewhere this weekend.