- I (268) cpu_start: Pro cpu u
- p.
- I (269) cpu_start: Application information:
- I (269) cpu_start: Project name: V2
- I (269) cpu_start: App version: 2f76511-dirty
- I (269) cpu_start: Compile time: Jan 27 2020 10:23:00
- I (269) cpu_start: ELF file SHA256: 1b2e752ef3bbbe53...
- I (270) cpu_start: ESP-IDF: v3.3.1-dirty
- I (270) cpu_start: Starting app cpu, entry point is 0x40080f8c
- 0x40080f8c: call_start_cpu1 at C:/msys32/home/bgoldbach/Git/esp-idf/components/esp32/cpu_start.c:269
- I (254) cpu_start: App cpu up.
- D (271) memory_layout: Checking 7 reserved memory ranges:
- D (271) memory_layout: Reserved memory range 0x3ffae000 - 0x3ffae6e0
- D (271) memory_layout: Reserved memory range 0x3ffb0000 - 0x3ffb8768
- D (272) memory_layout: Reserved memory range 0x3ffe0000 - 0x3ffe0440
- D (272) memory_layout: Reserved memory range 0x3ffe3f20 - 0x3ffe4350
- D (272) memory_layout: Reserved memory range 0x40070000 - 0x40078000
- D (273) memory_layout: Reserved memory range 0x40078000 - 0x40080000
- 0x40080000: _WindowOverflow4 at C:/msys32/home/bgoldbach/Git/esp-idf/components/freertos/xtensa_vectors.S:1779
- D (273) memory_layout: Reserved memory range 0x40080000 - 0x4008fc61
- 0x40080000: _WindowOverflow4 at C:/msys32/home/bgoldbach/Git/esp-idf/components/freertos/xtensa_vectors.S:1779
- D (273) memory_layout: Building list of available memory regions:
- D (274) memory_layout: Available memory region 0x3ffae6e0 - 0x3ffb0000
- D (274) memory_layout: Available memory region 0x3ffb8768 - 0x3ffc0000
- D (274) memory_layout: Available memory region 0x3ffc0000 - 0x3ffc2000
- D (275) memory_layout: Available memory region 0x3ffc2000 - 0x3ffc4000
- D (275) memory_layout: Available memory region 0x3ffc4000 - 0x3ffc6000
- D (276) memory_layout: Available memory region 0x3ffc6000 - 0x3ffc8000
- D (276) memory_layout: Available memory region 0x3ffc8000 - 0x3ffca000
- D (276) memory_layout: Available memory region 0x3ffca000 - 0x3ffcc000
- D (277) memory_layout: Available memory region 0x3ffcc000 - 0x3ffce000
- D (277) memory_layout: Available memory region 0x3ffce000 - 0x3ffd0000
- D (278) memory_layout: Available memory region 0x3ffd0000 - 0x3ffd2000
- D (278) memory_layout: Available memory region 0x3ffd2000 - 0x3ffd4000
- D (278) memory_layout: Available memory region 0x3ffd4000 - 0x3ffd6000
- D (279) memory_layout: Available memory region 0x3ffd6000 - 0x3ffd8000
- D (279) memory_layout: Available memory region 0x3ffd8000 - 0x3ffda000
- D (279) memory_layout: Available memory region 0x3ffda000 - 0x3ffdc000
- D (280) memory_layout: Available memory region 0x3ffdc000 - 0x3ffde000
- D (280) memory_layout: Available memory region 0x3ffde000 - 0x3ffe0000
- D (281) memory_layout: Available memory region 0x3ffe0440 - 0x3ffe3f20
- D (281) memory_layout: Available memory region 0x3ffe4350 - 0x3ffe8000
- D (281) memory_layout: Available memory region 0x3ffe8000 - 0x3fff0000
- D (282) memory_layout: Available memory region 0x3fff0000 - 0x3fff8000
- D (282) memory_layout: Available memory region 0x3fff8000 - 0x3fffc000
- D (282) memory_layout: Available memory region 0x3fffc000 - 0x40000000
- D (283) memory_layout: Available memory region 0x4008fc64 - 0x40090000
- D (283) memory_layout: Available memory region 0x40090000 - 0x40092000
- D (284) memory_layout: Available memory region 0x40092000 - 0x40094000
- D (284) memory_layout: Available memory region 0x40094000 - 0x40096000
- D (284) memory_layout: Available memory region 0x40096000 - 0x40098000
- D (285) memory_layout: Available memory region 0x40098000 - 0x4009a000
- D (285) memory_layout: Available memory region 0x4009a000 - 0x4009c000
- D (286) memory_layout: Available memory region 0x4009c000 - 0x4009e000
- D (286) memory_layout: Available memory region 0x4009e000 - 0x400a0000
- I (286) heap_init: Initializing. RAM available for dynamic allocation:
- D (287) heap_init: New heap initialised at 0x3ffae6e0
- I (287) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
- D (287) heap_init: New heap initialised at 0x3ffb8768
- I (288) heap_init: At 3FFB8768 len 00027898 (158 KiB): DRAM
- I (288) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
- I (288) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
- D (289) heap_init: New heap initialised at 0x4008fc64
- I (289) heap_init: At 4008FC64 len 0001039C (64 KiB): IRAM
- I (289) cpu_start: Pro cpu start user code
- D (297) clk: RTC_SLOW_CLK calibration value: 3590605
- D (74) intr_alloc: Connected src 46 to int 2 (cpu 0)
- D (75) intr_alloc: Connected src 57 to int 3 (cpu 0)
- D (75) stack_chk: Intialize random stack guard
- D (76) intr_alloc: Connected src 24 to int 9 (cpu 0)
- I (77) cpu_start: Starting scheduler on PRO CPU.
- D (0) intr_alloc: Connected src 25 to int 2 (cpu 1)
- I (0) cpu_start: Starting scheduler on APP CPU.
- D (77) heap_init: New heap initialised at 0x3ffe0440
- D (77) heap_init: New heap initialised at 0x3ffe4350
- D (77) intr_alloc: Connected src 16 to int 12 (cpu 0)
- D (77) nvs: nvs_flash_init_custom partition=nvs start=9 count=4
- Task Watchdog Enabled
- D (97) nvs: nvs_open_from_partition misc 1
- D (107) nvs: nvs_get_str_or_blob log
- D (107) nvs: nvs_erase_key log
- D (107) nvs: nvs_get_str_or_blob log
- D (107) nvs: nvs_set_blob log 24
- I (117) wifi: wifi driver task: 3ffc3800, prio:23, stack:3584, core=1
- I (117) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
- D (117) efuse: coding scheme 0
- D (117) efuse: In EFUSE_BLK0__DATA2_REG is used 8 bits starting with 8 bit
- D (117) efuse: coding scheme 0
- D (117) efuse: In EFUSE_BLK0__DATA2_REG is used 8 bits starting with 0 bit
- D (117) efuse: coding scheme 0
- D (117) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 24 bit
- D (117) efuse: coding scheme 0
- D (117) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 16 bit
- D (117) efuse: coding scheme 0
- D (117) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 8 bit
- D (117) efuse: coding scheme 0
- D (117) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 0 bit
- D (117) efuse: coding scheme 0
- D (117) efuse: In EFUSE_BLK0__DATA2_REG is used 8 bits starting with 16 bit
- I (117) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
- D (117) efuse: coding scheme 0
- D (117) efuse: In EFUSE_BLK0__DATA2_REG is used 8 bits starting with 8 bit
- D (117) efuse: coding scheme 0
- D (117) efuse: In EFUSE_BLK0__DATA2_REG is used 8 bits starting with 0 bit
- D (117) efuse: coding scheme 0
- D (117) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 24 bit
- D (117) efuse: coding scheme 0
- D (117) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 16 bit
- D (117) efuse: coding scheme 0
- D (117) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 8 bit
- D (117) efuse: coding scheme 0
- D (117) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 0 bit
- D (117) efuse: coding scheme 0
- D (117) efuse: In EFUSE_BLK0__DATA2_REG is used 8 bits starting with 16 bit
- D (127) nvs: nvs_open_from_partition nvs.net80211 1
- D (127) nvs: nvs_get opmode 1
- D (127) nvs: nvs_get_str_or_blob sta.ssid
- D (127) nvs: nvs_get_str_or_blob sta.mac
- D (127) nvs: nvs_get sta.authmode 1
- D (127) nvs: nvs_get_str_or_blob sta.pswd
- D (127) nvs: nvs_get_str_or_blob sta.pmk
- D (127) nvs: nvs_get sta.chan 1
- D (127) nvs: nvs_get auto.conn 1
- D (127) nvs: nvs_get bssid.set 1
- D (127) nvs: nvs_get_str_or_blob sta.bssid
- D (127) nvs: nvs_get sta.lis_intval 2
- D (127) nvs: nvs_get sta.phym 1
- D (127) nvs: nvs_get sta.phybw 1
- D (127) nvs: nvs_get_str_or_blob sta.apsw
- D (127) nvs: nvs_get_str_or_blob sta.apinfo
- D (127) nvs: nvs_get sta.scan_method 1
- D (127) nvs: nvs_get sta.sort_method 1
- D (127) nvs: nvs_get sta.minrssi 1
- D (137) nvs: nvs_get sta.minauth 1
- D (137) nvs: nvs_get_str_or_blob ap.ssid
- D (137) nvs: nvs_get_str_or_blob ap.mac
- D (137) nvs: nvs_get_str_or_blob ap.passwd
- D (137) nvs: nvs_get_str_or_blob ap.pmk
- D (137) nvs: nvs_get ap.chan 1
- D (137) nvs: nvs_get ap.authmode 1
- D (137) nvs: nvs_get ap.hidden 1
- D (137) nvs: nvs_get ap.max.conn 1
- D (137) nvs: nvs_get bcn.interval 2
- D (137) nvs: nvs_get ap.phym 1
- D (137) nvs: nvs_get ap.phybw 1
- D (137) nvs: nvs_get ap.sndchan 1
- D (137) nvs: nvs_get lorate 1
- D (137) nvs: nvs_set_blob sta.mac 6
- D (137) nvs: nvs_set_blob ap.mac 6
- I (147) wifi: wifi firmware version: ac331d7
- I (147) wifi: config NVS flash: enabled
- I (147) wifi: config nano formating: disabled
- I (147) wifi: Init dynamic tx buffer num: 16
- I (147) wifi: Init data frame dynamic rx buffer num: 8
- I (147) wifi: Init management frame dynamic rx buffer num: 8
- I (147) wifi: Init management short buffer num: 32
- I (147) wifi: Init static rx buffer size: 1600
- I (147) wifi: Init static rx buffer num: 8
- I (147) wifi: Init dynamic rx buffer num: 8
- I (147) wifi: Set ps type: 0
- I (147) test_http: Connecting to: ssid: TESTWF
- D (147) RTC_MODULE: Wi-Fi takes adc2 lock.
- D (147) phy_init: loading PHY init data from application binary
- D (147) nvs: nvs_open_from_partition phy 0
- D (147) nvs: nvs_get cal_version 4
- D (147) nvs: nvs_get_str_or_blob cal_mac
- D (147) efuse: coding scheme 0
- D (147) efuse: In EFUSE_BLK0__DATA2_REG is used 8 bits starting with 8 bit
- D (147) efuse: coding scheme 0
- D (147) efuse: In EFUSE_BLK0__DATA2_REG is used 8 bits starting with 0 bit
- D (147) efuse: coding scheme 0
- D (147) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 24 bit
- D (147) efuse: coding scheme 0
- D (147) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 16 bit
- D (147) efuse: coding scheme 0
- D (147) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 8 bit
- D (147) efuse: coding scheme 0
- D (147) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 0 bit
- D (147) efuse: coding scheme 0
- D (147) efuse: In EFUSE_BLK0__DATA2_REG is used 8 bits starting with 16 bit
- D (157) nvs: nvs_get_str_or_blob cal_data
- D (157) nvs: nvs_close 3
- D (157) efuse: coding scheme 0
- D (157) efuse: In EFUSE_BLK0__DATA2_REG is used 8 bits starting with 8 bit
- D (157) efuse: coding scheme 0
- D (157) efuse: In EFUSE_BLK0__DATA2_REG is used 8 bits starting with 0 bit
- D (157) efuse: coding scheme 0
- D (157) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 24 bit
- D (157) efuse: coding scheme 0
- D (157) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 16 bit
- D (157) efuse: coding scheme 0
- D (157) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 8 bit
- D (157) efuse: coding scheme 0
- D (157) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 0 bit
- D (157) efuse: coding scheme 0
- D (157) efuse: In EFUSE_BLK0__DATA2_REG is used 8 bits starting with 16 bit
- I (247) phy: phy_version: 4102, 2fa7a43, Jul 15 2019, 13:06:06, 0, 0
- I (247) wifi: mode : sta (30:ae:a4:26:a7:04)
- D (247) event: SYSTEM_EVENT_STA_START
- I (247) test_http: Wifi started.
- I (2297) wifi: new:<5,0>, old:<1,0>, ap:<255,255>, sta:<5,0>, prof:1
- I (2307) wifi: state: init -> auth (b0)
- I (3307) wifi: state: auth -> init (200)
- I (3307) wifi: new:<5,0>, old:<5,0>, ap:<255,255>, sta:<5,0>, prof:1
- D (3307) event: SYSTEM_EVENT_STA_DISCONNECTED, ssid:TESTWF, ssid_len:6, bssid:24:f5:a2:04:0f:fb, reason:2,wifi reason: auth expire
- D (3307) tcpip_adapter: if0 start ip lost tmr: enter
- D (3307) tcpip_adapter: if0 start ip lost tmr: no need start because netif=0x3ffc7700 interval=120 ip=0
- I (3307) test_http: Wifi disconnected. Reconnecting...
- D (5357) event: SYSTEM_EVENT_STA_DISCONNECTED, ssid:TESTWF, ssid_len:6, bssid:00:00:00:00:00:00, reason:205,wifi reason: other reason
- D (5357) tcpip_adapter: if0 start ip lost tmr: enter
- D (5357) tcpip_adapter: if0 start ip lost tmr: no need start because netif=0x3ffc7700 interval=120 ip=0
- I (5357) test_http: Wifi disconnected. Reconnecting...
- I (7407) wifi: new:<5,0>, old:<5,0>, ap:<255,255>, sta:<5,0>, prof:1
- I (7407) wifi: state: init -> auth (b0)
- I (7447) wifi: state: auth -> assoc (0)
- I (7477) wifi: state: assoc -> run (10)
- I (9637) wifi: connected with TESTWF, aid = 1, channel 5, BW20, bssid = 24:f5:a2:04:0f:fb
- I (9637) wifi: security type: 3, phy: bgn, rssi: -78
- D (9637) nvs: nvs_set sta.chan 1 5
- D (9637) nvs: nvs_set_blob sta.apinfo 700
- I (9647) wifi: pm start, type: 0
- D (9647) event: SYSTEM_EVENT_STA_CONNECTED, ssid:TESTWF, ssid_len:6, bssid:24:f5:a2:04:0f:fb, channel:5, authmode:3
- D (9647) tcpip_adapter: dhcp client init ip/mask/gw to all-0
- D (9647) tcpip_adapter: if0 start ip lost tmr: enter
- D (9647) tcpip_adapter: if0 start ip lost tmr: no need start because netif=0x3ffc7700 interval=120 ip=0
- D (9647) tcpip_adapter: dhcp client start successfully
- I (9647) test_http: Wifi Connected.
- I (9867) wifi: AP's beacon interval = 102400 us, DTIM period = 1
- D (10147) tcpip_adapter: if0 dhcpc cb
- D (10147) tcpip_adapter: if0 ip changed=1
- D (10147) event: SYSTEM_EVENT_STA_GOT_IP, ip:192.168.1.107, mask:255.255.255.0, gw:192.168.1.1
- I (10147) event: sta ip: 192.168.1.107, mask: 255.255.255.0, gw: 192.168.1.1
- I (10147) test_http: IP Obtained.
- D (10147) HTTP_CLIENT: set post file length = 12799
- D (10147) HTTP_CLIENT: Begin connect to: http://www.google.com:80
- D (10237) TRANS_TCP: [sock=48],connecting to server IP:64.233.177.106,Port:80...
- D (10267) HTTP_CLIENT: Write header[4]: POST / HTTP/1.1
- User-Agent: ESP32 HTTP Client/1.0
- Host: www.google.com
- Content-Type: application/x-www-form-urlencoded
- Content-Length: 12799
- I (11147) Status: 1 seconds since startup.
- E (11677) test_http: HTTP POST request failed: ESP_FAIL
- I (12147) Status: 2 seconds since startup.
- D (12677) HTTP_CLIENT: set post file length = 12799
- D (12677) HTTP_CLIENT: Begin connect to: http://www.google.com:80
- D (12677) TRANS_TCP: [sock=49],connecting to server IP:64.233.177.106,Port:80...
- D (12757) HTTP_CLIENT: Write header[4]: POST / HTTP/1.1
- User-Agent: ESP32 HTTP Client/1.0
- Host: www.google.com
- Content-Type: application/x-www-form-urlencoded
- Content-Length: 12799
- I (13147) Status: 3 seconds since startup.
- I (14147) Status: 4 seconds since startup.
- I (15147) Status: 5 seconds since startup.
- I (16147) Status: 6 seconds since startup.
- E (16867) test_http: HTTP POST request failed: ESP_FAIL
- I (17147) Status: 7 seconds since startup.
- D (17867) HTTP_CLIENT: set post file length = 12799
- D (17867) HTTP_CLIENT: Begin connect to: http://www.google.com:80
- D (17867) TRANS_TCP: [sock=50],connecting to server IP:64.233.177.106,Port:80...
- D (17877) HTTP_CLIENT: Write header[4]: POST / HTTP/1.1
- User-Agent: ESP32 HTTP Client/1.0
- Host: www.google.com
- Content-Type: application/x-www-form-urlencoded
- Content-Length: 12799
- I (18147) Status: 8 seconds since startup.
- I (19147) Status: 9 seconds since startup.
- I (20147) Status: 10 seconds since startup.
- I (21147) Status: 11 seconds since startup.
- I (22147) Status: 12 seconds since startup.
- I (23147) Status: 13 seconds since startup.
- I (24147) Status: 14 seconds since startup.
- I (25147) Status: 15 seconds since startup.
- I (26147) Status: 16 seconds since startup.
- I (27147) Status: 17 seconds since startup.
- I (28147) Status: 18 seconds since startup.
- I (29147) Status: 19 seconds since startup.
- I (30147) Status: 20 seconds since startup.
- I (31147) Status: 21 seconds since startup.
- I (32147) Status: 22 seconds since startup.
- I (33147) Status: 23 seconds since startup.
- I (34147) Status: 24 seconds since startup.
- I (35147) Status: 25 seconds since startup.
- I (36147) Status: 26 seconds since startup.
- I (37147) Status: 27 seconds since startup.
- I (38147) Status: 28 seconds since startup.
- I (39147) Status: 29 seconds since startup.
- I (40147) Status: 30 seconds since startup.
- I (41147) Status: 31 seconds since startup.
- I (42147) Status: 32 seconds since startup.
- I (43147) Status: 33 seconds since startup.
- I (44147) Status: 34 seconds since startup.
- I (45147) Status: 35 seconds since startup.
- I (46147) Status: 36 seconds since startup.
- I (47147) Status: 37 seconds since startup.
- I (48147) Status: 38 seconds since startup.
- I (49147) Status: 39 seconds since startup.
- I (50147) Status: 40 seconds since startup.
- I (51147) Status: 41 seconds since startup.
- I (52147) Status: 42 seconds since startup.
- I (53147) Status: 43 seconds since startup.
- I (54147) Status: 44 seconds since startup.
- I (55147) Status: 45 seconds since startup.
- I (56147) Status: 46 seconds since startup.
- I (57147) Status: 47 seconds since startup.
- I (58147) Status: 48 seconds since startup.
- I (59147) Status: 49 seconds since startup.
- I (60147) Status: 50 seconds since startup.
- I (61147) Status: 51 seconds since startup.
- I (62147) Status: 52 seconds since startup.
- I (63147) Status: 53 seconds since startup.
- I (64147) Status: 54 seconds since startup.
- I (65147) Status: 55 seconds since startup.
- I (66147) Status: 56 seconds since startup.
- I (67147) Status: 57 seconds since startup.
- I (68147) Status: 58 seconds since startup.
- I (69147) Status: 59 seconds since startup.
- I (70147) Status: 60 seconds since startup.
- I (71147) Status: 61 seconds since startup.
- I (72147) Status: 62 seconds since startup.
- I (73147) Status: 63 seconds since startup.
- I (74147) Status: 64 seconds since startup.
- I (75147) Status: 65 seconds since startup.
- I (76147) Status: 66 seconds since startup.
- I (77147) Status: 67 seconds since startup.
- I (78147) Status: 68 seconds since startup.
- I (79147) Status: 69 seconds since startup.
This test is currently running on esp-idf 3.3.1 but have had similar failures on 3.2.X. I have found that the larger the file being sent the more likely it is to get stuck. And when the transmission does get stuck it also does not trigger the watchdog as it is supposed to after a minute.
Given time the device may get out of this state, but it is expected to timeout properly.
Device model: ESP_WROOM_32D (rev 1)
ESP-IDF Version: 3.3.1
Example Code:
- #include "nvs_flash.h"
- #include "lwip/err.h"
- #include "lwip/sockets.h"
- #include "lwip/sys.h"
- #include "lwip/netdb.h"
- #include "lwip/dns.h"
- #include "lwip/apps/sntp.h"
- #include "lwip/inet.h"
- #include "freertos/event_groups.h"
- #include "esp_err.h"
- #include "esp_log.h"
- #include "esp_wifi.h"
- #include "esp_event.h"
- #include "esp_event_loop.h"
- #include "esp_system.h"
- #include "esp_http_client.h"
- #include "esp_task_wdt.h"
- #include <tcpip_adapter.h>
- #include <string.h>
- #define WIFI_CONNECT_TIMEOUT 20000/portTICK_PERIOD_MS
- #define WIFI_CONNECTED_BIT BIT0
- #define SSID "TESTWF"
- #define PASSWORD "testwfpw"
- #define HTTP_DEFAULT_BUFFER_SIZE 16384
- #define HTTP_DEFAULT_TIMEOUT_MS 5000
- #define HTTP_DEFAULT_URL "http://www.google.com"
- #define HTTP_SAMPLE_DATA_SIZE 12800
- esp_http_client_handle_t client = NULL;
- EventGroupHandle_t wifi_event_group;
- char* TAG = "test_http";
- esp_err_t wifi_event_handler(void *ctx, system_event_t *event) {
- switch (event->event_id) {
- case SYSTEM_EVENT_SCAN_DONE:
- ESP_LOGI(TAG, "Wifi scan done.");
- break;
- case SYSTEM_EVENT_STA_START:
- ESP_LOGI(TAG, "Wifi started.");
- xEventGroupClearBits(wifi_event_group, WIFI_CONNECTED_BIT);
- esp_wifi_connect();
- break;
- case SYSTEM_EVENT_STA_STOP:
- ESP_LOGI(TAG, "Wifi stopped.");
- break;
- case SYSTEM_EVENT_STA_GOT_IP:
- ESP_LOGI(TAG, "IP Obtained.");
- xEventGroupSetBits(wifi_event_group, WIFI_CONNECTED_BIT);
- break;
- case SYSTEM_EVENT_STA_LOST_IP:
- ESP_LOGI(TAG, "IP lost.");
- break;
- case SYSTEM_EVENT_STA_CONNECTED:
- ESP_LOGI(TAG, "Wifi Connected.");
- break;
- case SYSTEM_EVENT_STA_DISCONNECTED:
- ESP_LOGI(TAG, "Wifi disconnected. Reconnecting...");
- esp_wifi_connect();
- xEventGroupClearBits(wifi_event_group, WIFI_CONNECTED_BIT);
- break;
- case SYSTEM_EVENT_AP_START:
- ESP_LOGI(TAG, "Access Point Started.");
- break;
- case SYSTEM_EVENT_AP_STOP:
- ESP_LOGI(TAG, "Access Point Stopped.");
- break;
- case SYSTEM_EVENT_AP_STACONNECTED:
- ESP_LOGI(TAG, "Device Connected to AP.");
- break;
- case SYSTEM_EVENT_AP_STADISCONNECTED:
- ESP_LOGI(TAG, "Device Disconnected from AP.");
- break;
- case SYSTEM_EVENT_AP_PROBEREQRECVED:
- ESP_LOGI(TAG, "Probe Request.");
- break;
- default:
- ESP_LOGE(TAG, "ERROR: Unhandled Wi-Fi Event: %d", event->event_id);
- break;
- }
- return ESP_OK;
- }
- esp_err_t _http_event_handler(esp_http_client_event_t *evt) {
- switch (evt->event_id) {
- case HTTP_EVENT_ERROR:
- ESP_LOGE(TAG, "HTTP_EVENT_ERROR");
- break;
- case HTTP_EVENT_ON_CONNECTED:
- break;
- case HTTP_EVENT_HEADER_SENT:
- break;
- case HTTP_EVENT_ON_HEADER:
- ESP_LOGI(TAG, "HTTP_EVENT_ON_HEADER, key=%s, value=%s", evt->header_key, evt->header_value);
- break;
- case HTTP_EVENT_ON_DATA:
- break;
- case HTTP_EVENT_ON_FINISH:
- break;
- case HTTP_EVENT_DISCONNECTED:
- break;
- }
- return ESP_OK;
- }
- esp_err_t wifi_init(void) {
- wifi_config_t sta_config;
- //init TCPIP, Event Group, and wifi.
- tcpip_adapter_init();
- wifi_event_group = xEventGroupCreate();
- esp_event_loop_init(wifi_event_handler, NULL);;
- wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
- esp_wifi_init(&cfg);
- esp_wifi_set_storage(WIFI_STORAGE_FLASH);
- esp_wifi_set_mode(WIFI_MODE_STA);
- esp_wifi_set_ps(WIFI_PS_NONE);
- //init credentials
- esp_wifi_get_config(WIFI_IF_STA, &sta_config);
- sprintf((char*)sta_config.sta.ssid, SSID);
- sprintf((char*)sta_config.sta.password, PASSWORD);
- sta_config.sta.bssid_set = false;
- esp_wifi_set_config(WIFI_IF_STA, &sta_config);
- //attempt to connect
- ESP_LOGI(TAG, "Connecting to: ssid: %s\n", sta_config.sta.ssid);
- esp_wifi_start();
- if (strlen((char*)sta_config.sta.ssid) != 0) {
- if (esp_wifi_connect() != ESP_OK) return ESP_FAIL;
- }
- else return ESP_ERR_WIFI_SSID;
- //wait for connection
- xEventGroupWaitBits(wifi_event_group, WIFI_CONNECTED_BIT, false, true, WIFI_CONNECT_TIMEOUT);
- if (xEventGroupGetBits(wifi_event_group) & WIFI_CONNECTED_BIT) {
- return ESP_OK;
- }
- return ESP_FAIL;
- }
- esp_err_t wifi_http_init(uint16_t buffer_size, uint16_t timeout, char* url) {
- // config setup
- if (client != NULL) return ESP_FAIL;
- esp_http_client_config_t config;
- memset(&config, 0, sizeof(esp_http_client_config_t));
- config.url = url;
- config.event_handler = _http_event_handler;
- config.buffer_size = buffer_size;
- config.timeout_ms = timeout;
- client = esp_http_client_init(&config);
- if (client == NULL) return ESP_FAIL;
- else return ESP_OK;
- }
- esp_err_t wifi_http_deinit(void) {
- esp_err_t ret = esp_http_client_cleanup(client);
- if (ret == ESP_OK) client = NULL;
- return ret;
- }
- esp_err_t wifi_http_close(void) {
- return esp_http_client_close(client);
- }
- esp_err_t wifi_http_post(char* url, char* post_data, int post_size, char** response, int* response_size) {
- esp_err_t err = ESP_OK;
- uint16_t resp_code = 0;
- *response_size = 0;
- if (client == NULL || url == NULL) {
- ESP_LOGE(TAG, "ERROR: Invalid Parameters given to wifi_https_post.");
- return ESP_ERR_INVALID_ARG;
- }
- //set URL and HTTP method
- esp_http_client_set_url(client, url);
- esp_http_client_set_method(client, HTTP_METHOD_POST);
- // setup headers and other data
- esp_http_client_set_post_field(client, post_data, post_size);
- // send post
- err = esp_http_client_perform(client);
- if (err == ESP_OK) {
- // allocate size of response
- *response_size = esp_http_client_get_content_length(client);
- *response = (char*)malloc(*response_size * sizeof(char) + 1);
- memset(*response, 0, *response_size * sizeof(char) + 1);
- // retrieve and post response
- if (esp_http_client_read(client, *response, *response_size) != -1) {
- // Check the Response Code
- resp_code = esp_http_client_get_status_code(client);
- ESP_LOGI(TAG, "HTTP POST Status = %d, content_length = %d", resp_code, *response_size);
- if (resp_code != 200) {
- if (resp_code % 100 == 2) err = ESP_FAIL;
- else if (resp_code % 100 == 3) err = ESP_FAIL;
- else if (resp_code % 100 == 4) err = ESP_FAIL;
- else if (resp_code % 100 == 5) err = ESP_FAIL;
- }
- }
- else {
- ESP_LOGE(TAG, "HTTP POST request failed.");
- }
- }
- else {
- ESP_LOGE(TAG, "HTTP POST request failed: %s", esp_err_to_name(err));
- }
- return err;
- }
- void task_time(void *pvParameters){
- for (int i = 1; true; i++){
- vTaskDelay(1000/portTICK_PERIOD_MS);
- ESP_LOGI("Status", "%d seconds since startup.", i);
- }
- }
- void app_main(void) {
- nvs_flash_init();
- char* data;
- char* response = NULL;
- int response_size = 0;
- int fail_count = 0;
- data = (char*) malloc(HTTP_SAMPLE_DATA_SIZE*sizeof(char));
- memset(data, 'a', HTTP_SAMPLE_DATA_SIZE);
- data[HTTP_SAMPLE_DATA_SIZE-1] = 0;
- printf("\nTask Watchdog Enabled\n");
- esp_task_wdt_init(60, true);
- esp_task_wdt_reset();
- if (wifi_init() != ESP_OK) esp_restart();
- xTaskCreatePinnedToCore(&task_time, "task_time", 4096, NULL, 10, NULL, 1);
- while(true){
- wifi_http_init(HTTP_DEFAULT_BUFFER_SIZE, HTTP_DEFAULT_TIMEOUT_MS, (char*) HTTP_DEFAULT_URL);
- esp_task_wdt_reset();
- if (wifi_http_post((char*) HTTP_DEFAULT_URL, data, (HTTP_SAMPLE_DATA_SIZE - 1),&response, &response_size) != ESP_OK){
- fail_count++;
- }
- if (fail_count > 10) break;
- if(response != NULL){
- printf("Response: %s\n",response);
- free(response);
- response = NULL;
- }
- wifi_http_close();
- vTaskDelay(1000/portTICK_PERIOD_MS);
- }
- esp_restart();
- }
In the example output below it shows the first two transmissions more or less failing properly, then on the third transmission it gets stuck after printing out the headers. I have also added a task to help show time elapsing after it gets stuck.
Output with Debug printout