Пример #1
0
OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
                                        OCClientResponse * clientResponse) {
    uint8_t remoteIpAddr[4];
    uint16_t remotePortNu;

    if (ctx == (void*) DEFAULT_CONTEXT_VALUE) {
        printf ("Callback Context for DISCOVER query recvd successfully\n");
    }

    if (clientResponse) {
        printf ("StackResult: %s\n", getResult(clientResponse->result));

        OCDevAddrToIPv4Addr((OCDevAddr *) clientResponse->addr, remoteIpAddr,
                            remoteIpAddr + 1, remoteIpAddr + 2, remoteIpAddr + 3);
        OCDevAddrToPort((OCDevAddr *) clientResponse->addr, &remotePortNu);

        printf ("Device =============> Discovered %s @ %d.%d.%d.%d:%d\n",
                clientResponse->resJSONPayload, remoteIpAddr[0], remoteIpAddr[1],
                remoteIpAddr[2], remoteIpAddr[3], remotePortNu);

        parseClientResponse(clientResponse);

        // Init GET request to the server.
        printf ("\n\nExecuting %s\n", __func__);
        std::ostringstream query;
        query << "coap://" << coapServerIP << ":" << coapServerPort << coapServerResource;
        InvokeOCDoResource(query, OC_REST_GET, OC_LOW_QOS, getReqCB, NULL, 0);
    }

    return (UNICAST_DISCOVERY) ? OC_STACK_DELETE_TRANSACTION : OC_STACK_KEEP_TRANSACTION;
}
Пример #2
0
/*
 * This is a function called back when a device is discovered
 */
OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
        OCClientResponse * clientResponse)
{
    uint8_t remoteIpAddr[4];
    uint16_t remotePortNu;
    if (ctx == (void*)DEFAULT_CONTEXT_VALUE)
    {
        OC_LOG(INFO, TAG, "\n<====Callback Context for DISCOVERY query "
               "received successfully====>");
    }
    else
    {
        OC_LOG(ERROR, TAG, "\n<====Callback Context for DISCOVERY fail====>");
    }

    if (clientResponse)
    {
        OCDevAddrToIPv4Addr((OCDevAddr *) clientResponse->addr, remoteIpAddr,
                remoteIpAddr + 1, remoteIpAddr + 2, remoteIpAddr + 3);
        OCDevAddrToPort((OCDevAddr *) clientResponse->addr, &remotePortNu);

        OC_LOG_V(INFO, TAG,
                "Device Discovered %s \n @ %d.%d.%d.%d:%d\n",
                clientResponse->resJSONPayload, remoteIpAddr[0], remoteIpAddr[1],
                remoteIpAddr[2], remoteIpAddr[3], remotePortNu);

        collectUniqueResource(clientResponse);
    }
    else
    {
        OC_LOG(ERROR, TAG, "<====DISCOVERY Callback fail to receive clientResponse====>\n");
    }
    return (UNICAST_DISCOVERY) ?
           OC_STACK_DELETE_TRANSACTION : OC_STACK_KEEP_TRANSACTION ;
}
Пример #3
0
OCStackApplicationResult postReqCB(void *ctx, OCDoHandle handle,
                          OCClientResponse *clientResponse)
{
    uint8_t remoteIpAddr[4];
    uint16_t remotePortNu;

    if(ctx == (void*)DEFAULT_CONTEXT_VALUE)
    {
        OC_LOG(INFO, TAG, "<====Callback Context for POST received successfully====>");
    }
    else
    {
        OC_LOG(ERROR, TAG, "<====Callback Context for POST fail====>");
    }

    if(clientResponse)
    {
        OCDevAddrToIPv4Addr((OCDevAddr *) clientResponse->addr, remoteIpAddr,
                            remoteIpAddr + 1, remoteIpAddr + 2, remoteIpAddr + 3);
        OCDevAddrToPort((OCDevAddr *) clientResponse->addr, &remotePortNu);

        OC_LOG_V(INFO, TAG,"POST Response: %s \nFrom %d.%d.%d.%d:%d\n",
                    clientResponse->resJSONPayload, remoteIpAddr[0], remoteIpAddr[1],
                    remoteIpAddr[2], remoteIpAddr[3], remotePortNu);
    }
    else
    {
        OC_LOG(ERROR, TAG, "<====POST Callback fail to receive clientResponse====>\n");
    }

    return OC_STACK_DELETE_TRANSACTION;
}
Пример #4
0
OCStackApplicationResult subscribePresenceCallback(void* ctx, OCDoHandle handle,
        OCClientResponse* clientResponse)
{
    char stringAddress[DEV_ADDR_SIZE_MAX];
    ostringstream os;
    uint16_t port;

    if(OCDevAddrToString(clientResponse->addr, stringAddress) == 0 &&
            OCDevAddrToPort(clientResponse->addr, &port) == 0)
    {
        os<<stringAddress<<":"<<port;

        ClientCallbackContext::SubscribePresenceContext* context =
            static_cast<ClientCallbackContext::SubscribePresenceContext*>(ctx);

        std::thread exec(context->callback, clientResponse->result,
                         clientResponse->sequenceNumber, os.str());

        exec.detach();
    }
    else
    {
        oclog() << "subscribePresenceCallback(): OCDevAddrToString() or OCDevAddrToPort() "
                <<"failed"<< std::flush;
    }
    return OC_STACK_KEEP_TRANSACTION;
}
Пример #5
0
std::string getPortTBServer(OCClientResponse * clientResponse) {
    if(!clientResponse) return "";
    if(!clientResponse->addr) return "";
    uint16_t p = 0;
    if(0 != OCDevAddrToPort(clientResponse->addr, &p) ) return "";
    std::ostringstream ss;
    ss << p;
    return ss.str();
}
Пример #6
0
OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle,
                           OCClientResponse * clientResponse)
{
    uint8_t remoteIpAddr[4];
    uint16_t remotePortNu;

    if (ctx == (void*) DEFAULT_CONTEXT_VALUE)
    {
        OC_LOG(INFO, TAG, "<====Callback Context for GET received successfully====>");
    }
    else
    {
        OC_LOG(ERROR, TAG, "<====Callback Context for GET fail====>");
    }

    if (clientResponse)
    {
        OCDevAddrToIPv4Addr((OCDevAddr *) clientResponse->addr, remoteIpAddr, remoteIpAddr + 1,
                remoteIpAddr + 2, remoteIpAddr + 3);
        OCDevAddrToPort((OCDevAddr *) clientResponse->addr, &remotePortNu);

        OC_LOG_V(INFO, TAG,"Get Response: %s \nFrom %d.%d.%d.%d:%d\n",
                clientResponse->resJSONPayload, remoteIpAddr[0], remoteIpAddr[1],
                remoteIpAddr[2], remoteIpAddr[3], remotePortNu);

        if (clientResponse->rcvdVendorSpecificHeaderOptions
                && clientResponse->numRcvdVendorSpecificHeaderOptions)
        {
            OC_LOG (INFO, TAG, "Received vendor specific options");
            uint8_t i = 0;
            OCHeaderOption * rcvdOptions = clientResponse->rcvdVendorSpecificHeaderOptions;
            for (i = 0; i < clientResponse->numRcvdVendorSpecificHeaderOptions; i++)
            {
                if (((OCHeaderOption) rcvdOptions[i]).protocolID == OC_COAP_ID)
                {
                    OC_LOG_V(INFO, TAG, "Received option with OC_COAP_ID and ID %u with",
                            ((OCHeaderOption)rcvdOptions[i]).optionID );

                    OC_LOG_BUFFER(INFO, TAG, ((OCHeaderOption)rcvdOptions[i]).optionData,
                        MAX_HEADER_OPTION_DATA_LENGTH);
                }
            }
        }
    }
    else
    {
        OC_LOG(ERROR, TAG, "<====GET Callback fail to receive clientResponse====>\n");
    }
    return OC_STACK_DELETE_TRANSACTION;
}
Пример #7
0
// This is a function called back when a device is discovered
OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
        OCClientResponse * clientResponse)
{
    uint8_t remoteIpAddr[4];
    uint16_t remotePortNu;

    if (ctx == (void*) DEFAULT_CONTEXT_VALUE)
    {
        OC_LOG(INFO, TAG, "Callback Context for DISCOVER query recvd successfully");
    }

    if (clientResponse)
    {
        OC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));

        OCDevAddrToIPv4Addr((OCDevAddr *) clientResponse->addr, remoteIpAddr,
                remoteIpAddr + 1, remoteIpAddr + 2, remoteIpAddr + 3);
        OCDevAddrToPort((OCDevAddr *) clientResponse->addr, &remotePortNu);

        OC_LOG_V(INFO, TAG,
                "Device =============> Discovered %s @ %d.%d.%d.%d:%d",
                clientResponse->resJSONPayload, remoteIpAddr[0], remoteIpAddr[1],
                remoteIpAddr[2], remoteIpAddr[3], remotePortNu);

        parseClientResponse(clientResponse);

        switch(TEST_CASE)
        {
            case TEST_NON_CON_OP:
                InitGetRequest(OC_LOW_QOS);
                InitPutRequest();
                InitPostRequest(OC_LOW_QOS);
                break;
            case TEST_CON_OP:
                InitGetRequest(OC_HIGH_QOS);
                InitPutRequest();
                InitPostRequest(OC_HIGH_QOS);
                break;
            default:
                PrintUsage();
                break;
        }
    }

    return (UNICAST_DISCOVERY) ? OC_STACK_DELETE_TRANSACTION : OC_STACK_KEEP_TRANSACTION ;

}
Пример #8
0
const char * getPort(const OCClientResponse * clientResponse)
{
    uint16_t p = 0;
    if(!clientResponse || 0 != OCDevAddrToPort(clientResponse->addr, &p) )
    {
        return "";
    }

    char * port = NULL;
    if((port = (char *) OICCalloc(1, MAX_PORT_ST_SZ)))
    {
        snprintf(port, MAX_PORT_ST_SZ, "%d", p);
    }
    else
    {
        OC_LOG(ERROR, TAG, "Memory not allocated to port");
    }
    return port;
}
Пример #9
0
//discovery callback
OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
        OCClientResponse * clientResponse) {
    uint8_t remoteIpAddr[4];
    uint16_t remotePortNu;

    if (ctx == (void*) CTX_VAL)
    {
        OC_LOG_V(INFO, TAG, "Callback Context for DISCOVER query recvd successfully");
	}
    if(clientResponse)
    {
        OC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));

        OCDevAddrToIPv4Addr((OCDevAddr *) clientResponse->addr, remoteIpAddr,
                remoteIpAddr + 1, remoteIpAddr + 2, remoteIpAddr + 3);
        OCDevAddrToPort((OCDevAddr *) clientResponse->addr, &remotePortNu);

	if(clientResponse->resJSONPayload !=NULL)
	{
        
	    OC_LOG_V(INFO, TAG,
            "Device =============> Discovered %s @ %d.%d.%d.%d:%d",
            clientResponse->resJSONPayload, remoteIpAddr[0], remoteIpAddr[1],
            remoteIpAddr[2], remoteIpAddr[3], remotePortNu);
				
	    //DM client
	    char addr[MAX_URI_LEN]="";
	    snprintf(addr, sizeof(addr), "coap://%d.%d.%d.%d:%d", remoteIpAddr[0], remoteIpAddr[1], remoteIpAddr[2], remoteIpAddr[3], remotePortNu);
	    dmc_resource( addr, clientResponse );
	}
	else
	{
		OC_LOG_V(INFO, TAG, " response NULL");
	}

    }
    return OC_STACK_KEEP_TRANSACTION ;
}
Пример #10
0
// This is a function called back when a device is discovered
OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
        OCClientResponse * clientResponse)
{
    uint8_t remoteIpAddr[4];
    uint16_t remotePortNu;

    if (ctx == (void*) DEFAULT_CONTEXT_VALUE)
    {
        OC_LOG(INFO, TAG, "Callback Context for DISCOVER query recvd successfully");
    }

    if (clientResponse)
    {
        OC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));

        OCDevAddrToIPv4Addr((OCDevAddr *) clientResponse->addr, remoteIpAddr,
                remoteIpAddr + 1, remoteIpAddr + 2, remoteIpAddr + 3);
        OCDevAddrToPort((OCDevAddr *) clientResponse->addr, &remotePortNu);

        std::string connectionType = getConnectivityType (clientResponse->connType);
        OC_LOG_V(INFO, TAG, "Discovered on %s", connectionType.c_str());
        OC_LOG_V(INFO, TAG,
                "Device =============> Discovered %s @ %d.%d.%d.%d:%d",
                clientResponse->resJSONPayload, remoteIpAddr[0], remoteIpAddr[1],
                remoteIpAddr[2], remoteIpAddr[3], remotePortNu);

        parseClientResponse(clientResponse);

        switch(TEST_CASE)
        {
            case TEST_GET_REQ_NON:
                InitGetRequest(OC_LOW_QOS, 0, 0);
                break;
            case TEST_GET_REQ_NON_WITH_FILTERS:
                InitGetRequest(OC_LOW_QOS, 0, 1);
                break;
            case TEST_PUT_REQ_NON:
                InitPutRequest(OC_LOW_QOS);
                break;
            case TEST_POST_REQ_NON:
                InitPostRequest(OC_LOW_QOS);
                break;
            case TEST_DELETE_REQ_NON:
                InitDeleteRequest(OC_LOW_QOS);
                break;
            case TEST_OBS_REQ_NON:
            case TEST_OBS_REQ_NON_CANCEL_IMM:
                InitObserveRequest(OC_LOW_QOS);
                break;
            case TEST_GET_UNAVAILABLE_RES_REQ_NON:
                InitGetRequestToUnavailableResource(OC_LOW_QOS);
                break;
            case TEST_GET_REQ_CON:
                InitGetRequest(OC_HIGH_QOS, 0, 0);
                break;
            case TEST_POST_REQ_CON:
                InitPostRequest(OC_HIGH_QOS);
                break;
            case TEST_DELETE_REQ_CON:
                InitDeleteRequest(OC_HIGH_QOS);
                break;
            case TEST_OBS_REQ_CON:
                InitObserveRequest(OC_HIGH_QOS);
                break;
#ifdef WITH_PRESENCE
            case TEST_OBS_PRESENCE:
            case TEST_OBS_PRESENCE_WITH_FILTER:
            case TEST_OBS_PRESENCE_WITH_FILTERS:
            case TEST_OBS_MULTICAST_PRESENCE:
                InitPresence();
                break;
#endif
            case TEST_GET_REQ_NON_WITH_VENDOR_HEADER_OPTIONS:
                InitGetRequest(OC_LOW_QOS, 1, 0);
                break;
            case TEST_DISCOVER_DEV_REQ:
                InitDeviceDiscovery(OC_LOW_QOS);
                break;
            default:
                PrintUsage();
                break;
        }
    }
    else
    {
        OC_LOG_V(INFO, TAG, "discoveryReqCB received Null clientResponse");
    }
    return OC_STACK_KEEP_TRANSACTION;
}
Пример #11
0
//This function is called back by libcoap when a response is received
static void HandleCoAPResponses(struct coap_context_t *ctx,
        const coap_queue_t * rcvdResponse) {
    OCResponse * response = NULL;
    OCCoAPToken rcvdToken;
    OCClientResponse clientResponse = {0};
    ClientCB * cbNode = NULL;
    unsigned char bufRes[MAX_RESPONSE_LENGTH] = {0};
    uint32_t sequenceNumber = OC_OBSERVE_NO_OPTION;
    uint32_t maxAge = 0;
    OCStackResult result = OC_STACK_ERROR;
    coap_pdu_t * sendPdu = NULL;
    coap_pdu_t * recvPdu = NULL;
    unsigned char rcvdUri[MAX_URI_LENGTH] = { 0 };
    uint8_t isObserveNotification = 0;
    #ifdef WITH_PRESENCE
    char * resourceTypeName = NULL;
    uint8_t remoteIpAddr[4];
    uint16_t remotePortNu;
    unsigned char fullUri[MAX_URI_LENGTH] = { 0 };
    uint8_t isPresenceNotification = 0;
    uint8_t isMulticastPresence = 0;
    uint32_t lowerBound;
    uint32_t higherBound;
    char * tok = NULL;
    #endif
    coap_block_t rcvdBlock1 = {COAP_BLOCK_FILL_VALUE};
    coap_block_t rcvdBlock2 = {COAP_BLOCK_FILL_VALUE};
    uint16_t rcvdSize2 = 0;

    VERIFY_NON_NULL(ctx);
    VERIFY_NON_NULL(rcvdResponse);
    recvPdu = rcvdResponse->pdu;

    result = ParseCoAPPdu(recvPdu, rcvdUri, NULL, &sequenceNumber, &maxAge,
            &clientResponse.numRcvdVendorSpecificHeaderOptions,
            clientResponse.rcvdVendorSpecificHeaderOptions,
            &rcvdBlock1, &rcvdBlock2, NULL, &rcvdSize2, bufRes);

    VERIFY_SUCCESS(result, OC_STACK_OK);

    OC_LOG_V(DEBUG, TAG, "The sequenceNumber/NONCE of this response %u", sequenceNumber);
    OC_LOG_V(DEBUG, TAG, "The maxAge/TTL of this response %u", maxAge);
    OC_LOG_V(DEBUG, TAG, "The response received is %s", bufRes);

    if(sequenceNumber >= OC_OFFSET_SEQUENCE_NUMBER)
    {
        isObserveNotification = 1;
        OC_LOG(INFO, TAG, PCF("Received an observe notification"));
    }

    #ifdef WITH_PRESENCE
    if(!strcmp((char *)rcvdUri, (char *)OC_PRESENCE_URI)){
        char* tokSavePtr;

        isPresenceNotification = 1;
        OC_LOG(INFO, TAG, PCF("Received a presence notification"));
        tok = strtok_r((char *)bufRes, "[:]}", &tokSavePtr);
        bufRes[strlen((char *)bufRes)] = ':';
        tok = strtok_r(NULL, "[:]}", &tokSavePtr);
        bufRes[strlen((char *)bufRes)] = ':';
        VERIFY_NON_NULL(tok);
        sequenceNumber = (uint32_t )atol(tok);
        OC_LOG_V(DEBUG, TAG, "The received NONCE is %u", sequenceNumber);
        tok = strtok_r(NULL, "[:]}", &tokSavePtr);
        VERIFY_NON_NULL(tok);
        maxAge = (uint32_t )atol(tok);
        OC_LOG_V(DEBUG, TAG, "The received TTL is %u", maxAge);
        tok = strtok_r(NULL, "[:]}", &tokSavePtr);
        if(tok) {
            bufRes[strlen((char *)bufRes)] = ':';
            resourceTypeName = (char *)OCMalloc(strlen(tok));
            if(!resourceTypeName)
            {
                goto exit;
            }
            strcpy(resourceTypeName, tok);
            OC_LOG_V(DEBUG, TAG, "----------------resourceTypeName %s",
                    resourceTypeName);
        }
        bufRes[strlen((char *)bufRes)] = ']';
    }
    #endif

    // fill OCCoAPToken structure
    RetrieveOCCoAPToken(recvPdu, &rcvdToken);
    OC_LOG_V(INFO, TAG,"Received a pdu with Token", rcvdToken.tokenLength);
    OC_LOG_BUFFER(INFO, TAG, rcvdToken.token, rcvdToken.tokenLength);

    // fill OCClientResponse structure
    result = FormOCClientResponse(&clientResponse, CoAPToOCResponseCode(recvPdu->hdr->code),
            (OCDevAddr *) &(rcvdResponse->remote), sequenceNumber, bufRes);
    VERIFY_SUCCESS(result, OC_STACK_OK);

    cbNode = GetClientCB(&rcvdToken, NULL, NULL);

    #ifdef WITH_PRESENCE
    // Check if the application subscribed for presence
    if(!cbNode)
    {
        // get the address of the remote
        OCDevAddrToIPv4Addr((OCDevAddr *) &(rcvdResponse->remote), remoteIpAddr,
                remoteIpAddr + 1, remoteIpAddr + 2, remoteIpAddr + 3);
        OCDevAddrToPort((OCDevAddr *) &(rcvdResponse->remote), &remotePortNu);
        snprintf((char *)fullUri, sizeof(fullUri), "coap://%d.%d.%d.%d:%d%s",
                remoteIpAddr[0],remoteIpAddr[1],remoteIpAddr[2],remoteIpAddr[3],
                remotePortNu,rcvdUri);
        cbNode = GetClientCB(NULL, NULL, fullUri);
    }

    // Check if application subscribed for multicast presence
    if(!cbNode)
    {
        snprintf((char *)fullUri, sizeof(fullUri), "%s%s", OC_MULTICAST_IP, rcvdUri);
        cbNode = GetClientCB(NULL, NULL, fullUri);
        isMulticastPresence = 1;
        isPresenceNotification = 0;
    }
    #endif

    // fill OCResponse structure
    result = FormOCResponse(&response, cbNode, maxAge, &clientResponse);
    VERIFY_SUCCESS(result, OC_STACK_OK);

    if(cbNode)
    {
        if(!isObserveNotification)
        {
            #ifdef WITH_PRESENCE
            if(!isPresenceNotification)
            {
            #endif
                OC_LOG(INFO, TAG, PCF("Received a regular response"));
                if(recvPdu->hdr->type == COAP_MESSAGE_CON)
                {
                    sendPdu = GenerateCoAPPdu(COAP_MESSAGE_ACK, 0,
                            recvPdu->hdr->id, NULL, NULL, NULL);
                    VERIFY_NON_NULL(sendPdu);
                    result = SendCoAPPdu(gCoAPCtx, (coap_address_t*) &rcvdResponse->remote,
                            sendPdu,
                            (coap_send_flags_t)(rcvdResponse->secure ? SEND_SECURE_PORT : 0));
                }
            #ifdef WITH_PRESENCE
            }
            #endif
        }
        if(isObserveNotification)
        {
            OC_LOG(INFO, TAG, PCF("Received an observe notification"));
            if(recvPdu->hdr->type == COAP_MESSAGE_CON)
            {
                sendPdu = GenerateCoAPPdu(COAP_MESSAGE_ACK, 0,
                        recvPdu->hdr->id, NULL, NULL, NULL);
                VERIFY_NON_NULL(sendPdu);
                result = SendCoAPPdu(gCoAPCtx, (coap_address_t*) &rcvdResponse->remote,
                        sendPdu,
                        (coap_send_flags_t)(rcvdResponse->secure ? SEND_SECURE_PORT : 0));
            }
            //TODO: check the standard for methods to detect wrap around condition
            if(cbNode->method == OC_REST_OBSERVE &&
                    (clientResponse.sequenceNumber <= cbNode->sequenceNumber ||
                            (clientResponse.sequenceNumber > cbNode->sequenceNumber &&
                                    clientResponse.sequenceNumber == (MAX_SEQUENCE_NUMBER))))
            {
                OC_LOG_V(DEBUG, TAG, "Observe notification came out of order. \
                        Ignoring Incoming:%d  Against Current:%d.",
                        clientResponse.sequenceNumber, cbNode->sequenceNumber);
                goto exit;
            }
            if(clientResponse.sequenceNumber > cbNode->sequenceNumber){
                cbNode->sequenceNumber = clientResponse.sequenceNumber;
            }
        }
        else
        {
            #ifdef WITH_PRESENCE
            if(isPresenceNotification)
Пример #12
0
//Start sample app 'sendrecv' on different Linux box.
void SendReceiveTest()
{
    Serial.println("entering SendReceiveTest...");
    OCDevAddr ipAddr, peerAddr, recvAddr;
    int32_t sfd;
    int32_t recvLen;
    uint8_t buf[MAX_BUF_SIZE];
    uint16_t recvPort;

    VERIFY_SUCCESS(OCBuildIPv4Address( 0, 0, 0, 0, TEST_PORT_NUM, &ipAddr), ERR_SUCCESS);
    VERIFY_SUCCESS(OCBuildIPv4Address(PEER_IP_ADDR[0], PEER_IP_ADDR[1],
                PEER_IP_ADDR[2], PEER_IP_ADDR[3], TEST_PORT_NUM, &peerAddr), ERR_SUCCESS);
    VERIFY_SUCCESS(OCInitUDP( &ipAddr, &sfd), ERR_SUCCESS);
    OC_LOG(DEBUG, MOD_NAME, PCF("Peer Addr :"));
    OC_LOG_BUFFER(INFO, MOD_NAME, peerAddr.addr, peerAddr.size);
    for (int i = 0; i < 300; i++)
    {

        OC_LOG_V(DEBUG, MOD_NAME, "--------------------- i --------------- %d", i);
        VERIFY_SUCCESS(OCSendTo(sfd, TEST_BUF, i + 10, 0, &peerAddr), i+10);

        delay(2000);
        recvLen = OCRecvFrom(sfd, buf, MAX_BUF_SIZE, 0, &recvAddr);
        if (recvLen > 0)
        {
            OC_LOG(DEBUG, MOD_NAME, PCF("Rcvd data from :"));
            OC_LOG_BUFFER(INFO, MOD_NAME, recvAddr.addr, recvAddr.size);
            OCDevAddrToPort(&recvAddr, &recvPort);
            OC_LOG_V(DEBUG, MOD_NAME, "Recv Data from Port %hu", recvPort);
            OC_LOG(DEBUG, MOD_NAME, PCF("Data Length :"));
            OC_LOG_BUFFER(INFO, MOD_NAME, (uint8_t*)&recvLen, sizeof(recvLen));
            OC_LOG(DEBUG, MOD_NAME, PCF("Data :"));
            if (recvLen < 255)
            {
                OC_LOG_BUFFER(INFO, MOD_NAME, buf, recvLen);
            }
            else
            {
                int idx = 0;
                int rem = recvLen;
                do {
                    if (rem > 255)
                    {
                        OC_LOG_BUFFER(INFO, MOD_NAME, buf + idx, 255);
                        rem = rem - 255;
                    }
                    else
                    {
                        OC_LOG_BUFFER(INFO, MOD_NAME, buf + idx, rem);
                        rem = 0;
                    }
                    idx = idx + 255;
                }while(rem > 0);
            }

        }
    }
    VERIFY_SUCCESS(OCClose( sfd), ERR_SUCCESS);
    OC_LOG(DEBUG, MOD_NAME, PCF("WifiTest - Completed"));

}