Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 363db85

Browse files
committed
Merge branch 'bugfix/fix_aws_ssl_fail_by_wolfssl' into 'master'
examples: fix aws SSL connect fail when using wolfSSL See merge request sdk/ESP8266_RTOS_SDK!974
2 parents c74d4f1 + 208d86d commit 363db85

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

examples/protocols/aws_iot/subscribe_publish/main/subscribe_publish_sample.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
#include "nvs.h"
4747
#include "nvs_flash.h"
4848

49+
#ifdef CONFIG_SSL_USING_WOLFSSL
50+
#include "lwip/apps/sntp.h"
51+
#endif
52+
4953
#include "aws_iot_config.h"
5054
#include "aws_iot_log.h"
5155
#include "aws_iot_version.h"
@@ -111,6 +115,39 @@ char HostAddress[255] = AWS_IOT_MQTT_HOST;
111115
*/
112116
uint32_t port = AWS_IOT_MQTT_PORT;
113117

118+
#ifdef CONFIG_SSL_USING_WOLFSSL
119+
static void get_time()
120+
{
121+
struct timeval now;
122+
int sntp_retry_cnt = 0;
123+
int sntp_retry_time = 0;
124+
125+
sntp_setoperatingmode(0);
126+
sntp_setservername(0, "pool.ntp.org");
127+
sntp_init();
128+
129+
while (1) {
130+
for (int32_t i = 0; (i < (SNTP_RECV_TIMEOUT / 100)) && now.tv_sec < 1525952900; i++) {
131+
vTaskDelay(100 / portTICK_RATE_MS);
132+
gettimeofday(&now, NULL);
133+
}
134+
135+
if (now.tv_sec < 1525952900) {
136+
sntp_retry_time = SNTP_RECV_TIMEOUT << sntp_retry_cnt;
137+
138+
if (SNTP_RECV_TIMEOUT << (sntp_retry_cnt + 1) < SNTP_RETRY_TIMEOUT_MAX) {
139+
sntp_retry_cnt ++;
140+
}
141+
142+
ESP_LOGE(TAG, "SNTP get time failed, retry after %d ms\n", sntp_retry_time);
143+
vTaskDelay(sntp_retry_time / portTICK_RATE_MS);
144+
} else {
145+
ESP_LOGI(TAG, "SNTP get time success\n");
146+
break;
147+
}
148+
}
149+
}
150+
#endif
114151

115152
static esp_err_t event_handler(void *ctx, system_event_t *event)
116153
{
@@ -223,6 +260,10 @@ void aws_iot_task(void *param) {
223260
xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT,
224261
false, true, portMAX_DELAY);
225262

263+
#ifdef CONFIG_SSL_USING_WOLFSSL
264+
get_time();
265+
#endif
266+
226267
connectParams.keepAliveIntervalInSec = 10;
227268
connectParams.isCleanSession = true;
228269
connectParams.MQTTVersion = MQTT_3_1_1;

0 commit comments

Comments
 (0)