<?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>nRF9160 TCP connection, sending over LTE-M</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/65041/nrf9160-tcp-connection-sending-over-lte-m</link><description>Hello, 
 I&amp;#39;m trying to setup a TCP connection to a remote TCP echo server (echo.u-blox.com : 195.34.89.241, port 7), for testing. 
 The socket is being opened, and I receive a welcome message. However, it seems as if the connection is closed afterwards</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 01 Sep 2020 14:28:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/65041/nrf9160-tcp-connection-sending-over-lte-m" /><item><title>RE: nRF9160 TCP connection, sending over LTE-M</title><link>https://devzone.nordicsemi.com/thread/267491?ContentTypeID=1</link><pubDate>Tue, 01 Sep 2020 14:28:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a30495d2-b6b7-4ac4-9b6e-12461e6d4f81</guid><dc:creator>newUser</dc:creator><description>&lt;p&gt;We are now successfully communicating with our own server. Thank you for your support and patience.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF9160 TCP connection, sending over LTE-M</title><link>https://devzone.nordicsemi.com/thread/267457?ContentTypeID=1</link><pubDate>Tue, 01 Sep 2020 12:10:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7299a963-c91e-40bf-b60f-44c43a750dd1</guid><dc:creator>newUser</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/oyvind-schei"&gt;Øyvind&lt;/a&gt;  Thank you guys. I can also confirm that the U-Blox test server is no longer working according to &lt;a title="U-Blox Echo Server" href="https://www.u-blox.com/sites/default/files/products/documents/TestServerForSocketOperations_AppNote_%28UBX-14005690%29.pdf"&gt;their spec&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I will setup our own server again and report back the latest results, perhaps the code is already working.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF9160 TCP connection, sending over LTE-M</title><link>https://devzone.nordicsemi.com/thread/267396?ContentTypeID=1</link><pubDate>Tue, 01 Sep 2020 08:51:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c2028bea-9e55-40a8-83e0-d64179ae70ea</guid><dc:creator>newUser</dc:creator><description>&lt;p&gt;Hi, no problem! Thank you for getting back to me.&lt;/p&gt;
&lt;p&gt;The current status is that with UDP, everything works fine. With TCP, the server&amp;#39;s welcome message is received, but after that no communication is working anymore. The send() function still returns 0 (success) and the expected number of written bytes (13), but the recv() fails (we would expected the &amp;#39;Hello U-Blox&amp;#39; message to be echoed):&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;Sent: AT+CFUN=1
Received: OK

tcp_socket: 2
connect to 195.34.89.241 err: 0
Received: U-Blox AG TCP/UDP test service
 [31]
Sent: Hello U-Blox [Bytes: 13] [Error: 0]
Receive failed: [Bytes: 0] [Error: 0]
Send failed: 54
Receive failed: [Bytes: -1] [Error: 54]&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;When I test this server with other embedded devices, it is working just fine for both UDP and TCP.&lt;br /&gt;Our own remote management server is also working just fine with these other devices, but we observe the above behavior when connecting from the nRF9160 board.&lt;/p&gt;
&lt;p&gt;The code producing this output:&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;device.h&amp;gt;
#include &amp;lt;drivers/gpio.h&amp;gt;

#include &amp;lt;stdint.h&amp;gt;

#include &amp;lt;net/socket.h&amp;gt;

#include &amp;quot;test.h&amp;quot;

#define TEST_THREAD_PRIORITY 7

#define TCP_HOST &amp;quot;195.34.89.241&amp;quot;
#define TCP_PORT 7
#define RECV_BUF_SIZE 128

static uint8_t recv_buf[RECV_BUF_SIZE];

K_THREAD_STACK_DEFINE(testThreadStack, 2048);
struct k_thread testThread;

static void TestThreadFxn (void);

