Commit da48ee46 authored by Michał Więckowski's avatar Michał Więckowski Committed by Kishen Maloor

Add send ping implementation for client

parent 0812173c
Pipeline #874 passed with stage
in 15 minutes and 36 seconds
...@@ -124,7 +124,11 @@ display_menu(void) ...@@ -124,7 +124,11 @@ display_menu(void)
PRINT("[8] Start OBSERVE resource TCP\n"); PRINT("[8] Start OBSERVE resource TCP\n");
PRINT("[9] Stop OBSERVE resource TCP\n"); PRINT("[9] Stop OBSERVE resource TCP\n");
PRINT("-----------------------------------------------\n"); PRINT("-----------------------------------------------\n");
PRINT("[10] Exit\n"); #ifdef OC_CLOUD
PRINT("[20] Send ping message\n");
PRINT("-----------------------------------------------\n");
#endif /* OC_CLOUD */
PRINT("[99] Exit\n");
PRINT("################################################\n"); PRINT("################################################\n");
PRINT("\nSelect option: \n"); PRINT("\nSelect option: \n");
} }
...@@ -270,6 +274,42 @@ GET_handler(oc_client_response_t *data) ...@@ -270,6 +274,42 @@ GET_handler(oc_client_response_t *data)
display_menu(); display_menu();
} }
#ifdef OC_CLOUD
static void
ping_handler(oc_client_response_t *data)
{
(void)data;
PRINT("\nReceived Pong\n");
}
static void
cloud_send_ping(void)
{
PRINT("\nEnter receiving endpoint: ");
char addr[256];
SCANF("%255s", addr);
char endpoint_string[267];
sprintf(endpoint_string, "coap+tcp://%s", addr);
oc_string_t ep_string;
oc_new_string(&ep_string, endpoint_string, strlen(endpoint_string));
oc_endpoint_t endpoint;
int ret = oc_string_to_endpoint(&ep_string, &endpoint, NULL);
oc_free_string(&ep_string);
if (ret < 0) {
PRINT("\nERROR parsing endpoint string\n");
return;
}
pthread_mutex_lock(&app_sync_lock);
if (oc_send_ping(false, &endpoint, 10, ping_handler, NULL)) {
PRINT("\nSuccessfully issued Ping request\n");
} else {
PRINT("\nERROR issuing Ping request\n");
}
pthread_mutex_unlock(&app_sync_lock);
signal_event_loop();
}
#endif /* OC_CLOUD */
static void static void
get_resource(bool tcp, bool observe) get_resource(bool tcp, bool observe)
{ {
...@@ -643,7 +683,12 @@ main(void) ...@@ -643,7 +683,12 @@ main(void)
case 9: case 9:
stop_observe_resource(true); stop_observe_resource(true);
break; break;
case 10: #ifdef OC_CLOUD
case 20:
cloud_send_ping();
break;
#endif /* OC_CLOUD */
case 99:
handle_signal(0); handle_signal(0);
break; break;
default: default:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment