This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Setting up TCP over IPv6 using nRF52840 Development kit and nrf5 iot sdk

Hello,

I was trying to setup nrf5 board with IoT sdk for tcp connections where the tcp board will act as a server and raspberry pi 3 model B 1.2 as client.

I downloaded the SDK from the following link

developer.nordicsemi.com/.../

Because latest v17.0.2 IoT TCP example that I could locate. Once the sample TCP server was installed on nrf dk board. LED1 turned on.

For raspberry pi the following steps were done.

root@raspberrypi:/home/pi/blll# cat /etc/sysctl.conf | grep ipv6

net.ipv6.conf.all.forwarding=1

#net.ipv6.conf.all.accept_redirects = 0

#net.ipv6.conf.all.accept_source_route = 0

root@raspberrypi:/home/pi/blll# sudo dpkg -l | grep bluez

ii  bluez                                5.50-1.2~deb10u1+rpt2               armhf        Bluetooth tools and daemons

ii  bluez-firmware                       1.2-4+rpt7                          all          Firmware for Bluetooth devices

root@raspberrypi:/home/pi/blll# sudo dpkg -l | grep radvd

ii  radvd                                1:2.17-2                            armhf        Router Advertisement Daemon

root@raspberrypi:/home/pi/blll# sudo dpkg -l | grep libcap-ng0

ii  libcap-ng0:armhf                     0.7.9-2                             armhf        An alternate POSIX capabilities library

root@raspberrypi:/home/pi/blll# uname -a

Linux raspberrypi 5.4.83-v7+ #1379 SMP Mon Dec 14 13:08:57 GMT 2020 armv7l GNU/Linux

root@raspberrypi:/home/pi/blll# cat /etc/radvd.conf

interface bt0

{

    AdvSendAdvert on;

    prefix 2001:db8::/64

    {

        AdvOnLink off;

        AdvAutonomous on;

        AdvRouterAddr on;

    };

};

root@raspberrypi:/home/pi/blll# echo 1 > /proc/sys/net/ipv6/conf/all/forwarding

root@raspberrypi:/home/pi/blll# service radvd restart

The connection links were referred as follows -

https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v16.0.0%2Fiot_sdk_app_lwip_tcp_client.html

root@raspberrypi:/home/pi/blll# mount -t debugfs none /sys/kernel/debug

root@raspberrypi:/home/pi/blll# modprobe bluetooth_6lowpan

root@raspberrypi:/home/pi/blll# echo 1 > /sys/kernel/debug/bluetooth/6lowpan_enable

root@raspberrypi:/home/pi/blll# hciconfig

hci0: Type: Primary  Bus: UART

BD Address: B8:27:EB:7B:84:E8  ACL MTU: 1021:8  SCO MTU: 64:1

UP RUNNING

RX bytes:1476 acl:0 sco:0 events:90 errors:0

TX bytes:3512 acl:0 sco:0 commands:90 errors:0

root@raspberrypi:/home/pi/blll# hciconfig hci0 reset

root@raspberrypi:/home/pi/blll#

root@raspberrypi:/home/pi/blll# hciconfig

hci0: Type: Primary  Bus: UART

BD Address: B8:27:EB:7B:84:E8  ACL MTU: 1021:8  SCO MTU: 64:1

UP RUNNING

RX bytes:2186 acl:0 sco:0 events:131 errors:0

TX bytes:4282 acl:0 sco:0 commands:131 errors:0

root@raspberrypi:/home/pi/blll# hcitool lescan

LE Scan ...

00:02:BE:51:03:08 TCP_Server

00:02:BE:51:03:08 (unknown)

^Croot@raspberrypi:/home/pi/blll# echo "connect 00:02:BE:51:03:08 1" > /sys/kernel/debug/bluetooth/6lowpan_control

Now on board LED2 has started and LED 1 is off which is as per documentation.

root@raspberrypi:/home/pi/blll# lsmod | grep bluetooth_6lowpan