void TestCreateThread (void)
{
  k_thread_create(&amp;amp;testThread, testThreadStack,
                  K_THREAD_STACK_SIZEOF(testThreadStack),
                  (k_thread_entry_t) TestThreadFxn,
                  NULL, NULL, NULL,
                  TEST_THREAD_PRIORITY, 0, K_NO_WAIT);
}

static void TestThreadFxn (void)
{
  printk(&amp;quot;Starting socket\n&amp;quot;);

  int at_socket_fd = socket(AF_LTE, SOCK_DGRAM, NPROTO_AT);

  if (at_socket_fd &amp;lt; 0)
  {
    printk(&amp;quot;Socket err: %d, errno: %d\r\n&amp;quot;, at_socket_fd, errno);
  }

  char *initCmds[1] = { &amp;quot;AT+CFUN=1&amp;quot; };
  send(at_socket_fd, initCmds[0], strlen(initCmds[0]), 0);
  printk(&amp;quot;Sent: %s\n&amp;quot;, initCmds[0]);

  recv(at_socket_fd, recv_buf, sizeof(recv_buf), 0);
  printk(&amp;quot;Received: %s\n&amp;quot;, recv_buf);

  k_msleep(20000);

  int tcp_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); // SOCK_DGRAM, IPPROTO_UDP
  printk(&amp;quot;tcp_socket: %i\n&amp;quot;, tcp_socket);

  struct sockaddr_in remote_addr;
  remote_addr.sin_family = AF_INET;
  remote_addr.sin_port = htons(TCP_PORT);
  inet_pton(AF_INET, TCP_HOST, &amp;amp;(remote_addr.sin_addr));

  int err = connect(tcp_socket, (struct sockaddr *) &amp;amp;remote_addr, sizeof(remote_addr));
  printk(&amp;quot;connect to %s err: %i\n&amp;quot;, TCP_HOST, err);

  int bytes_received = recv(tcp_socket, recv_buf, sizeof(recv_buf), 0);
  if (bytes_received &amp;gt; 0)
  {
    printk(&amp;quot;Received: %s [%i]\n&amp;quot;, recv_buf, bytes_received);
  }
  else
  {
    printk(&amp;quot;Receive failed: %i\n&amp;quot;, errno);
  }

  for (;;)
  {
    memset(recv_buf, 0, sizeof(recv_buf));

    uint8_t cmd[] = &amp;quot;Hello U-Blox&amp;quot;;

    int bytes_sent = send(tcp_socket, cmd, sizeof(cmd), 0);
    if (bytes_sent &amp;lt; 0)
    {
      printk(&amp;quot;Send failed: %i\n&amp;quot;, errno);
    }
    else
    {
      printk(&amp;quot;Sent: %s [Bytes: %i] [Error: %i]\n&amp;quot;, cmd, bytes_sent, errno);
    }

    int bytes_received = recv(tcp_socket, recv_buf, sizeof(recv_buf), 0);
    if (bytes_received &amp;gt; 0)
    {
      printk(&amp;quot;Received: %s [Bytes: %i]\n&amp;quot;, recv_buf, bytes_received);
    }
    else
    {
      printk(&amp;quot;Receive failed: [Bytes: %i] [Error: %i]\n&amp;quot;, bytes_received, errno);
    }

    k_msleep(5000);
  }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;proj.conf:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#
# Copyright (c) 2019 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#
# General config
CONFIG_ASSERT=y

# Network
CONFIG_NETWORKING=y
CONFIG_NET_NATIVE=n
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y

# BSD library
CONFIG_BSD_LIBRARY=y

# AT host library
CONFIG_AT_HOST_LIBRARY=y
CONFIG_UART_INTERRUPT_DRIVEN=y

# Stacks and heaps
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_HEAP_MEM_POOL_SIZE=32768

