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

How to set TCP Port Address in TCP example.

Hi,

I am a beginner in nrf52840 DK. I am trying to run TCP example.
I have flashed client example in the DK and able to connect to the laptop(LED_2 ON).
When I press BUTTON_1 for "TCP connection request" it generates a fatal error. the reason behind this error might be below setting in the client code.

/** Remote TCP Port Address on which data is transmitted.
* Modify m_remote_addr according to your setup.
* The address provided below is a place holder. */
static const ip6_addr_t m_remote_addr =
{
.addr =
{HTONL(0x20010DB8),
0x00000000,
0x00000000,
HTONL(0x00000001)}
};

When is connect the device using echo command as mention the doc. below is the output of ifcofig bt0

bt0 Link encap:UNSPEC HWaddr 54-13-79-FF-FE-7A-56-76-00-00-00-00-00-00-00-00
inet6 addr: fe80::5613:79ff:fe7a:5676/64 Scope:Link
inet6 addr: 2005::5613:79ff:fe7a:5676/64 Scope:Global
UP POINTOPOINT RUNNING MULTICAST MTU:1280 Metric:1
RX packets:3 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:1 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:65 (65.0 B) TX bytes:225 (225.0 B)

Please let me know how to assign value for "m_remote_addr" in source code.

  • Which example, exactly, are you trying?

    and what IDE / toolchain are you using?

  • Please try with this address:

    static const ip6_addr_t m_remote_addr =
    {
    .addr =
    {HTONL(0x20050000),
    0x00000000,
    HTONL(0x561379FF),
    HTONL(0xFE7A5676)}
    };

    It should correspond to 2005::5613:79ff:fe7a:5676 if I typed it in correctly. You may use wireshark to confirm. 

    edit: just want to point out that ipv6 over BT is quite bit complicated and not particularly beginner friendly in my opinion. Depending on your use case it may be better to consider alternatives if possible. Maybe use regular BLE instead. 

  • Hi Vidar,

    As per your suggestion, I have made the changes. I have followed below steps to test the TCP_Client app with a laptop as a server.

    Steps

    1. Run Server python script in the laptop
    2. Program the TCP_client example in nRF52840 DK.
    3. Connect the DK to laptop using "echo "connect 00:C6:11:36:D6:50 1" > /sys/kernel/debug/bluetooth/6lowpan_control" command.
    4. Assign Global ip to bt0 interface in laptop "ifconfig bt0 add 2005::5613:79ff:fe7a:5676/64". (Scope:Global)

    Below is the output of ifconfig bt0


    bt0       Link encap:UNSPEC  HWaddr 54-13-79-FF-FE-7A-56-76-00-00-00-00-00-00-00-00  

              inet6 addr: fe80::5613:79ff:fe7a:5676/64 Scope:Link
              inet6 addr: 2005::5613:79ff:fe7a:5676/64 Scope:Global
              UP POINTOPOINT RUNNING MULTICAST  MTU:1280  Metric:1
              RX packets:3 errors:0 dropped:0 overruns:0 frame:0
              TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1 

              RX bytes:65 (65.0 B)  TX bytes:338 (338.0 B)


    But not able to tranfer Ping and Pong data.

    static const ip6_addr_t m_remote_addr =
    {
        .addr =
        {HTONL(0xfe800000),
        0x00000000,
        HTONL(0x561379FF),
        HTONL(0xFE7A5676)}
    };

    If I use "fe80::5613:79ff:fe7a:5676" (Scope:Link) as value for m_remote_addr in the source code and follow all the steps except Step 3. Then able to transfer Ping and Pong data.

    Could you please confirm which IPv6 (Link or Global) need to use in source code?

Related