Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 6 months ago.
How to update firmware using library LocalFileSystem as names are limited to 8 characters??
Hello,
I would like to update the firmware bin file: LWM2M_NanoService_Ethernet_LPC1768.bin using the LocalFileSystem library. But that doesn't seem possible. Is there a way to do it?
Thank you,
Pascal
Here my code: /* Only PUT method allowed */ static uint8_t firmware_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto) { sn_coap_hdr_s *coap_res_ptr = 0; char *firmware_binary = '\0';
pc.printf("Firmware updating-------\r\n");
if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_PUT) { FILE *fp;
firmware_binary = (char*)malloc(received_coap_ptr->payload_len * sizeof(char)); memcpy(firmware_binary, (char *)received_coap_ptr->payload_ptr, received_coap_ptr->payload_len);
TCPSocketConnection sock; sock.connect("m2mcc02.cloudapp.net", 5001);
char http_cmd[] = "GET /LWM2M_NanoService_Ethernet_LPC1768.bin HTTP/1.0\n\n"; sock.send_all(http_cmd, sizeof(http_cmd)-1); cleanupAllBinFiles(); fp = fopen("/local/out.bin", "wb"); char buffer[500]; int ret; int lenret=0; while (true) { ret = sock.receive(buffer, sizeof(buffer)-1); if (ret <= 0) { fclose(fp); copy("/local/OUT.BIN","/local/LWM2M_NanoService_Ethernet_LPC1768.bin"); pc.printf("Going out %d\n",lenret); break; } buffer[ret] = '\0'; lenret += ret; fwrite( &buffer , sizeof(buffer) , 1 , fp);
pc.printf("."); }
sock.close(); pc.printf("Received %d chars from server:\n", lenret);
coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CHANGED); sn_nsdl_send_coap_message(address, coap_res_ptr);
pc.printf("Resetting...\r\n"); mbed_reset();
status=1; result=1;
}
sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); return 0; }
Question relating to:
1 Answer
9 years, 5 months ago.
I wrote a simple application switcher demo a while back and encountered similar problems. My solution may work for you. Take a look at: https://developer.mbed.org/forum/mbed/topic/4414/?page=1#comment-22026
Hope this helps.