@@ -54,6 +54,49 @@ static const char *TAG = "main";
54
54
static EventGroupHandle_t mender_client_events ;
55
55
#define MENDER_CLIENT_EVENT_RESTART (1 << 0)
56
56
57
+ /**
58
+ * @brief Network connnect callback
59
+ * @return MENDER_OK if network is connected following the request, error code otherwise
60
+ */
61
+ static mender_err_t
62
+ network_connect_cb (void ) {
63
+
64
+ ESP_LOGI (TAG , "Mender client connect network" );
65
+
66
+ /* This callback can be used to configure network connection */
67
+ /* Note that the application can connect the network before if required */
68
+ /* This callback only indicates the mender-client requests network access now */
69
+ /* In this example this helper function configures Wi-Fi or Ethernet, as selected in menuconfig */
70
+ /* Read "Establishing Wi-Fi or Ethernet Connection" section in examples/protocols/README.md for more information */
71
+ if (ESP_OK != example_connect ()) {
72
+ ESP_LOGE (TAG , "Unable to connect network" );
73
+ return MENDER_FAIL ;
74
+ }
75
+
76
+ return MENDER_OK ;
77
+ }
78
+
79
+ /**
80
+ * @brief Network release callback
81
+ * @return MENDER_OK if network is released following the request, error code otherwise
82
+ */
83
+ static mender_err_t
84
+ network_release_cb (void ) {
85
+
86
+ ESP_LOGI (TAG , "Mender client released network" );
87
+
88
+ /* This callback can be used to release network connection */
89
+ /* Note that the application can keep network activated if required */
90
+ /* This callback only indicates the mender-client doesn't request network access now */
91
+ /* in this example this helper function disconnects the network */
92
+ if (ESP_OK != example_disconnect ()) {
93
+ ESP_LOGE (TAG , "Unable to disconnect network" );
94
+ return MENDER_FAIL ;
95
+ }
96
+
97
+ return MENDER_OK ;
98
+ }
99
+
57
100
/**
58
101
* @brief Authentication success callback
59
102
* @return MENDER_OK if application is marked valid and success deployment status should be reported to the server, error code otherwise
@@ -420,18 +463,11 @@ app_main(void) {
420
463
ESP_ERROR_CHECK (esp_netif_init ());
421
464
ESP_ERROR_CHECK (esp_event_loop_create_default ());
422
465
423
- /*
424
- * This helper function configures Wi-Fi or Ethernet, as selected in menuconfig.
425
- * Read "Establishing Wi-Fi or Ethernet Connection" section in
426
- * examples/protocols/README.md for more information about this function.
427
- */
428
- ESP_ERROR_CHECK (example_connect ());
429
-
430
466
/* Read base MAC address of the device */
431
467
uint8_t mac [6 ];
432
468
char mac_address [18 ];
433
- ESP_ERROR_CHECK (esp_base_mac_addr_get (mac ));
434
- snprintf (mac_address , sizeof ( mac_address ) , "%02x:%02x:%02x:%02x:%02x:%02x" , mac [0 ], mac [1 ], mac [2 ], mac [3 ], mac [4 ], mac [5 ]);
469
+ ESP_ERROR_CHECK (esp_read_mac (mac , ESP_MAC_WIFI_STA ));
470
+ sprintf (mac_address , "%02x:%02x:%02x:%02x:%02x:%02x" , mac [0 ], mac [1 ], mac [2 ], mac [3 ], mac [4 ], mac [5 ]);
435
471
ESP_LOGI (TAG , "MAC address of the device '%s'" , mac_address );
436
472
437
473
/* Create mender-client event group */
@@ -446,7 +482,7 @@ app_main(void) {
446
482
447
483
/* Compute artifact name */
448
484
char artifact_name [128 ];
449
- snprintf (artifact_name , sizeof ( artifact_name ) , "%s-v%s" , running_app_info .project_name , running_app_info .version );
485
+ sprintf (artifact_name , "%s-v%s" , running_app_info .project_name , running_app_info .version );
450
486
451
487
/* Retrieve device type */
452
488
char * device_type = running_app_info .project_name ;
@@ -461,7 +497,9 @@ app_main(void) {
461
497
.authentication_poll_interval = 0 ,
462
498
.update_poll_interval = 0 ,
463
499
.recommissioning = false };
464
- mender_client_callbacks_t mender_client_callbacks = { .authentication_success = authentication_success_cb ,
500
+ mender_client_callbacks_t mender_client_callbacks = { .network_connect = network_connect_cb ,
501
+ .network_release = network_release_cb ,
502
+ .authentication_success = authentication_success_cb ,
465
503
.authentication_failure = authentication_failure_cb ,
466
504
.deployment_status = deployment_status_cb ,
467
505
.restart = restart_cb };
0 commit comments