Deep sleep withe aws iot connecton
Posted: Fri Jun 23, 2017 1:47 pm
by aztech2017
Hi,
I am working on a project to send a message to aws iot every 20sec. Esp32 need to be in deep sleep and then wakeup in between.
However, I kept getting stack overflow error. Is there an example how to do this
Thank you!
Re: Deep sleep withe aws iot connecton
Posted: Fri Jun 23, 2017 3:29 pm
by ESP_krzychb
Hi @aztech2017,
You would need to combine to examples:
1. Wake up from deep sleep -
https://github.com/espressif/esp-idf/tr ... ocols/sntp
2. Sending requests to AWS -
https://github.com/espressif/esp-idf/tr ... ls/aws_iot
If you try them one by one first, this may help to rule out which part is causing the stack overflow error.
Re: Deep sleep withe aws iot connecton
Posted: Mon Jun 26, 2017 1:43 am
by aztech2017
Hi,
Thanks for your quick reply.
I tried to combine two 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, ¶msQOS0);
sprintf(cPayload, "%s : %d ", "hello from ESP32 (QOS1)", i++);
paramsQOS1.payloadLen = strlen(cPayload);
rc = aws_iot_mqtt_publish(&client, PUBTOPIC, PUBTOPIC_LEN, ¶msQOS1);
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!