<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Trouble receiving binary stream data with recv()</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/96730/trouble-receiving-binary-stream-data-with-recv</link><description>I&amp;#39;ve been writing this FOTA solution that would work together with an existing server we use together with Onomondo connectors. 
 And I&amp;#39;ve been running into this issue when I&amp;#39;m trying to download a firmware bin file, when I try to use the recv function</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 07 Mar 2023 13:36:12 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/96730/trouble-receiving-binary-stream-data-with-recv" /><item><title>RE: Trouble receiving binary stream data with recv()</title><link>https://devzone.nordicsemi.com/thread/413849?ContentTypeID=1</link><pubDate>Tue, 07 Mar 2023 13:36:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:759e0d8e-90f9-4138-9f5a-bc4d0e0a46a1</guid><dc:creator>-Richard-</dc:creator><description>&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;I tried every single encoding type that the express server supported and none of them worked, but I have been in touch with Onomondo&amp;#39;s support, and although they don&amp;#39;t think they&amp;#39;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!&lt;/p&gt;
&lt;p&gt;So for now I&amp;#39;ll just have to use regular requests and avoid the connector system when sending binary data.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thank you for the support!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trouble receiving binary stream data with recv()</title><link>https://devzone.nordicsemi.com/thread/412800?ContentTypeID=1</link><pubDate>Wed, 01 Mar 2023 15:25:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:541cb59a-0040-4aa5-b791-7a7e056d528b</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;To view your modem traces, I converted them to .pcapng using the Modem Trace tool.&lt;br /&gt;Then I open .pcapng in Wireshark.&lt;/p&gt;
&lt;p&gt;For the app_update.bin, I use the command-line tool hexyl to look at the data.&lt;/p&gt;
&lt;p&gt;Here are two screenshots from Wireshark and hexyl:&lt;/p&gt;
&lt;p&gt;The &amp;quot;broken&amp;quot; trace:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1677683810058v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;app_update.bin:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1677683855810v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;As you can see from the data, both start with &amp;quot;3d&amp;quot; and then differ slightly.&lt;br /&gt;I suspect this is because you have sent me the wrong app_update.bin from the one used in your trace.&lt;br /&gt;Either way, both have &amp;quot;02 00 00 00 00 00 etc&amp;quot; as well, so the start of both these look fine so far.&lt;/p&gt;
&lt;p&gt;However, after a little bit, the trace repeats &amp;quot;ef bd bd ef bf bd&amp;quot; and so on.&lt;br /&gt;When I inspect packets further down where the data start to repeat, I get all &amp;quot;ef bd db&amp;quot; repeating. &lt;br /&gt;If you convert this to decimal, it is likely the data you get repeating.&lt;/p&gt;
&lt;p&gt;I googled this and found a post on stack overflow: &lt;a href="https://stackoverflow.com/questions/38018263/what-is-the-format-or-encoding-of-a-file-with-data-like-this"&gt;https://stackoverflow.com/questions/38018263/what-is-the-format-or-encoding-of-a-file-with-data-like-this&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;From this, I suggest you have another look at how you encode the binary file when you transfer it.&lt;br /&gt;I am not experienced in nodejs express server, but you put &amp;quot;utf-8&amp;quot; into the send function. Maybe do something else here?&lt;/p&gt;
&lt;p&gt;From the working hex-string trace, I can read data which is not these &amp;quot;illegal utf-8&amp;quot; bytes from the pcapng.&lt;br /&gt;I think this is because when you send a string, the string is &amp;quot;utf-8&amp;quot;.&lt;/p&gt;
&lt;p&gt;Does this help?&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Sigurd Hellesvik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trouble receiving binary stream data with recv()</title><link>https://devzone.nordicsemi.com/thread/412363?ContentTypeID=1</link><pubDate>Mon, 27 Feb 2023 21:32:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3b1ca3eb-e33f-446b-9434-22d705699135</guid><dc:creator>-Richard-</dc:creator><description>&lt;p&gt;Here&amp;#39;s the bin file that&amp;#39;s on the server&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/4722.app_5F00_update.bin"&gt;devzone.nordicsemi.com/.../4722.app_5F00_update.bin&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This is how I read the data from the socket on the nrf9160, both string formatted and binary.&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt="Function to read incoming bytes" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/Screenshot-2023_2D00_02_2D00_27-at-6.58.18-PM.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The IP being 1.2.3.4 is correct, we use Onomondo connectors to send and receive our data, and we configure on their dashboard where the data will be sent. You can&amp;nbsp;read more about it here&amp;nbsp;&lt;a title="Intro to onomondo connector" href="https://onomondo.com/help-center/setting-up/connectors/how-do-i-use-connectors/"&gt;Onomondo Connectors&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s how the&amp;nbsp;nodejs express server returns the bin currently, where response is just an array of the bytes.&lt;/p&gt;
&lt;p&gt;Binary version&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt="Data sent in binary form" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/Screenshot-2023_2D00_02_2D00_27-at-9.42.04-PM.png" /&gt;&lt;/p&gt;
&lt;p&gt;Hex string version&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt="Data sent in a hex string format" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/Screenshot-2023_2D00_02_2D00_27-at-9.41.57-PM.png" /&gt;&lt;/p&gt;
&lt;p&gt;When I test this in Postman or download it directly to my computer through the API it works with the binary version, but when I try to download on the NRF9160 I get the wrong bytes, although when I convert it to a string in a hex format I then receive it correctly.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Modem trace with string formatting.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/trace_2D00_2023_2D00_02_2D00_27T21_2D00_26_2D00_23.459Z.bin"&gt;devzone.nordicsemi.com/.../trace_2D00_2023_2D00_02_2D00_27T21_2D00_26_2D00_23.459Z.bin&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/trace_2D00_2023_2D00_03_2D00_01T12_2D00_15_2D00_56.056Z.bin"&gt;devzone.nordicsemi.com/.../trace_2D00_2023_2D00_03_2D00_01T12_2D00_15_2D00_56.056Z.bin&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trouble receiving binary stream data with recv()</title><link>https://devzone.nordicsemi.com/thread/412306?ContentTypeID=1</link><pubDate>Mon, 27 Feb 2023 14:18:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:521f5805-788b-4183-8b6b-b944d5bc619a</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;I have still been unable to find what this could be, so I will keep asking for info.&lt;/p&gt;
&lt;p&gt;Can you send the file you are trying to transfer?&lt;br /&gt;Can you list the functions on the nRF9160 you use to receive the data?&lt;/p&gt;
&lt;p&gt;From your modem trace, it looks like your server has the IP 1.2.3.4. This seems a bit odd to me. Does your server actually have the IP 1.2.3.4, or is something else happening here?&lt;/p&gt;
&lt;p&gt;Since it works when you send the data as strings, can you list how the send function looks with and without the string formatting?&lt;br /&gt;And can you take a modem trace with the string formatting? It could be useful to compare the good VS bad modem traces.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Sigurd Hellesvik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trouble receiving binary stream data with recv()</title><link>https://devzone.nordicsemi.com/thread/412245?ContentTypeID=1</link><pubDate>Mon, 27 Feb 2023 11:55:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:57d6bd43-bebd-48de-8c28-498913ab2184</guid><dc:creator>-Richard-</dc:creator><description>&lt;p&gt;The modem firmware version is&amp;nbsp;&lt;span&gt;mfw_nrf9160_1.3.3&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trouble receiving binary stream data with recv()</title><link>https://devzone.nordicsemi.com/thread/411667?ContentTypeID=1</link><pubDate>Thu, 23 Feb 2023 13:16:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:80c196aa-6f45-4317-9a83-c1e8d00b9ba5</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Which modem firmware version do you use?&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Sigurd Hellesvik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trouble receiving binary stream data with recv()</title><link>https://devzone.nordicsemi.com/thread/411176?ContentTypeID=1</link><pubDate>Tue, 21 Feb 2023 16:16:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:06bf7d81-5d97-421b-972d-67a08d6a3b9e</guid><dc:creator>-Richard-</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/8357.modem_2D00_trace.zip"&gt;devzone.nordicsemi.com/.../8357.modem_2D00_trace.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;There&amp;#39;s a modem trace for 2 of the ports, as 2 of them seemed to read something and I wasn&amp;#39;t sure which port exactly was the right one.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trouble receiving binary stream data with recv()</title><link>https://devzone.nordicsemi.com/thread/410936?ContentTypeID=1</link><pubDate>Mon, 20 Feb 2023 14:31:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e3ceb469-5922-4cc1-b510-627977e85ba1</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;Can you record and upload a &lt;a href="https://infocenter.nordicsemi.com/topic/ug_trace_collector/UG/trace_collector/intro.html"&gt;modem trace&lt;/a&gt;?&lt;/p&gt;
&lt;p&gt;This may give us more insight into the issue.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Sigurd Hellesvik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trouble receiving binary stream data with recv()</title><link>https://devzone.nordicsemi.com/thread/410590?ContentTypeID=1</link><pubDate>Fri, 17 Feb 2023 10:28:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:80ce5818-b64c-4e8d-9a49-32e3351e97c2</guid><dc:creator>-Richard-</dc:creator><description>&lt;p&gt;Yes it returns success for both bytes, I recv chunks of 2048 bytes at a time, and in there I&amp;#39;ll have a mix of both.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I use a NodeJS express server, and if I return a binary buffer, that&amp;#39;s when the NRF9160 gets the wrong bytes, however if I take that buffer and say turn it into a string or a hex string on the server before returning it, then I receive the data in string format correctly on the NRF9160.&lt;/p&gt;
&lt;p&gt;Appears to only happen when I try to recv a binary buffer on the NRF9160 from the express server, as I&amp;#39;ve tried with other formats such as JSON, and that gets handled correctly.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trouble receiving binary stream data with recv()</title><link>https://devzone.nordicsemi.com/thread/410527?ContentTypeID=1</link><pubDate>Fri, 17 Feb 2023 08:08:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:83949b08-2a42-4fe9-aa96-ffc9069231e1</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>[quote user=""] I try to use the recv&amp;nbsp;function[/quote]
&lt;p&gt;Do you check the return value of the recv() function?&lt;br /&gt;Does it return success both for the &amp;quot;good bytes&amp;quot; and the &amp;quot;bad bytes&amp;quot;?&lt;/p&gt;
[quote user=""] I am however able to return the bytes in a string format and then convert them on the device, although it&amp;#39;s a very slow operation.[/quote]
&lt;p&gt;Is this for the server or the nRF9160?&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Sigurd Hellesvik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trouble receiving binary stream data with recv()</title><link>https://devzone.nordicsemi.com/thread/410435?ContentTypeID=1</link><pubDate>Thu, 16 Feb 2023 15:30:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1e8f78f5-42fa-4fcb-b656-52bd39ff3893</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I will look into this and return with more information tomorrow.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Sigurd Hellesvik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>