|
17 | 17 | #include <dfu/mcuboot.h> |
18 | 18 | #include <power/reboot.h> |
19 | 19 |
|
| 20 | +BUILD_ASSERT_MSG(!IS_ENABLED(CONFIG_LTE_AUTO_INIT_AND_CONNECT), |
| 21 | + "This sample does not support auto init and connect"); |
| 22 | + |
20 | 23 | #if defined(CONFIG_USE_NRF_CLOUD) |
21 | 24 | #define NRF_CLOUD_SECURITY_TAG 16842753 |
22 | 25 | #endif |
@@ -434,36 +437,44 @@ static int fds_init(struct mqtt_client *c) |
434 | 437 | return 0; |
435 | 438 | } |
436 | 439 |
|
437 | | -/**@brief Configures modem to provide LTE link. |
438 | | - * |
439 | | - * Blocks until link is successfully established. |
440 | | - */ |
441 | | -static void modem_configure(void) |
| 440 | +/**@brief Configures AT Command interface to the modem link. */ |
| 441 | +static void at_configure(void) |
442 | 442 | { |
443 | | -#if defined(CONFIG_LTE_LINK_CONTROL) |
444 | | - BUILD_ASSERT_MSG(!IS_ENABLED(CONFIG_LTE_AUTO_INIT_AND_CONNECT), |
445 | | - "This sample does not support auto init and connect"); |
446 | 443 | int err; |
447 | 444 |
|
448 | 445 | err = at_notif_init(); |
449 | 446 | __ASSERT(err == 0, "AT Notify could not be initialized."); |
450 | 447 | err = at_cmd_init(); |
451 | 448 | __ASSERT(err == 0, "AT CMD could not be established."); |
452 | | - printk("LTE Link Connecting ...\n"); |
453 | | - err = lte_lc_init_and_connect(); |
454 | | - __ASSERT(err == 0, "LTE link could not be established."); |
455 | | - printk("LTE Link Connected!\n"); |
456 | | -#endif |
457 | 449 | } |
458 | 450 |
|
459 | 451 | static void aws_fota_cb_handler(enum aws_fota_evt_id evt) |
460 | 452 | { |
| 453 | + int err; |
| 454 | + |
461 | 455 | switch (evt) { |
462 | 456 | case AWS_FOTA_EVT_DONE: |
463 | 457 | printk("AWS_FOTA_EVT_DONE, rebooting to apply update.\n"); |
464 | 458 | do_reboot = true; |
465 | 459 | break; |
466 | 460 |
|
| 461 | + case AWS_FOTA_EVT_ERASE_PENDING: |
| 462 | + printk("AWS_FOTA_EVT_ERASE_PENDING, reboot or disconnect the " |
| 463 | + "LTE link\n"); |
| 464 | + err = lte_lc_offline(); |
| 465 | + if (err) { |
| 466 | + printk("Error turning off the LTE link\n"); |
| 467 | + } |
| 468 | + break; |
| 469 | + |
| 470 | + case AWS_FOTA_EVT_ERASE_DONE: |
| 471 | + printk("AWS_FOTA_EVT_ERASE_DONE, reconnecting the LTE link\n"); |
| 472 | + err = lte_lc_connect(); |
| 473 | + if (err) { |
| 474 | + printk("Error reconnecting the LTE link\n"); |
| 475 | + } |
| 476 | + break; |
| 477 | + |
467 | 478 | case AWS_FOTA_EVT_ERROR: |
468 | 479 | printk("AWS_FOTA_EVT_ERROR\n"); |
469 | 480 | break; |
@@ -505,10 +516,14 @@ void main(void) |
505 | 516 | } |
506 | 517 | printk("Initialized bsdlib\n"); |
507 | 518 |
|
| 519 | + at_configure(); |
508 | 520 | #if defined(CONFIG_PROVISION_CERTIFICATES) |
509 | 521 | provision_certificates(); |
510 | 522 | #endif /* CONFIG_PROVISION_CERTIFICATES */ |
511 | | - modem_configure(); |
| 523 | + printk("LTE Link Connecting ...\n"); |
| 524 | + err = lte_lc_init_and_connect(); |
| 525 | + __ASSERT(err == 0, "LTE link could not be established."); |
| 526 | + printk("LTE Link Connected!\n"); |
512 | 527 |
|
513 | 528 | client_init(&client, CONFIG_MQTT_BROKER_HOSTNAME); |
514 | 529 |
|
|
0 commit comments