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.
Diff: main.cpp
- Branch:
- wakaama_mbed
- Revision:
- 7:4de75b12fbf9
- Parent:
- 1:3549d3c3967c
- Child:
- 9:279794541018
- Child:
- 14:ec9e195830ff
--- a/main.cpp Wed May 03 04:56:47 2017 +0000 +++ b/main.cpp Wed May 03 14:28:12 2017 +0800 @@ -14,7 +14,7 @@ #define LESHAN_PORT 5683 #define UDP_TIMEOUT 60000 -#define UDP_PORT 5683 +#define UDP_PORT 56830 // LCD 128X32 C12832 lcd(p5, p7, p6, p8, p11); @@ -70,8 +70,8 @@ int ret = 0; udp.open(ð); - udp.set_timeout(UDP_TIMEOUT); - udp.bind(LESHAN_PORT); + //udp.set_timeout(UDP_TIMEOUT); + udp.bind(UDP_PORT); return ret; } @@ -80,7 +80,7 @@ { int ret = 0; - // try to connect and get ip via DHCP. + //try to connect and get ip via DHCP. lcd.locate(0,10); lcd.printf("obtaining ip address...\n"); ret = eth.connect(); @@ -91,7 +91,7 @@ lcd.printf("IP is %s\n", eth.get_ip_address()); //wait(2.0); - // test code which need to be masked + //test code which only used to verify the connect functinon //test_tcp(eth); //test_udp(eth); @@ -102,7 +102,8 @@ int init_display() { - // Bootup and display initial information + int ret = 0; + //Bootup and display initial information lcd.cls(); lcd.locate(0,0); lcd.printf("mbed-wakaama-example"); @@ -110,7 +111,7 @@ lcd.printf("starting..."); //wait(2.0); - return 0; + return ret; } void debug_dump(uint8_t * buffer, size_t length) @@ -130,16 +131,15 @@ size_t length, void * userdata) { - + int ret = 0; + SocketAddress * addr = (SocketAddress*) sessionH; printf("Send packet to: %s of port %d, size: %d\n", addr->get_ip_address(), addr->get_port(),length); - + //debug_dump(buffer,length); - debug_dump(buffer,length); - - - udp.sendto(addr->get_ip_address(), addr->get_port(), (void *)buffer, (int)length); + ret = udp.sendto(addr->get_ip_address(), addr->get_port(), (void *)buffer, (int)length); + if(ret!=0) { return COAP_500_INTERNAL_SERVER_ERROR; } @@ -148,22 +148,24 @@ int main() { + int result = 0; + // Init the lwm2m char buffer[1024]; lwm2m_context_t * lwm2mH = NULL; lwm2m_object_t * objArray[3]; lwm2m_security_t security; - int result; + - // Init the lwm2m server, set Leshan as default + //Init the lwm2m server, set Leshan as default SocketAddress server(LESHAN_SERVER, LESHAN_PORT); + SocketAddress client; //SocketAddress client(LESHAN_SERVER, LESHAN_PORT); - SocketAddress client(LESHAN_SERVER, LESHAN_PORT); - // init_display + //Init display modual via LCD init_display(); - // Init the ethernet + //Init the network modual via ethernet init_ethernet(); objArray[0] = get_object_device(); @@ -173,7 +175,7 @@ return -1; } - lwm2mH = lwm2m_init("TERENCE"/*ENDPOINT_NAME*/, 1, objArray, prv_buffer_send, NULL); + lwm2mH = lwm2m_init(ENDPOINT_NAME, 1, objArray, prv_buffer_send, NULL); if (NULL == lwm2mH) { fprintf(stderr, "lwm2m_init() failed\r\n"); @@ -207,7 +209,7 @@ size = udp.recvfrom(&client, buffer, sizeof(buffer)); printf("Received packet from: %s of size %d\n", client.get_ip_address(), size); if (size>0) { - debug_dump((uint8_t *)buffer,size); + //debug_dump((uint8_t *)buffer,size); lwm2m_handle_packet(lwm2mH, (uint8_t*)buffer, size, (void*) &client); } }//while()