fix(examples): fix aws SSL connect fail when using wolfSSL
#include "nvs.h"
#include "nvs_flash.h"
+#ifdef CONFIG_SSL_USING_WOLFSSL
+#include "lwip/apps/sntp.h"
+#endif
+
#include "aws_iot_config.h"
#include "aws_iot_log.h"
#include "aws_iot_version.h"
@@ -111,6 +115,39 @@ char HostAddress[255] = AWS_IOT_MQTT_HOST;
*/
uint32_t port = AWS_IOT_MQTT_PORT;
+#ifdef 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 ++;
+ }
+
+ ESP_LOGE(TAG, "SNTP get time failed, retry after %d ms\n", sntp_retry_time);
+ vTaskDelay(sntp_retry_time / portTICK_RATE_MS);
+ } else {
+ ESP_LOGI(TAG, "SNTP get time success\n");
+ break;
+ }
+ }
+}
+#endif
static esp_err_t event_handler(void *ctx, system_event_t *event)
{
@@ -223,6 +260,10 @@ void aws_iot_task(void *param) {
xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT,
false, true, portMAX_DELAY);
+#ifdef CONFIG_SSL_USING_WOLFSSL
+ get_time();
+#endif
+
connectParams.keepAliveIntervalInSec = 10;
connectParams.isCleanSession = true;
connectParams.MQTTVersion = MQTT_3_1_1;
