Trouble receiving binary stream data with recv()

I've been writing this FOTA solution that would work together with an existing server we use together with Onomondo connectors.

And I've been running into this issue when I'm trying to download a firmware bin file, when I try to use the recv function to retrieve the data, I'll get a few bytes that make sense, the starter byte for example, and then in between there's a loop of `239 191 189` bytes just repeating hundreds of times.

When I've tested the output from the server through Postman or just by URL, it appears to work correctly and returns the file. I am however able to return the bytes in a string format and then convert them on the device, although it's a very slow operation.

I've also setup logging on the server to verify the data that's supposedly being returned to the nrf9160, and that also appears to be correct?

Parents Reply Children
  • To view your modem traces, I converted them to .pcapng using the Modem Trace tool.
    Then I open .pcapng in Wireshark.

    For the app_update.bin, I use the command-line tool hexyl to look at the data.

    Here are two screenshots from Wireshark and hexyl:

    The "broken" trace:

    app_update.bin:

    As you can see from the data, both start with "3d" and then differ slightly.
    I suspect this is because you have sent me the wrong app_update.bin from the one used in your trace.
    Either way, both have "02 00 00 00 00 00 etc" as well, so the start of both these look fine so far.

    However, after a little bit, the trace repeats "ef bd bd ef bf bd" and so on.
    When I inspect packets further down where the data start to repeat, I get all "ef bd db" repeating.
    If you convert this to decimal, it is likely the data you get repeating.

    I googled this and found a post on stack overflow: https://stackoverflow.com/questions/38018263/what-is-the-format-or-encoding-of-a-file-with-data-like-this.

    From this, I suggest you have another look at how you encode the binary file when you transfer it.
    I am not experienced in nodejs express server, but you put "utf-8" into the send function. Maybe do something else here?

    From the working hex-string trace, I can read data which is not these "illegal utf-8" bytes from the pcapng.
    I think this is because when you send a string, the string is "utf-8".

    Does this help?

    Regards,
    Sigurd Hellesvik

  • It is in fact the same app_update.bin, the first 4 bytes when you compile the firmware in a sort of identifier, so 3D B8 F3 96 is an ID for MCUBoot Application Image, so I think even if the app_update.bin were different it should still start with that.

    I tried every single encoding type that the express server supported and none of them worked, but I have been in touch with Onomondo's support, and although they don't think they're the cause of the issue either, I tried disabling the connector and just using regular HTTP/s requests and that actually works as expected!

    So for now I'll just have to use regular requests and avoid the connector system when sending binary data. 

    Thank you for the support!

Related