Coap-Server Coap-Client Example / OpenThread Border Router

Hi,

I am developing Coap-Client and Coap-Server devices using nRf52840 dev kit. I am using ncs 1.7.1 sdk. I have a few questions.


1- I can successfully send a data received from Coap-Client to the Border Router, but after a while, the Coap-Server, the Router, declares itself as the Leader and disconnects from the network (connects back as a child device) and does not become a router again. What is the reason for this?


2- The Coap-Server device creates a different ip address each time and I have to change the address to which the coap-client will send the data. Is there a shorter way to send data to the router it connects to every time without changing the ip address in unicast without multicasting?


3- Coap client must first send data to coap-server and then coap-server must send the data it receives to Border Router, for this I made some changes in coap-server, it is working now, but a data received from Border Router is Cannot send to Coap-Client (route same order (BR-Server-Client)) , what should I do about it?

Thank you for your help!

Parents
  • Hi

    Before I answer your questuons, here are some clarifications, to avoid misunderstandings:


    1- I can successfully send a data received from Coap-Client to the Border Router, but after a while, the Coap-Server, the Router, declares itself as the Leader and disconnects from the network (connects back as a child device) and does not become a router again. What is the reason for this?

    Can you send debug logs from the nodes?


    2- The Coap-Server device creates a different ip address each time and I have to change the address to which the coap-client will send the data. Is there a shorter way to send data to the router it connects to every time without changing the ip address in unicast without multicasting?

    You say "each time". Each time what?


    3- Coap client must first send data to coap-server and then coap-server must send the data it receives to Border Router, for this I made some changes in coap-server, it is working now, but a data received from Border Router is Cannot send to Coap-Client (route same order (BR-Server-Client)) , what should I do about it?

    Why do you need to send data from the BR to the server?
    Where do you want to send data from (Client?) and where is the final destination for the data (a webpage or server maybe?)?

    Regards,
    Sigurd Hellesvik

Reply
  • Hi

    Before I answer your questuons, here are some clarifications, to avoid misunderstandings:


    1- I can successfully send a data received from Coap-Client to the Border Router, but after a while, the Coap-Server, the Router, declares itself as the Leader and disconnects from the network (connects back as a child device) and does not become a router again. What is the reason for this?

    Can you send debug logs from the nodes?


    2- The Coap-Server device creates a different ip address each time and I have to change the address to which the coap-client will send the data. Is there a shorter way to send data to the router it connects to every time without changing the ip address in unicast without multicasting?

    You say "each time". Each time what?


    3- Coap client must first send data to coap-server and then coap-server must send the data it receives to Border Router, for this I made some changes in coap-server, it is working now, but a data received from Border Router is Cannot send to Coap-Client (route same order (BR-Server-Client)) , what should I do about it?

    Why do you need to send data from the BR to the server?
    Where do you want to send data from (Client?) and where is the final destination for the data (a webpage or server maybe?)?

    Regards,
    Sigurd Hellesvik

