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.

LP-CC1352P7: LP-CC1352P7 COAP SERVER

Part Number: LP-CC1352P7
Other Parts Discussed in Thread: CC1352P7

Hi,

I am using LP-CC1352p7-1 for wisun fan communication between BR and RN. I am running ns_coap_node_src_LP_CC1352P7_1_tirtos7_ticlang example. i could able to communicate between BR and RN. Now i want to send network management data to some other ip and port. For this, i want to create a coap server with user configurable/config file based ip/port. Can i get some example to create a another coap server alog with the currently running coap server.

  • Hi Ranjit,

    Why do you want to do this?

    You merely have to add another coap server. You can get started by copying the "rssi" service.

    Here are some steps to help you:

    1. in application.c, define a new COAP URI for your service:
      1. #define COAP_URI_DATA "data"
    2. Now, create your callback function, you can copy paste "coap_recv_cb_rssi", and give it a new name, like "coap_recv_cb_networkmanagement"
    3. Register your callback function using coap_service_register_uri, with your new COAP_URI_NETWORKMANAGEMENT and callback functions

    Regards,

    Arthur

  • This already we hae done with some of the messages. Our requirement is to send data through another coap server, for that we need help from you

  • Hi Arthur,

    So instead of creating another coap server, we have planned to create another UDP server for Metering data. 

    1. I believe we can create another UDP server on router node in another task in parallel with Coap task.

    2. if we can do so, how we can coomunicate the UDP data, whose ip is user defined, can communicate with Spinel.

    3. What modification I need to do on Spinel or BR to receive those UDP data.

  • Hi Ranjit, 

    This already we hae done with some of the messages. Our requirement is to send data through another coap server, for that we need help from you

    I see you have already created multiple services for the same server we have provided. 

    If I understand you correctly, you want a completely different CoAP server and not a different service. Is there any specific reason this is needed?

    Also, if you check the wpan_callback in spinel-cli.py you see the responses for the various packet types. If it is a udp_pkt then it checks for the destination port and in the default case, it takes action if it is a CoAP port. This is where the Border router-spinel responds to packets. 

    Please can you elaborate on the need for an additional UDP/CoAP server? I am assuming your requirement is to send ip packets from pyspinel through the border router to the router node. 

    Regards,

    Sid 

  • Hi sid,

    We want a transparent channel for meter data communication, this need to be on UDP as head end system api support only UDP interfaces. For this reason, i want to create a UDP server on router node. However, we will be sending network management data through coap server only. Another issue I was facing on router node was, while I create a UDP server on router node I a separate thread, that is blocking coap in main thread. What could be reason for these. I believe my requirement is clear to you. 

  • Hi Sid,

    I created a thread, in which i created  UDP socket. I could able to create the socket but binding is getting failed. However coap server in another thread is working fine. Can you share me an application code with both Coap server and a UDP server?

  • Hi Ranjit,

    I will close this thread for now as we have contact over email. 

    Regards,

    Sid

  • Hi Sid,

    THere was some understanding issue. Yes you are correct that we can have one device with one ip only, whether they have coap server or UDP server.

    I have successfully created two udp server with two different UDP port and a coap server. I could able to send UDP data from Router Node to BR router. On spinel side i could able to receive the message, but i dont know how to parse the UDP message on spinel side.

    Incoming IPv6 Packet Decode Error
    Traceback (most recent call last):
    File "C:\Users\Admin\Downloads\ti-wisunfan-pyspinel\ti-wisunfan-pyspinel\spinel\ipv6.py", line 1564, in _get_payload_factory
    return self._dst_port_factories[dst_port]
    ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
    KeyError: 1234

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "C:\Users\Admin\Downloads\ti-wisunfan-pyspinel\ti-wisunfan-pyspinel\spinel-cli.py", line 465, in wpan_callback
    pkt = self.ipv6_factory.from_bytes(value)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\Admin\Downloads\ti-wisunfan-pyspinel\ti-wisunfan-pyspinel\spinel-cli.py", line 262, in from_bytes
    return self.ipv6_factory.parse(io.BytesIO(data), common.MessageInfo())
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\Admin\Downloads\ti-wisunfan-pyspinel\ti-wisunfan-pyspinel\spinel\ipv6.py", line 1372, in parse
    upper_layer_protocol = self._parse_upper_layer_protocol(
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\Admin\Downloads\ti-wisunfan-pyspinel\ti-wisunfan-pyspinel\spinel\ipv6.py", line 1361, in _parse_upper_layer_protocol
    return factory.parse(data, message_info)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\Admin\Downloads\ti-wisunfan-pyspinel\ti-wisunfan-pyspinel\spinel\ipv6.py", line 1574, in parse
    factory = self._get_payload_factory(udp_header.dst_port)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\Admin\Downloads\ti-wisunfan-pyspinel\ti-wisunfan-pyspinel\spinel\ipv6.py", line 1567, in _get_payload_factory
    raise RuntimeError(
    RuntimeError: Could not find factory to parse UDP datagram payload based on destination port: 1234

    Please let me know, how i can parse the UDP message on spinel side and how I can send UDP message from Spinel to Router.

  • Hi Ranjit, 

    You said that you were able to parse messages on the spinel side, what are you parsing here? 

    What changes have you made on the router node side to transmit non CoAP messages?

    Regards,
    Sid

  • To send non-coap messages, we have created a separate UDP socket .
     
     udp_trans_socket_id = socket_open(SOCKET_UDP, 0, socket_callback);
        if (0 > udp_trans_socket_id )
        {
            return false;
        }

        bind_addr.type = ADDRESS_IPV6;
        memcpy(bind_addr.address, ns_in6addr_any, 16);
        bind_addr.identifier = UDP_PORT;

        send_addr_endpoint.identifier = UDP_PORT;
        send_addr_endpoint.type = ADDRESS_IPV6;
        ret = socket_bind(udp_trans_socket_id, &bind_addr);
        if (0 > ret )
        {
            return false;
        }
    //for sending UDP packet.
    socket_sendto(udp_trans_socket_id, &send_addr_endpoint, transparent_Buff, TransMsgLen );
    //to receive UDP packet from Spinel(BR)
     len = socket_recvfrom(udp_trans_socket_id, recv_buffer, sizeof(recv_buffer), 0, &source_addr);
             if(len > 0)
             {
                 //transparent uart for meter communication
                 sem_wait(&sem_uart_read);
                 UART2_write(uart_transparent, recv_buffer, sizeof(recv_buffer), NULL);
                 b_udp_req = true;
    
             }
    
     
    we could not able to figure out, how to send UDP packet to Router Node.
  • Hi Ranjit,

    You can use do_coap() function on pyspinel as a reference implementation of a function that sends UDP packets to the router node.

    In the do_coap() function, you are building a coap packet by applying coap and udp headers to the packet and then send the built packet with the wpan_api.ip_send().

    So, in your case, where you do not need a coap header or coap payload, it should be possible to remove these and then just transmit the UDP datagram and send it using wpan_api.ip_send().

     This is code snippet where the coap_request is created before transmission. You can modify it as I mentioned above.

    Or as a preliminary test, simply use the coap command in pyspinel but change the "COAP_PORT" to the UDP port number of the socket you created. 

    You should still receive this packet. But then you are responsible for packet handling.

            coap_request = ipv6.IPv6Packet(
                ipv6_header=ipv6.IPv6Header(source_address=src,
                                            destination_address=dst,
                                            hop_limit=hop_limit
                ),
                upper_layer_protocol=ipv6.UDPDatagram(
                    header=ipv6.UDPHeader(src_port=COAP_PORT, dst_port=COAP_PORT),
                    payload=ipv6.CoAP(
                        header=ipv6.CoAPHeader(_type=coap_type, tkl=tkl, code=coap_method_code,
                            msg_id=msg_id, token=token, options=coap_options
                        ),
                        payload=coap_payload
                    )
                )
            )

    Regards,
    Sid