bluetooth_6lowpan      20480  1

6lowpan                28672  8 nhc_udp,nhc_routing,nhc_mobility,bluetooth_6lowpan,nhc_fragment,nhc_dest,nhc_hop,nhc_ipv6

bluetooth             360448  30 bluetooth_6lowpan,hci_uart,bnep,btbcm,rfcomm

ipv6                  458752  50 bluetooth_6lowpan,6lowpan

root@raspberrypi:/home/pi/blll# sudo echo 2 > /proc/sys/net/ipv6/conf/bt0/accept_ra

root@raspberrypi:/home/pi/blll# service radvd restart

root@raspberrypi:/home/pi/blll# ifconfig bt0

bt0: flags=4161<UP,RUNNING,MULTICAST>  mtu 1280

        inet6 fe80::b827:ebff:fe7b:84e8  prefixlen 64  scopeid 0x20<link>

        inet6 2001:db8::b827:ebff:fe7b:84e8  prefixlen 64  scopeid 0x0<global>

        unspec B8-27-EB-7B-84-E8-00-00-00-00-00-00-00-00-00-00  txqueuelen 1000  (UNSPEC)

        RX packets 5  bytes 157 (157.0 B)

        RX errors 0  dropped 2  overruns 0  frame 0

        TX packets 40  bytes 3570 (3.4 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

root@raspberrypi:/home/pi/blll# ping6 -I bt0 fe80::02:beff:fe51:0308

ping6: Warning: source address might be selected on device other than bt0.

PING fe80::02:beff:fe51:0308(fe80::2:beff:fe51:308) from :: bt0: 56 data bytes

64 bytes from fe80::2:beff:fe51:308%bt0: icmp_seq=1 ttl=255 time=79.4 ms

64 bytes from fe80::2:beff:fe51:308%bt0: icmp_seq=2 ttl=255 time=101 ms

64 bytes from fe80::2:beff:fe51:308%bt0: icmp_seq=3 ttl=255 time=74.9 ms

64 bytes from fe80::2:beff:fe51:308%bt0: icmp_seq=4 ttl=255 time=97.6 ms

^C

--- fe80::02:beff:fe51:0308 ping statistics ---

4 packets transmitted, 4 received, 0% packet loss, time 7ms

rtt min/avg/max/mdev = 74.853/88.329/101.493/11.397 ms

The above ping shows that the board is pinging using lowpan module.

root@raspberrypi:/home/pi/blll# cat pyCode1.py

from socket import *

import struct

import sys

SERVER_ADDR = 'fe80::02:beff:fe51:0308%bt0'

SERVER_PORT = 9000

sequence_number = 1

addrinfo = getaddrinfo(SERVER_ADDR, SERVER_PORT, AF_INET6, SOCK_STREAM)

#sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)

(family, socktype, proto, canonname, sockaddr) = addrinfo[0]

sock = socket(family, socktype, proto)

sock.connect(sockaddr)

while sequence_number < 101 :

    data = struct.pack("!I", sequence_number)

    data +=  'Ping'

    sock.sendto(data, (SERVER_ADDR, SERVER_PORT, 0, 0))

    recv_data = sock.recvfrom(8)

    print(recv_data)

    rx_sequence_number = struct.unpack("!I", recv_data[0][:4])[0]

    if sequence_number is not rx_sequence_number:

        print("Sequence number mismatch!")

    sequence_number+= 1

    

sock.close()

del sock

root@raspberrypi:/home/pi/blll# python3 pyCode1.py

Traceback (most recent call last):

  File "pyCode1.py", line 11, in <module>

    sock.connect(sockaddr)

TimeoutError: [Errno 110] Connection timed out

I have referred to one of the following links but no help -

https://devzone.nordicsemi.com/f/nordic-q-a/15422/nrf5-iot-sdk-v0-9-0-tcp-server-example---connection-refused

Thanks in advance.

Related