Deep sleep with AWS IOT

aztech2017
Posts: 4
Joined: Fri Jun 23, 2017 6:05 am

Deep sleep with AWS IOT

Postby aztech2017 » Fri Jun 23, 2017 6:11 am

Hi,
I am experimenting deep sleep function with AWS IOT. The idea is to send a MQTT message to AWS when a GPIO is trigger and then fall back into deep sleep mode.
However, I kept getting "stack overflow" error when I am calling this inside switch cases:
rc = aws_iot_mqtt_init(&client, &mqttInitParams);
Should I use:
xTaskCreatePinnedToCore(&aws_iot_task, "aws_iot_task", stack_size, NULL, 5, NULL, 1);
Even xTaskCreate is not working at all.

Please comment or show me a working example.

Thank you very much!

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Deep sleep with AWS IOT

Postby kolban » Mon Jun 26, 2017 10:29 pm

Stack overflow errors can be caused by not allocating sufficient stack space when the task is created. Have a look at the following video:

https://www.youtube.com/watch?v=9zxU9uAifMI

It may be that the resolution is as simple as allocating more stack space for your task.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

aztech2017
Posts: 4
Joined: Fri Jun 23, 2017 6:05 am

Re: Deep sleep with AWS IOT

Postby aztech2017 » Tue Jun 27, 2017 2:13 am

Hi,
Thanks for your quick reply.
I tried to combine two ESP32 examples together. I put esp_deep_sleep function inside aws_iot_task:

while((NETWORK_ATTEMPTING_RECONNECT == rc || NETWORK_RECONNECTED == rc || SUCCESS == rc)) {

//Max time the yield function will wait for read messages
rc = aws_iot_mqtt_yield(&client, 100);
if(NETWORK_ATTEMPTING_RECONNECT == rc) {
// If the client is attempting to reconnect we will skip the rest of the loop.
continue;
}

ESP_LOGI(TAG, "-->sleep");
vTaskDelay(1000 / portTICK_RATE_MS);
sprintf(cPayload, "%s : %d ", "hello from ESP32 (QOS0)", i++);
paramsQOS0.payloadLen = strlen(cPayload);
rc = aws_iot_mqtt_publish(&client, PUBTOPIC, PUBTOPIC_LEN, &paramsQOS0);

sprintf(cPayload, "%s : %d ", "hello from ESP32 (QOS1)", i++);
paramsQOS1.payloadLen = strlen(cPayload);
rc = aws_iot_mqtt_publish(&client, PUBTOPIC, PUBTOPIC_LEN, &paramsQOS1);
if (rc == MQTT_REQUEST_TIMEOUT_ERROR) {
ESP_LOGW(TAG, "QOS1 publish ack not received.");
rc = SUCCESS;
}

ESP_LOGI(TAG, "Entering deep sleep for %d seconds", deep_sleep_sec);
esp_deep_sleep(1000000LL * deep_sleep_sec);
}

ESP_LOGE(TAG, "An error occurred in the main loop.");
abort();
}

However, I got strange error like:

I (932) wifi: n:5 0, o:1 0, ap:255 255, sta:5 0, prof:1
I (1912) wifi: state: init -> auth (b0)
I (1912) wifi: state: auth -> assoc (0)
I (1922) wifi: state: assoc -> run (10)
I (1962) wifi: connected with blessed, channel 5
I (2712) event: ip: 192.168.29.220, mask: 255.255.255.0, gw: 192.168.29.1
I (2712) subpub: Connecting to AWS...
I (9352) subpub: -->sleep
I (11922) wifi: pm start, type:0

Task watchdog got triggered. The following tasks did not feed the watchdog in time:
- IDLE (CPU 1)
Tasks currently running:
CPU 0: IDLE
CPU 1: aws_iot_task
I (20322) subpub: Entering deep sleep for 20 seconds

What is the best way to implement deep_sleep with AWS_IOT?

Thank you!

Who is online

Users browsing this forum: MicroController and 139 guests