After developing a program for an ESP8266 module for some time I have a few suggestions on how to improve the code. Firstly the code won't compile if "LWM2M_WITH_DTLS" is not defined, because then the "ssl.h" header doesn't get included and symbols like "MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL" stay undefined, causing compilation errors when compiling "network_lwip.c", function "mbedtls_net_send".
Also, I suggest "memset" for same measure. I have run into problems after the device receives a reply from a server. In "udp_raw_recv" declaring structure "t" without defining "net_if_out" causes it to be defined as a random number, probably because of leftovers from the previous stack. This in turn causes "if(connection->addr.net_if_out)" statement in function "mbedtls_net_send" to be true, so the program calls "udp_sendto_if" because the network interface is specified, when in reality it is not. This later causes undefined behavior in the lwip stack, usually ending in a crash, when it tries to execute a function at address "0x0000000" or similar.
The "lwm2m_get_time" function uses some internal 32bit esp buffer, running at 1MHz, so after around 70 minutes the buffer overflows, and the client registration update mechanism stops working, because suddenly "current" time is lower than "previous" time
After developing a program for an ESP8266 module for some time I have a few suggestions on how to improve the code. Firstly the code won't compile if "LWM2M_WITH_DTLS" is not defined, because then the "ssl.h" header doesn't get included and symbols like "MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL" stay undefined, causing compilation errors when compiling "network_lwip.c", function "mbedtls_net_send".
Also, I suggest "memset" for same measure. I have run into problems after the device receives a reply from a server. In "udp_raw_recv" declaring structure "t" without defining "net_if_out" causes it to be defined as a random number, probably because of leftovers from the previous stack. This in turn causes "if(connection->addr.net_if_out)" statement in function "mbedtls_net_send" to be true, so the program calls "udp_sendto_if" because the network interface is specified, when in reality it is not. This later causes undefined behavior in the lwip stack, usually ending in a crash, when it tries to execute a function at address "0x0000000" or similar.
The "lwm2m_get_time" function uses some internal 32bit esp buffer, running at 1MHz, so after around 70 minutes the buffer overflows, and the client registration update mechanism stops working, because suddenly "current" time is lower than "previous" time