This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[FAQ] LP-CC1352P7: How to Send packets from Wi-SUN Router Node to Border Router?

Part Number: LP-CC1352P7
Other Parts Discussed in Thread: WI-SUN, CC1352P7

Hi Ti,

Does Wi-SUN Router Node can actively send data packets to Border Router?

After studied the examples from SDK I only found the way Border Router use spinel command to request Router Node to send data, but most of the sensor data will report to uplink devices(gateway and server) automatically in IOT scenarios. Could you please tell me how to make Router node actively send data packets to Border Router? Is there any reference example can follow. 

Thank you very much.

  • Someone have been assigned to this post and will come back to you with an answer shortly

  • Hi Kathy,

    For the ns_node example we have not implemented a command to send data in the pyspinel interface. (Only the ping command.)

    For the Coap example you can use the coap server to update data.

    Cheers,

    Marie H

  • Hi Marie,

    Nice to have your support again Slight smile

    I still got some further questions about Coap example which I am using.

    For the Coap example I know the Border Router is Coap client, all the Router Node is Coap server, is it?

    As I know Router Node will send a response to Border Router after it received Request from Border Router. So that means in the Coap each communication is activated by Coap client(Border Router).

    The Coap example implemented this communication by send Coap command from Border Router to Router Node through pyspinel interface. So If I want to update the data of Coap Server(Router Node) I need send Coap command from Border Router to request it.

    Now if I hope the Router node(coap server) can actively report the data instead of asking the Border Router(Coap client) to request it. what should I do? 

    you mentioned "For the Coap example you can use the coap server to update data." in the last reply.

    Could you please explain it more detail? How to make Router node(coap server) actively report data to Border Router(coap client)? Thank you very much.

  • Hi Cathy,

    Yes, in this case the RN is the Coap server. 

    You can use the coap_service_request_send() to send a data update. You can find the documentation for this and several other useful APIs in the file coap_server_api.h.

    Cheers,

    Marie H

  • Hi Marie,

    Thank you for your reply, I found the documentation you've mentioned in coap_service_api.h and found the coap_service_request_send() definition. There are some comments in this function definition as below:

    uint16_t coap_service_request_send(int8_t service_id, uint8_t options, const uint8_t destination_addr[static 16], uint16_t destination_port, sn_coap_msg_type_e msg_type, sn_coap_msg_code_e msg_code, const char *uri,
    sn_coap_content_format_e cont_type, const uint8_t *payload_ptr, uint16_t payload_len, coap_service_response_recv *request_response_cb)
    {
    //TODO: coap_service_response_recv is an ugly cast, this should be refactored away + sn_coap_hdr_s MUST NOT be exposed to users of coap-service!
    //Callback would be still needed, but where to store callback?
    return coap_message_handler_request_send(coap_service_handle, service_id, options, destination_addr, destination_port, msg_type, msg_code, uri, cont_type, payload_ptr, payload_len, request_response_cb);
    }

    seems this function implementation not finished so far, but I still want to try it. Let me try it first then I will update the result here later. Thank you very much.

  • Hi Kathy,

    The function implementation is done.

    We will remove this note in the next release.

    Cheers,

    Marie H

  • Hi Marie,

    I already tried use coap_service_request_send() to send data update from Router Node to Border Router, it works properly. Thank you so much.

    BR

    Kathy

  • Hi Marie,

    May I ask one more question about coap_service_request_send() function usage?

    After use this function I found that before use coap_service_request_send() to send Coap request from Bouter Node to Border Router, I must send Coap post/get/put from Border Router to Router Node first.  If not like this I can not directly use coap_service_request_send() to send data from Router Node to Border Router, is it true? Thank you so much.

    BR

    kathy

  • Hi Kathy,

    The Coap Service is set up so that the client (aka BR) requests something, then the server (aka RN) replies.

    If you want to avoid this, you can simulate received get message on the RN device without this message actually going over the air.

    Cheers,

    Marie H

  • Hi Marie,

    Thanks for your reply. I see. Smiley But I still got a concern about coap_service_request_send() using.

    The fully definition of this function is:

    uint16_t coap_service_request_send(int8_t service_id, uint8_t options, const uint8_t destination_addr[static 16], uint16_t destination_port, sn_coap_msg_type_e msg_type, sn_coap_msg_code_e msg_code, const char *uri,sn_coap_content_format_e cont_type, const uint8_t *payload_ptr, uint16_t payload_len, coap_service_response_recv *request_response_cb))

    There are some parameters of coap_service_request_send() functions which used to determine sending destination. To my understanding if I want to send the data from RN to BR successfully I just need to make sure destination_addr  and destination_port  are all correct, Otherwise it can not send successfullyBut the result turns to be no matter what destination_addr I used to send data from RN to BR the sending will successful. Only when the service-id incorrect the sending will fail. Could you please tell me what does the service-id used for, is it unique for each RN? and what dose the destination_addr used for? I am a bit confusing here.  Thank you very much!

    BR,

    Kathy

  • Hi Kathy,

    We're investigating internally whether all these parameters are used.

    Cheers,

    Marie H

  • Hi Marie,

    Noted with Thanks. Could you please let me know once have a result? Thank you very much.

    Best Regards,

    Kathy

  • Hi Kathy,

    The parameters in coap_service_request_send() are used differently depending on whether your device is acting as a Coap Server or Client.

    In the case of the ns_coap application, you are running the coap server mode. In this case, the service ID is the parameter which tells the device where to send the message.

    If you use this API from the BR, which is acting as the coap client, the service ID as well as the destinantion address will tell the device where the message is going.

    Cheers,

    Marie H

  • Hi Marie,

    Thank you very much for the reply.

    As you said if I am running the coap server mode on Router Node, the service ID in coap_service_request_send() should be refers to the corresponding Border Router where messages sent to, is it? If I am not wrong, there were only one Border Router in one PAN, So the Service ID should be the same for each Router Node in the same PAN during using coap_service_request_send() function, am I right? Thank you.

    BR,

    kathy

  • Hi Kathy,

    Apologies, I had misunderstood. Please disregard my previous post.

    I would run the Coap node as the client. Here are the necessary steps. 

    1. After node joins the network, register coap service by calling the API.
      1. service_id = coap_service_initialize(interface_id, COAP_PORT, 0, NULL, NULL);
      2. COAP_PORT is default Coap Port 5683.
      3. The service_id is required by all Coap API.
    2. Create the coap_client_response_recv function as callback function.
    3. Get the border router IP address: root_unicast_addr
    4. Send the message to border router
      1. coap_service_request_send(service_id, 0, root_unicast_addr, COAP_PORT, COAP_MSG_TYPE_NON_CONFIRMABLE, COAP_MSG_CODE_REQUEST_GET, COAP_CAR_URI, COAP_CT_TEXT_PLAIN, &car_state, sizeof(car_state),                           coap_client_response_recv);
    5. In the border router side (Host or Linux), you need to start the Coap Server code to wait the corresponding URI resource.
    6. In order to send a message from the Coap node without requesting it from the BR, you can call the coap_client_response_recv callback from you application. 

    We are working on a code example to illustrate this behavior. If you would like to see a code snippet, please send me a PM or ask Kien to send me an email.

    Cheers,

    Marie H

  • Hi Marie,

    Thanks for your reply. 

    I would like to see a code snippet, Could you please tell me how to send a PM to you?

    Another, I am so sorry I become more confusing after reading your latest explanation Joy 

    Based on the example project the BR(Border Router) is Coap Client and the (RN)Router Node is Coap server is it?

    I am using the example project "ns_coap_node_LP_CC1352P7_1_tirtos_ticlang" as RN project reference.

    In this project code, there is a flow as you described before, except the red high lighted part:

    1. After node joins the network, register coap service by calling the API.
      1. service_id = coap_service_initialize(interface_id, COAP_PORT, 0, NULL, NULL);
      2. COAP_PORT is default Coap Port 5683.
      3. The service_id is required by all Coap API.
    2. Create the coap_client_response_recv function as callback function.
    3. Get the border router IP address: root_unicast_addr
    4. Send the message to border router
      1. coap_service_request_send(service_id, 0, root_unicast_addr, COAP_PORT, COAP_MSG_TYPE_NON_CONFIRMABLE, COAP_MSG_CODE_REQUEST_GET, COAP_CAR_URI, COAP_CT_TEXT_PLAIN, &car_state, sizeof(car_state),                           coap_client_response_recv);

    I only add coap_service_request_send(.....) function to send data from RN to BR and the sending is successfully.

    I just want to know the usage of service_id and root_unicast_addr. Because it doesn't matter if the root_unicast_addr is correct or not as long as the service_id keeps the same value while sending and the sending will be successfully. So seems the root_unicast_addr not used. I am confusing if the root_unicast_addr not used then how the sending functions knows the destination ?

    My problem is I want to make RN send message to BR without BR request first while using coap_service_request_send(). Currently if I want to use coap_service_request_send() to send message to BR ,I need do a Coap request from BR to RN first.

    Last time you said "

    The Coap Service is set up so that the client (aka BR) requests something, then the server (aka RN) replies.

    If you want to avoid this, you can simulate received get message on the RN device without this message actually going over the air.

    " I don't know how to simulate received get message on the RN device. So I stuck here and want to know every details of coap_service_request_send().

    But now your latest reply said I can make RN as Coap client and BR router as Coap server is it? It's very different from the example projects. The BR and RN role exchanged. May I have one example code for how to exchange these two roles? Or you said "We are working on a code example to illustrate this behavior." is this code already included all the answers? :) Thank you very much!

    Best Regards,

    Kathy

  • Hi Kathy,

    You can send me a friend request here on E2E, then you will be able to send me a PM. Alternatively, you can ask Kien to send me an email.

    Cheers,

    Marie H

  • Hi Marie,

    Noted with Thanks. Let me try PM first, I already sent the friend request to you. Thank you.

    Best Regards,

    Kathy

  • Hello Marie,

    I also want the codes for uploading sensor readings to Wi-sun border router from my CC1352R1 launchpad.

  • How do I list all the functions defined in TI Wi-SUN stack?

  • Hi,

    We have published a SimpleLink Academy on this training, walking through the code changes needed. Please see:

    https://dev.ti.com/tirex/explore/node?node=A__Ab5oYpAuOfLVRwkotwJZNQ__com.ti.SIMPLELINK_ACADEMY_CC13XX_CC26XX_SDK__AfkT0vQ__LATEST

    Cheers,

    Marie H