cmd_ota.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Console example — various system commands
  2. This example code is in the Public Domain (or CC0 licensed, at your option.)
  3. Unless required by applicable law or agreed to in writing, this
  4. software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  5. CONDITIONS OF ANY KIND, either express or implied.
  6. */
  7. #include "cmd_ota.h"
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <ctype.h>
  11. #include "esp_log.h"
  12. #include "esp_console.h"
  13. #include "esp_system.h"
  14. #include "esp_sleep.h"
  15. #include "esp_spi_flash.h"
  16. #include "driver/rtc_io.h"
  17. #include "driver/uart.h"
  18. #include "argtable3/argtable3.h"
  19. #include "freertos/FreeRTOS.h"
  20. #include "freertos/task.h"
  21. #include "soc/rtc_cntl_reg.h"
  22. #include "sdkconfig.h"
  23. #include "platform_console.h"
  24. #include "messaging.h"
  25. static const char * TAG = "ota";
  26. extern esp_err_t start_ota(const char * bin_url);
  27. static struct {
  28. struct arg_str *url;
  29. struct arg_end *end;
  30. } ota_args;
  31. /* 'heap' command prints minumum heap size */
  32. static int perform_ota_update(int argc, char **argv)
  33. {
  34. int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&ota_args);
  35. if (nerrors != 0) {
  36. return 1;
  37. }
  38. const char *url = ota_args.url->sval[0];
  39. esp_err_t err=ESP_OK;
  40. ESP_LOGI(TAG, "Starting ota: %s", url);
  41. start_ota(url);
  42. if (err != ESP_OK) {
  43. ESP_LOGE(TAG, "%s", esp_err_to_name(err));
  44. return 1;
  45. }
  46. return 0;
  47. }
  48. void register_ota_cmd()
  49. {
  50. ota_args.url= arg_str1(NULL, NULL, "<url>", "url of the binary app file");
  51. ota_args.end = arg_end(2);
  52. const esp_console_cmd_t cmd = {
  53. .command = "update",
  54. .help = "Updates the application binary from the provided URL",
  55. .hint = NULL,
  56. .func = &perform_ota_update,
  57. .argtable = &ota_args
  58. };
  59. ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
  60. }