# Testing changes
CONFIG_GPIO=y&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF9160 TCP connection, sending over LTE-M</title><link>https://devzone.nordicsemi.com/thread/267383?ContentTypeID=1</link><pubDate>Tue, 01 Sep 2020 08:19:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:00413380-1a12-4938-9746-da86c0bd9d11</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&lt;br /&gt;&lt;br /&gt;My apologies for the late reply. Difficult to see what you have altered in the main post, it&amp;#39;s better to add changes as a comment to the thread. Can you please add prj.conf and main.c ?&lt;/p&gt;
[quote user="MaikASB"]&lt;span&gt;ECONNRESET &amp;quot;Connection reset by peer&amp;quot;&lt;/span&gt;:[/quote]
&lt;p&gt;&lt;span&gt;A connection reset by peer message means that the site you are connected to has reset the connection. This is usually caused by a high amount of traffic on the site, but may be caused by a server error as well.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;What other servers did you try?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF9160 TCP connection, sending over LTE-M</title><link>https://devzone.nordicsemi.com/thread/266680?ContentTypeID=1</link><pubDate>Thu, 27 Aug 2020 09:37:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2711d9df-7e12-49ef-a93c-e14e1955a2f7</guid><dc:creator>newUser</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/oyvind-schei"&gt;Øyvind&lt;/a&gt; I have edited the main post. I would appreciate your input!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF9160 TCP connection, sending over LTE-M</title><link>https://devzone.nordicsemi.com/thread/265758?ContentTypeID=1</link><pubDate>Fri, 21 Aug 2020 11:54:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3e3904b9-164b-4205-b80c-0bd9a805551b</guid><dc:creator>newUser</dc:creator><description>&lt;p&gt;I also tested UDP. This seems to work just fine. Funny thing though is, send() is returning 0 here as well. But the data is being echoed.&lt;/p&gt;
&lt;p&gt;TCP is still not working. I disabled power saving to make sure that nothing funny is happening there:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;AT+CEPPI=0
AT+CPSMS=0
AT+CEDRXS=0&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The socket seems to just get closed after receiving the initial data, resulting in error code &lt;span class="pl-en"&gt;ECONNRESET &amp;quot;Connection reset by peer&amp;quot;&lt;/span&gt;:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;tcp_socket: 2
connect to 195.34.89.241 err: 0
Received: U-Blox AG TCP/UDP test service
 [31]
Sent: Hello U-Blox [0]
// -------------------------&amp;gt; Here there is a pause
+CSCON: 0
+CSCON: 1
Receive failed: 0
Send failed: 54
Receive failed: 54&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;I have also tried it with another server, same thing happens. Both servers are proven to work correctly when connecting from other devices.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF9160 TCP connection, sending over LTE-M</title><link>https://devzone.nordicsemi.com/thread/265726?ContentTypeID=1</link><pubDate>Fri, 21 Aug 2020 10:11:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:54845808-37e2-4e4b-8ec4-e7dde3d90824</guid><dc:creator>newUser</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m using NCS 1.3.0. &lt;br /&gt;Upon further investigation, the send() function returns 0, indicating no error, but still 0 bytes transmitted.&lt;/p&gt;
&lt;p&gt;I believe this means the socket is closed. Perhaps I should change modem / connection / socket options? &lt;br /&gt;Other connections from both my PC and another embedded device (other modem) do not have this problem.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF9160 TCP connection, sending over LTE-M</title><link>https://devzone.nordicsemi.com/thread/265720?ContentTypeID=1</link><pubDate>Fri, 21 Aug 2020 09:50:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cab3bf63-9ff9-4c39-8c59-f628fccfa615</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;What version of NCS are you using? It looks like the server is the issue here as it doesn&amp;#39;t echo back. Attached is the main.c used in coap_client with added error handling just rename replace with main.c in the coap_client sample and rename to main.c&lt;br /&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-71557431f87d43e3bee536ed4c3ab3a2/main_5F00_dz255052.c"&gt;devzone.nordicsemi.com/.../main_5F00_dz255052.c&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Please see &lt;a href="https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.4.0/com.ibm.zos.v2r4.hala001/syserret.htm"&gt;this list&lt;/a&gt;&amp;nbsp;with possible issues given by errno -1.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>