Children
  • Hi,


    1- The problem is solved.

    2- When I make any changes in Coap-Server, the ip address of the router changes, coap-server is a router, I can reach the new ip address from the terminal, but is there a shorter way to connect the client (end-device) to Coap-Server?

    3- The final destination of the data will be server or web page, not decided but for this we need BR. BR will act as administrator in this project, all routers and end devices will be connected to BR. In this case, when we want to make any changes to the end device, data must be sent from the BR to the end device.
    Data will be transferred in two ways: end device-server-BR and BR-server-end device.


    Therefore I want to send data from BR to server. Likewise, I want to send data from server to end device. I can send data from BR to server but not from server to edge device.


    Regards,

  • Hi

    Let me show a couple of other methods to get data from the client to the server, which I would argue is simpler.

    Client(nrf) -> server(nrf) -> BR -> webserver / webserver -> BR -> server(nrf) -> client(nrf)
    The method you are currently using

    Client(nrf) -> Webserver
    One of the advantages with Thread is that devices get IP addresses.
    Because of this, they will be able to access the internet.
    You should be able to send data directly from your CoAP client to a CoAP server on the internet.

    Webserver -> Client(nrf)
    Since your clients does not have public IP addresses, this does not work. You will have to send these via the BR.
    However, you will be able to get info from the server if you poll with the clients. This can be either regular polling or just when the clients themselves know they need data. The server will not be able to push data to the clients.

    Client(nrf) -> Server(BR) -> Webserver /  Webserver -> Server(BR) -> Client(nrf)
    It is possible to run a CoAP server on the BR. This would be anything which is able to run on a raspberry pi, for example https://libcoap.net/. This way, you no longer need the server(nrf).

    2- The Coap-Server device creates a different ip address each time and I have to change the address to which the coap-client will send the data. Is there a shorter way to send data to the router it connects to every time without changing the ip address in unicast without multicasting?

    With a webserver in either the BR or webserver, it can have a static IP address, and this will not be an issue.

    3- Coap client must first send data to coap-server and then coap-server must send the data it receives to Border Router, for this I made some changes in coap-server, it is working now, but a data received from Border Router is Cannot send to Coap-Client (route same order (BR-Server-Client)) , what should I do about it?

    If you send data directly, this should not be an issue either.

    As you can see, either of these different topologies will make your system easier, and your issues should not be relevant anymore.
    Will this design change be possible for you?

    Regards,
    Sigurd Hellesvik

  • Unfortunately, I do not have the opportunity to change the topology. For this reason, I should change my questions as follows.


    1- Can I assign an ipaddress to the Coap-Server(nRF) device? Assigning the ip address that I have determined will solve many of my problems.


    2- I am sending data with the coap_send_request function on the Coap-Client(nrf) device. I can use the COAP_METHOD_PUT or COAP_METHOD_POST methods. But I can't to read data using COAP_METHOD_GET method. I see that data is sent from Coap-Server(nrf), but coap-client(nrf) cannot receive or parse the data, what can I do?

    Regards,

    ENC

    void client_state_callback(struct k_work *item)
    {
        ARG_UNUSED(item);
    
        char data_send_buf[120];
    
        sprintf(data_send_buf, "%s", write_data);
    
        coap_send_request(COAP_METHOD_PUT,(const struct sockaddr *)&unique_local_addr,
    		cli_option, data_send_buf, sizeof(data_send_buf), NULL);
    
        LOG_INF("Data send");
                    
    }
    
    static int on_client_receive_reply(const struct coap_packet *response,
    				 struct coap_reply *reply,
    				 const struct sockaddr *from)
    {
    	const uint8_t *payload;
    	uint16_t payload_size = 0u;
    
    	ARG_UNUSED(reply);
    	ARG_UNUSED(from);
    
    	payload = coap_packet_get_payload(response, &payload_size);
    
    	memcpy(data_receive_buf, payload, payload_size);
    
    }
    
    void client_receive_callback(struct k_work *item)
    {
        ARG_UNUSED(item);
    
    
        coap_send_request(COAP_METHOD_GET,(const struct sockaddr *)&unique_local_addr,
    		cli_option, NULL , 0u ,on_client_receive_reply);
        
        printk("Data %s\r\n", data_receive_buf);
    
        if(strcmp(data_data,data_receive_buf) == 0)
        {
            LOG_INF("Data received");
            memset(data_receive_buf, 0x00, sizeof(data_receive_buf));
        }           
    }

  • Hi,


    I was able to send data to the coap-client (nrf- end device). The only problem right now is ip address assignment. I want to assign ip address to Coap-Server(nRF) device. How can I do that ?

  • Hi

    Good that you managed to fix it.

    From what I read onThread IPv6 addressing, I can not see any way to assign static IP Addresses.
    To be sure, I have asked our developers, and will return as soon as they respond with what I learn.
    If this is not possible, I find and  advise you to an alternative method in place for static addresses.
    You will hear from be at latest by the end of tomorrow, at best sometime today.

    Regards,
    Sigurd Hellesvik

Related