3838#include "lwip/netdb.h"
3939#include "lwip/dns.h"
4040
41+ #if CONFIG_SSL_USING_WOLFSSL
42+ #include "lwip/apps/sntp.h"
43+ #endif
44+
4145#include "esp_tls.h"
4246
4347/* The examples use simple WiFi configuration that you can set via
@@ -123,11 +127,50 @@ static void initialise_wifi(void)
123127 ESP_ERROR_CHECK ( esp_wifi_start () );
124128}
125129
130+ #if CONFIG_SSL_USING_WOLFSSL
131+ static void get_time ()
132+ {
133+ struct timeval now ;
134+ int sntp_retry_cnt = 0 ;
135+ int sntp_retry_time = 0 ;
136+
137+ sntp_setoperatingmode (0 );
138+ sntp_setservername (0 , "pool.ntp.org" );
139+ sntp_init ();
140+
141+ while (1 ) {
142+ for (int32_t i = 0 ; (i < (SNTP_RECV_TIMEOUT / 100 )) && now .tv_sec < 1525952900 ; i ++ ) {
143+ vTaskDelay (100 / portTICK_RATE_MS );
144+ gettimeofday (& now , NULL );
145+ }
146+
147+ if (now .tv_sec < 1525952900 ) {
148+ sntp_retry_time = SNTP_RECV_TIMEOUT << sntp_retry_cnt ;
149+
150+ if (SNTP_RECV_TIMEOUT << (sntp_retry_cnt + 1 ) < SNTP_RETRY_TIMEOUT_MAX ) {
151+ sntp_retry_cnt ++ ;
152+ }
153+
154+ printf ("SNTP get time failed, retry after %d ms\n" , sntp_retry_time );
155+ vTaskDelay (sntp_retry_time / portTICK_RATE_MS );
156+ } else {
157+ printf ("SNTP get time success\n" );
158+ break ;
159+ }
160+ }
161+ }
162+ #endif
163+
126164static void https_get_task (void * pvParameters )
127165{
128166 char buf [512 ];
129167 int ret , len ;
130168
169+ #if CONFIG_SSL_USING_WOLFSSL
170+ /* CA date verification need system time */
171+ get_time ();
172+ #endif
173+
131174 while (1 ) {
132175 /* Wait for the callback to set the CONNECTED_BIT in the
133176 event group.
@@ -157,7 +200,13 @@ static void https_get_task(void *pvParameters)
157200 if (ret >= 0 ) {
158201 ESP_LOGI (TAG , "%d bytes written" , ret );
159202 written_bytes += ret ;
160- } else if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE ) {
203+ } else if
204+ #if CONFIG_SSL_USING_MBEDTLS
205+ (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE )
206+ #else
207+ (ret != WOLFSSL_ERROR_WANT_READ && ret != WOLFSSL_ERROR_WANT_WRITE )
208+ #endif
209+ {
161210 ESP_LOGE (TAG , "esp_tls_conn_write returned 0x%x" , ret );
162211 goto exit ;
163212 }
@@ -170,8 +219,13 @@ static void https_get_task(void *pvParameters)
170219 len = sizeof (buf ) - 1 ;
171220 bzero (buf , sizeof (buf ));
172221 ret = esp_tls_conn_read (tls , (char * )buf , len );
173-
174- if (ret == MBEDTLS_ERR_SSL_WANT_WRITE || ret == MBEDTLS_ERR_SSL_WANT_READ )
222+
223+ if
224+ #if CONFIG_SSL_USING_MBEDTLS
225+ (ret == MBEDTLS_ERR_SSL_WANT_WRITE || ret == MBEDTLS_ERR_SSL_WANT_READ )
226+ #else
227+ (ret == WOLFSSL_ERROR_WANT_READ && ret == WOLFSSL_ERROR_WANT_WRITE )
228+ #endif
175229 continue ;
176230
177231 if (ret < 0 )
0 commit comments