Skip to content

Commit

Permalink
Merge branch 'example/https_request_v3.1' into 'release/v3.1'
Browse files Browse the repository at this point in the history
Support using wolfSSL library (backport v3.1)

See merge request sdk/ESP8266_RTOS_SDK!755
  • Loading branch information
donghengqaz committed Jan 30, 2019
2 parents 6fe1882 + bc30620 commit 7a660b4
Showing 1 changed file with 57 additions and 3 deletions.
60 changes: 57 additions & 3 deletions examples/protocols/https_request/main/https_request_example_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
#include "lwip/netdb.h"
#include "lwip/dns.h"

#if CONFIG_SSL_USING_WOLFSSL
#include "lwip/apps/sntp.h"
#endif

#include "esp_tls.h"

/* The examples use simple WiFi configuration that you can set via
Expand Down Expand Up @@ -123,11 +127,50 @@ static void initialise_wifi(void)
ESP_ERROR_CHECK( esp_wifi_start() );
}

#if CONFIG_SSL_USING_WOLFSSL
static void get_time()
{
struct timeval now;
int sntp_retry_cnt = 0;
int sntp_retry_time = 0;

sntp_setoperatingmode(0);
sntp_setservername(0, "pool.ntp.org");
sntp_init();

while (1) {
for (int32_t i = 0; (i < (SNTP_RECV_TIMEOUT / 100)) && now.tv_sec < 1525952900; i++) {
vTaskDelay(100 / portTICK_RATE_MS);
gettimeofday(&now, NULL);
}

if (now.tv_sec < 1525952900) {
sntp_retry_time = SNTP_RECV_TIMEOUT << sntp_retry_cnt;

if (SNTP_RECV_TIMEOUT << (sntp_retry_cnt + 1) < SNTP_RETRY_TIMEOUT_MAX) {
sntp_retry_cnt ++;
}

printf("SNTP get time failed, retry after %d ms\n", sntp_retry_time);
vTaskDelay(sntp_retry_time / portTICK_RATE_MS);
} else {
printf("SNTP get time success\n");
break;
}
}
}
#endif

static void https_get_task(void *pvParameters)
{
char buf[512];
int ret, len;

#if CONFIG_SSL_USING_WOLFSSL
/* CA date verification need system time */
get_time();
#endif

while(1) {
/* Wait for the callback to set the CONNECTED_BIT in the
event group.
Expand Down Expand Up @@ -157,7 +200,13 @@ static void https_get_task(void *pvParameters)
if (ret >= 0) {
ESP_LOGI(TAG, "%d bytes written", ret);
written_bytes += ret;
} else if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) {
} else if
#if CONFIG_SSL_USING_MBEDTLS
(ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE)
#else
(ret != WOLFSSL_ERROR_WANT_READ && ret != WOLFSSL_ERROR_WANT_WRITE)
#endif
{
ESP_LOGE(TAG, "esp_tls_conn_write returned 0x%x", ret);
goto exit;
}
Expand All @@ -170,8 +219,13 @@ static void https_get_task(void *pvParameters)
len = sizeof(buf) - 1;
bzero(buf, sizeof(buf));
ret = esp_tls_conn_read(tls, (char *)buf, len);

if(ret == MBEDTLS_ERR_SSL_WANT_WRITE || ret == MBEDTLS_ERR_SSL_WANT_READ)

if
#if CONFIG_SSL_USING_MBEDTLS
(ret == MBEDTLS_ERR_SSL_WANT_WRITE || ret == MBEDTLS_ERR_SSL_WANT_READ)
#else
(ret == WOLFSSL_ERROR_WANT_READ && ret == WOLFSSL_ERROR_WANT_WRITE)
#endif
continue;

if(ret < 0)
Expand Down

0 comments on commit 7a660b4

Please sign in to comment.