Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of coap-example by
Revision 2:6704302e21c7, committed 2018-06-28
- Comitter:
- Martin1997
- Date:
- Thu Jun 28 14:16:47 2018 +0000
- Parent:
- 1:0615912bf8ec
- Commit message:
- working client
Changed in this revision
source/main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/source/main.cpp Thu Jun 28 14:11:10 2018 +0000 +++ b/source/main.cpp Thu Jun 28 14:16:47 2018 +0000 @@ -124,20 +124,30 @@ // UDPSocket::recvfrom is blocking, so run it in a separate RTOS thread recvfromThread.start(&recvfromMain); - -/* - while(endless){ -*/ // Path to the resource we want to retrieve + + + // const char* coap_uri_path = "1214"; + // + // See ns_coap_header.h sn_coap_hdr_s *coap_res_ptr = (sn_coap_hdr_s*)calloc(sizeof(sn_coap_hdr_s), 1); + coap_res_ptr->uri_path_ptr = (uint8_t*)coap_uri_path; // Path coap_res_ptr->uri_path_len = strlen(coap_uri_path); + + + + // coap_res_ptr->msg_code = COAP_MSG_CODE_REQUEST_GET; // CoAP method + // + + + coap_res_ptr->content_format = COAP_CT_TEXT_PLAIN; // CoAP content type coap_res_ptr->payload_len = 0; // Body length coap_res_ptr->payload_ptr = 0; // Body pointer @@ -146,6 +156,8 @@ // See the receive code to verify that we get the same message ID back coap_res_ptr->msg_id = 7; + + // Calculate the CoAP message size, allocate the memory and build the message uint16_t message_len = sn_coap_builder_calc_needed_packet_data_size(coap_res_ptr); printf("Calculated message length: %d bytes\n", message_len); @@ -153,13 +165,6 @@ uint8_t* message_ptr = (uint8_t*)malloc(message_len); sn_coap_builder(message_ptr, coap_res_ptr); - // Uncomment to see the raw buffer that will be sent... - // printf("Message is: "); - // for (size_t ix = 0; ix < message_len; ix++) { - // printf("%02x ", message_ptr[ix]); - // } - // printf("\n"); - int scount = socket.sendto(TARGET_IP, TARGET_PORT, message_ptr, message_len); printf("Sent %d bytes to %s:%d \n", scount,TARGET_IP, TARGET_PORT); @@ -167,23 +172,4 @@ free(message_ptr); Thread::wait(osWaitForever); - - - -/* - printf("Type /'t/' to send again, press /'f/' to stop"); - char c = pc.getc(); - - if(c == 't') - { - endless = true; - } - if(c == 'f') - { - endless = false; - } - } -*/ - - }