38
38
#include "lwip/netdb.h"
39
39
#include "lwip/dns.h"
40
40
41
+ #if CONFIG_SSL_USING_WOLFSSL
42
+ #include "lwip/apps/sntp.h"
43
+ #endif
44
+
41
45
#include "esp_tls.h"
42
46
43
47
/* The examples use simple WiFi configuration that you can set via
@@ -123,11 +127,50 @@ static void initialise_wifi(void)
123
127
ESP_ERROR_CHECK ( esp_wifi_start () );
124
128
}
125
129
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
+
126
164
static void https_get_task (void * pvParameters )
127
165
{
128
166
char buf [512 ];
129
167
int ret , len ;
130
168
169
+ #if CONFIG_SSL_USING_WOLFSSL
170
+ /* CA date verification need system time */
171
+ get_time ();
172
+ #endif
173
+
131
174
while (1 ) {
132
175
/* Wait for the callback to set the CONNECTED_BIT in the
133
176
event group.
@@ -157,7 +200,13 @@ static void https_get_task(void *pvParameters)
157
200
if (ret >= 0 ) {
158
201
ESP_LOGI (TAG , "%d bytes written" , ret );
159
202
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
+ {
161
210
ESP_LOGE (TAG , "esp_tls_conn_write returned 0x%x" , ret );
162
211
goto exit ;
163
212
}
@@ -170,8 +219,13 @@ static void https_get_task(void *pvParameters)
170
219
len = sizeof (buf ) - 1 ;
171
220
bzero (buf , sizeof (buf ));
172
221
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
175
229
continue ;
176
230
177
231
if (ret < 0 )
0 commit comments