35
35
#include <freertos/task.h>
36
36
#include "mender-client.h"
37
37
#include "mender-configure.h"
38
+ #include "mender-flash.h"
38
39
#include "mender-inventory.h"
39
- #include "mender-ota.h"
40
40
#include "mender-troubleshoot.h"
41
41
#include <nvs_flash.h>
42
42
#include <protocol_examples_common.h>
@@ -89,7 +89,7 @@ authentication_success_cb(void) {
89
89
/* Validate the image if it is still pending */
90
90
/* Note it is possible to do multiple diagnosic tests before validating the image */
91
91
/* In this example, authentication success with the mender-server is enough */
92
- if (MENDER_OK != (ret = mender_ota_mark_app_valid_cancel_rollback ())) {
92
+ if (MENDER_OK != (ret = mender_flash_confirm_image ())) {
93
93
ESP_LOGE (TAG , "Unable to validate the image" );
94
94
return ret ;
95
95
}
@@ -104,24 +104,22 @@ authentication_success_cb(void) {
104
104
static mender_err_t
105
105
authentication_failure_cb (void ) {
106
106
107
- static int tries = 0 ;
108
- mender_err_t ret = MENDER_OK ;
107
+ static int tries = 0 ;
108
+
109
+ /* Check if confirmation of the image is still pending */
110
+ if (true == mender_flash_is_image_confirmed ()) {
111
+ ESP_LOGE (TAG , "Mender client authentication failed" );
112
+ return MENDER_OK ;
113
+ }
109
114
110
115
/* Increment number of failures */
111
116
tries ++ ;
112
- ESP_LOGI (TAG , "Mender client authentication failed (%d/%d)" , tries , CONFIG_EXAMPLE_AUTHENTICATION_FAILS_MAX_TRIES );
113
-
114
- /* Invalidate the image if it is still pending */
115
- /* Note it is possible to invalid the image later to permit clean closure before reboot */
116
- /* In this example, several authentication failures with the mender-server is enough */
117
- if (tries >= CONFIG_EXAMPLE_AUTHENTICATION_FAILS_MAX_TRIES ) {
118
- if (MENDER_OK != (ret = mender_ota_mark_app_invalid_rollback_and_reboot ())) {
119
- ESP_LOGE (TAG , "Unable to invalidate the image" );
120
- return ret ;
121
- }
122
- }
117
+ ESP_LOGE (TAG , "Mender client authentication failed (%d/%d)" , tries , CONFIG_EXAMPLE_AUTHENTICATION_FAILS_MAX_TRIES );
123
118
124
- return ret ;
119
+ /* Restart the application after several authentication failures with the mender-server */
120
+ /* The image has not been confirmed and the bootloader will now rollback to the previous working image */
121
+ /* Note it is possible to customize this depending of the wanted behavior */
122
+ return (tries >= CONFIG_EXAMPLE_AUTHENTICATION_FAILS_MAX_TRIES ) ? MENDER_FAIL : MENDER_OK ;
125
123
}
126
124
127
125
/**
@@ -417,15 +415,15 @@ app_main(void) {
417
415
.authentication_poll_interval = 0 ,
418
416
.update_poll_interval = 0 ,
419
417
.recommissioning = false };
420
- mender_client_callbacks_t mender_client_callbacks = { .authentication_success = authentication_success_cb ,
421
- .authentication_failure = authentication_failure_cb ,
422
- .deployment_status = deployment_status_cb ,
423
- .ota_begin = mender_ota_begin ,
424
- .ota_write = mender_ota_write ,
425
- .ota_abort = mender_ota_abort ,
426
- .ota_end = mender_ota_end ,
427
- .ota_set_boot_partition = mender_ota_set_boot_partition ,
428
- .restart = restart_cb };
418
+ mender_client_callbacks_t mender_client_callbacks = { .authentication_success = authentication_success_cb ,
419
+ .authentication_failure = authentication_failure_cb ,
420
+ .deployment_status = deployment_status_cb ,
421
+ .flash . open = mender_flash_open ,
422
+ .flash . write = mender_flash_write ,
423
+ .flash . close = mender_flash_close ,
424
+ .flash . set_pending_image = mender_flash_set_pending_image ,
425
+ .flash . abort_deployment = mender_flash_abort_deployment ,
426
+ .restart = restart_cb };
429
427
ESP_ERROR_CHECK (mender_client_init (& mender_client_config , & mender_client_callbacks ));
430
428
ESP_LOGI (TAG , "Mender client initialized" );
431
429
0 commit comments