I am not able to create socket for TCP communication

Hello evebody,

                       I have problem with socket creation. I am trying to copy example of this tutorial:

https://academy.nordicsemi.com/courses/cellular-iot-fundamentals/lessons/lesson-3-cellular-fundamentals/topic/lesson-3-exercise-1/

What is my idea?

My idea is create a socket for TCP communication, and connected to a TCP server (my nrf9161-DK will work as Client). In another project, i tried to connect my client to server, but it didn't work cause of socket creation failure. If is not able to create socket in fact i am not able to connect to server. I tried to copy some examples, but they are not compatible with my device or not working. 

Now cause of some troubles with libraries i am not able to compile my project.

If I add to prj.conf:

CONFIG_NET_NATIVE=n
CONFIG_NET_SOCKETS_OFFLOAD=y
I am not able to compile my project. Zephyr missing some references (for some net_pkt.h functions maybe :-/ but this library is already included in project) in libraries, but all of them are part of SDK.
I am using SDK v2.5.1 (same as toolchain).
main.c:
#include <zephyr/kernel.h>
#include <zephyr/net/socket.h>
#include <zephyr/net/net_if.h>
#include <zephyr/net/net_ip.h>
#include <zephyr/net/net_pkt.h>
#include <zephyr/net/ppp.h>

int main(void)
{

   int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_TCP);
   if (sock < 0) 
   {
     printk("SCOKET was not created\n");
   }
   else
   {
      printk("SCOKET created :-)\n");  
   }
   return 0;


}
prj.conf:

CONFIG_NETWORKING=y
CONFIG_NET_NATIVE=n
CONFIG_NET_DRIVERS=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_OFFLOAD=y

CONFIG_NET_IPV4=y
CONFIG_NET_L2_PPP=y  # Povolení PPP jako síťové vrstvy
CONFIG_NET_DHCPV4=y  # Automatická konfigurace IP adresy
CONFIG_NET_LOG=y     # Debugging síťového stack
CONFIG_NRF_MODEM_LIB=y
CONFIG_MODEM=y
CONFIG_NET_IPV6=y
CONFIG_NET_TCP=y
CONFIG_NET_UDP=y
CONFIG_NET_DHCPV4=y

Devicetree:

/*
 * Copyright (c) 2023 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */

/dts-v1/;
#include <nordic/nrf9161ns_laca.dtsi>
#include "nrf9161dk_nrf9161_common.dtsi"

/ {
	chosen {
		zephyr,flash = &flash0;
		zephyr,sram = &sram0_ns;
		zephyr,code-partition = &slot0_ns_partition;
		zephyr,console = &uart0;
		zephyr,shell-uart = &uart0;
	};
};

&uart0 {

	status = "okay";
	current-speed = <115200>;
};
&uart1 {

	status = "okay";
	current-speed = <115200>;
};

&rtc0 {

	status = "okay";
};
&timer0 {

    status = "okay";          
    label = "TIMER_0";        
    interrupts = <1 0>;       
};

Could please somebody tell me what my prj.conf could include or what library could i add to my project? Is my devicetree ok?

Regards

Jaroslav Havel

Related