LoadProhibited on core 0 when concatenating with sprintf

ESPtronic
Posts: 9
Joined: Sat Jun 03, 2017 9:41 pm

LoadProhibited on core 0 when concatenating with sprintf

Postby ESPtronic » Sun Jun 04, 2017 5:51 pm

Hello, I need to send as a GET parameter ESP32 IP address to my web server. The problem is that, when I want to concatenate the strings with the URL, the IP and the rest of the request, it gives me the following error:

Code: Select all

Guru Meditation Error of type LoadProhibited occurred on core  0. Exception was unhandled.
Register dump:
PC      : 0x400014fd  PS      : 0x00060930  A0      : 0x800d884c  A1      : 0x3ffc6530
A2      : 0x00000000  A3      : 0xfffffffc  A4      : 0x000000ff  A5      : 0x0000ff00
A6      : 0x00ff0000  A7      : 0xff000000  A8      : 0x00000000  A9      : 0x3ffc64f0
A10     : 0x00000000  A11     : 0xffffffff  A12     : 0x00000004  A13     : 0x00000001
A14     : 0x400dbc18  A15     : 0x3ffc47fc  SAR     : 0x00000000  EXCCAUSE: 0x0000001c
0x400dbc18: http_get_task at /Users/my_user/esp/project/main/./main.c:71 (discriminator 1)

EXCVADDR: 0x00000000  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xffffffff

Backtrace: 0x400014fd:0x3ffc6530 0x400d884c:0x3ffc6540 0x4010d52c:0x3ffc6850 0x400dbc3c:0x3ffc68a0
0x4010f538: _svfprintf_r at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/vfprintf.c:1529

0x4010d69c: sprintf at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/sprintf.c:646

0x400dbc48: http_get_task at /Users/my_user/esp/project/main/./main.c:71 (discriminator 1)
My code is the following:
At the beginning:

Code: Select all

char* ip;
In the event handler (copied from your example):

Code: Select all

case SYSTEM_EVENT_STA_GOT_IP:
        xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
        ip = inet_ntoa(event->event_info.got_ip.ip_info.ip);
        break;
In the http_get_task (also copied):

Code: Select all

char WEB_URL1[128];
sprintf(WEB_URL1, "http://192.168.0.1/grbinventions/grbalarm/regip.php?ip=%s", ip);
char REQUEST[512];
sprintf(REQUEST, "GET %s HTTP/1.1\r\n%s", WEB_URL1, REQUEST_TEXT);

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: LoadProhibited on core 0 when concatenating with sprintf

Postby ESP_Sprite » Mon Jun 05, 2017 1:19 am

Not entirely sure what's going wrong, but inet_ntoa returns a pointer to some (internally-allocated or static) variable; this is either incompatible with multithreading or the pointer is only valid in the thread you use inet_ntoa in. Suggest creating your own buffer space and using inet_ntop instead.

ESPtronic
Posts: 9
Joined: Sat Jun 03, 2017 9:41 pm

Re: LoadProhibited on core 0 when concatenating with sprintf

Postby ESPtronic » Mon Jun 05, 2017 1:58 pm

I finally figured out the problem. It was that the http_get_task executed before getting an IP. So sprintf had nothing to put on the string, as I didn't put any default value. For solving the problem, I just moved the sprintf into the while loop. Now there is no error, but there's still a problem: outside of the event handler the ip is an empty string.

Code: Select all

I (2215) event: ip: 192.168.1.7, mask: 255.255.0.0, gw: 192.168.1.1
I (2215) tag: IP:
--- EDIT ---
I solved the problem. The problem was inet_ntop (which I tried for solving the problem). I don't understand why, maybe I didn't do it well. Here is the code:

Code: Select all

char ipbuf[INET_ADDRSTRLEN];
ip = inet_ntop(AF_INET, &event->event_info.got_ip.ip_info.ip, ipbuf, INET_ADDRSTRLEN);
I replaced it with inet_ntoa, but if inet_ntop is better, I would like to know what's wrong.

Who is online

Users browsing this forum: No registered users and 98 guests