Using the new Arduino IDE for ESP8266 and found bugs, report them here

Moderator: igrr

User avatar
By Mickbaer
#46198 Hope I've found the right forum/index.
I have built a nice Webserver on the ESP8266-07,
on Arduino IDE 1.69 build 20.4.16:8:33, to control 4 water valves.
The ESP8266WebServer is running since 8 days, with no crash,
and no Wifi reconnection, very well. :D
In addition to the water valves, the flow rate should be detected,
by an Watersensor 60L/min = 240 pulse / min,
connected to GPIO14, read via Interrupt. :?:

With water sensor is connected, I have observed the following:
Up to Water-puls below 50, all works fine. The system reports all data and all work fine.
At more than 50 water-puls, the ESP did not recorded every puls,
So when the number of puls gets higher, the ESP did not count pulses anymore.
(the 50 puls is here for example) :roll:
Here as example, at my Water-Ssytem, when the counting stops:
(Connected to the Generator, 78 puls / sec)
Heap: 38000
Boot Vers: 4
CPU: 80
SDK: 1.5.2(7eee54f4)
Chip ID: 1191149
Flash ID: 1327328
MakeHtmlPage duration = 11286, FreeHeap = 28864
WaterSensor pulseCount:84 Milis:19319
WaterSensor pulseCount:79 Milis:20322
WaterSensor pulseCount:78 Milis:21325
WaterSensor pulseCount:78 Milis:22328
WaterSensor pulseCount:78 Milis:23331
WaterSensor pulseCount:84 Milis:24414
WaterSensor pulseCount:79 Milis:25417
WaterSensor pulseCount:80 Milis:26444
WaterSensor pulseCount:36 Milis:27447 :o
WaterSensor pulseCount:13 Milis:28533 :shock:
WaterSensor pulseCount:9 Milis:29536 :?
WaterSensor pulseCount:0 Milis:30563 :oops:
WaterSensor pulseCount:0 Milis:31566
WaterSensor pulseCount:0 Milis:32653 :geek:


To reproduce this, I have built an second ESP8266-07 as Puls generator and on the same device counting the puls via GPIO14 by interrupt, reporting to Serial, and all works fine, up to 240 puls / sec.

Connecting these Puls-generator to my Water-Webserver-ESP, it crashes immediately,
When he saw the 240 puls/ sec. Below 50 it works. :?:

So I take the AdvancedWebserver example out of the ESP8266Wifi.zip
Newest Version, and added the follwing few lines:

// declare the value
volatile unsigned long G_pulseCount; // counted per Interrupt

// ISR
void pulseCounter()
{
G_pulseCount++; // Increment the pulse counter
}

// at the end of setup
G_pulseCount = 0;
attachInterrupt(14, pulseCounter, FALLING);

// at handleRoot() added the Puls Count line

<body>\
<h1>Hello from ESP8266!</h1>\
<p>Uptime: %02d:%02d:%02d</p>\
<p>PulsCount: %02d</p>\
<img src=\"/test.svg\" />\
</body>\

// and added the puls value to be displayed
hr, min % 60, sec % 60, G_pulseCount

Now I noticed that it works,
All puls where counted, and displayed.

I added at the LOOP an delay(2)
To simulate some other functions like calculating or Blinking some led,
to give the system more stress

void loop ( void ) {
server.handleClient();
delay(2);
}

And now the system crashes, sometimes in a few minutes, sometimes very fast.
It seams for me, the ESPWebserver consumes to much system time, to serve the IO-Interrupt,
So he counts not all or no more puls when the puls came to fast.
Some times when the ESP did not count the pulse, which are coming from the Generator very constant, 240Puls/sec.
The puls counting can be restart, by refreshing the website, for an short time, but it stops again or the system crashes with an exception like
wifi evt: 0
....wifi evt: 3
.
Connected to Spandau5
IP address: 192.168.111.43
MDNS responder started
HTTP server started
pm open,type:2 0
Fatal exception 0(IllegalInstructionCause):
epc1=0x40201f1c, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000
Exception (0):
epc1=0x40201f1c epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
ctx: sys
sp: 3ffffc30 end: 3fffffb0 offset: 01a0

>>>stack>>>
3ffffdd0: 40106bc8 3fff0334 3fff0334 fffffffe
3ffffde0: ffffffff 00000020 00000001 00000000
3ffffdf0: 00000000 401011b3 00000000 00000022
3ffffe00: 3fffc200 40106b90 3fffc258 4000050c
3ffffe10: 40004378 00000030 00000016 ffffffff
3ffffe20: 60000200 00000008 00000000 80000000
3ffffe30: 20000000 3fff2120 80000000 203fc040
3ffffe40: 80000000 3fffc6fc 3fff0334 3fff2124
3ffffe50: 000002b4 003fc040 60000600 00000030
3ffffe60: 3fffc200 40106b90 3fffc258 4000050c
3ffffe70: 40106c2c 00000030 0000001b ffffffff
3ffffe80: ffffffff 00000020 00000000 00000000
3ffffe90: 00000000 00000000 0000001f 401052f9
3ffffea0: 4000050c 40106b90 3fffc258 4000050c
3ffffeb0: 40000f68 00000030 00000016 ffffffff
3ffffec0: 40000f58 00000000 00000020 00000000
3ffffed0: feefeffe 3fff0334 3fff0334 fffffffe
3ffffee0: ffffffff 3ffeebd8 3fff0334 3fffdab0
3ffffef0: 00000000 3fffdad0 3fff0420 00000030
3fffff00: 00000000 400042db 3ffe9b51 60000600
3fffff10: 40004b31 3fff20e4 000002f4 003fc000
3fffff20: 401056e2 3ffeec00 3ffedca0 40106dc8
3fffff30: 4020bb99 3ffedca0 3ffeec00 0530a5fd
3fffff40: 3fff20e4 00001000 4020c02e 00000008
3fffff50: 00000000 00000000 4020c0db 3ffedd54
3fffff60: 3ffeec00 00520baf 3ffeebd8 40201018
3fffff70: 4021d7ad 3ffedd54 3ffeec00 0530a4d0
3fffff80: 4021d7f2 3fffdab0 00000000 3fffdcb0
3fffff90: 3ffeec10 3fffdad0 3fff0420 402071db
3fffffa0: 40000f49 00009b7b 3fffdab0 40000f49
<<<stack<<<
ets Jan 8 2013,rst cause:2, boot mode:(1,6)
ets Jan 8 2013,rst cause:4, boot mode:(1,6)
wdt reset

Can any body help here?
What is the reason on ESP8266Webserver and Interrupts usage?
I will be glad to get some Help.
Thanks
Mickbaer from Berlin Germany
You do not have the required permissions to view the files attached to this post.
User avatar
By Mickbaer
#46233 Thanks for youe quick reply.
I have installed the Exception Decoder and traced the following Exception:
----------------------------------------------------------------------------------------------------------------------------
Exception (0):
epc1=0x40201f1c epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

ctx: sys
sp: 3ffffc30 end: 3fffffb0 offset: 01a0

>>>stack>>>
3ffffdd0: 40106988 00dd9999 00000001 00000018
3ffffde0: ffffffff 00000020 40240000 00000066
3ffffdf0: 00000006 00000006 00000000 00000022
3ffffe00: 3fffc200 40106950 3fffc258 4000050c
3ffffe10: 40004384 00000030 00000016 ffffffff
3ffffe20: 60000200 00000000 0001e300 80000000
3ffffe30: 20000000 3fff2010 80000000 203fc2c0
3ffffe40: 00000000 3fffc6fc 3ffefe24 3fff2014
3ffffe50: 00000034 003fc2c0 60000600 00000030
3ffffe60: 401069ec 3ffe9d70 3ffe9d70 00000001
3ffffe70: 401069ec 00000020 3ffef3d0 00000003
3ffffe80: ffffffff 00000020 3fff1094 00000022
3ffffe90: 00000000 00000000 0000001f 401050b9
3ffffea0: 4000050c 40106950 3fffc258 4000050c
3ffffeb0: 40000f68 00000030 00000016 ffffffff
3ffffec0: 40000f58 00000000 00000020 00000000
3ffffed0: feefeffe 3ffefe24 3ffefe24 fffffffe
3ffffee0: ffffffff 3ffee6c8 3ffefe24 3fffdab0
3ffffef0: 00000000 3fffdad0 3ffeff10 00000030
3fffff00: 00000000 400042db 3ffe9e10 60000600
3fffff10: 40004b31 3fff1d54 000002f4 003fc000
3fffff20: 401054a2 3ffee6f0 3ffed790 40106b88
3fffff30: 4020b739 3ffed790 3ffee6f0 085840e0
3fffff40: 3fff1d54 00001000 4020bbce 00000008
3fffff50: 00000000 00000000 4020bc7b 3ffed844
3fffff60: 3ffee6f0 00c4c3f9 3ffee6c8 40201018
3fffff70: 4021d34d 3ffed844 3ffee6f0 08583ee0
3fffff80: 4021d392 3fffdab0 00000000 3fffdcb0
3fffff90: 3ffee700 3fffdad0 3ffeff10 40206d7f
3fffffa0: 40000f49 000183a9 3fffdab0 40000f49
<<<stack<<<
ets Jan 8 2013,rst cause:2, boot mode:(1,6)
ets Jan 8 2013,rst cause:4, boot mode:(1,6)
wdt reset
----------------------------------------------------------------------------------------------------------------------------
here the Exception Decoder:
Decoding 27 results
0x40201f1c: pulseCounter() at C:\#ESP8266\Gardena2016\Version3\AdvancedWebServer_INT/AdvancedWebServer_INT.ino line 154
0x40106988: interrupt_handler at C:\Users\Michael\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0-rc1\cores\esp8266/core_esp8266_wiring_digital.c line 119
0x40106950: interrupt_handler at C:\Users\Michael\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0-rc1\cores\esp8266/core_esp8266_wiring_digital.c line 113
0x401069ec: interrupt_handler at C:\Users\Michael\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0-rc1\cores\esp8266/core_esp8266_wiring_digital.c line 135
0x401069ec: interrupt_handler at C:\Users\Michael\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0-rc1\cores\esp8266/core_esp8266_wiring_digital.c line 135
0x401050b9: ets_timer_disarm at ?? line ?
0x40106950: interrupt_handler at C:\Users\Michael\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0-rc1\cores\esp8266/core_esp8266_wiring_digital.c line 113
0x401054a2: spi_flash_read at ?? line ?
0x40106b88: pvPortZalloc at C:\Users\Michael\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0-rc1\cores\esp8266/heap.c line 33
0x4020b739: pm_set_sleep_time at ?? line ?
0x4020bbce: pm_get_sleep_type at ?? line ?
0x4020bc7b: pm_get_sleep_type at ?? line ?
0x40201018: delay_end at C:\Users\Michael\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0-rc1\cores\esp8266/core_esp8266_wiring.c line 40
0x4021d34d: ets_timer_handler_isr at ?? line ?
0x4021d392: ets_timer_handler_isr at ?? line ?
0x40206d7f: loop_task at C:\Users\Michael\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0-rc1\cores\esp8266/core_esp8266_main.cpp line 43
----------------------------------------------------------------------------------------------------------------------------
Here the code, which belongs to that exceptions:

0x40201f1c: pulseCounter() at C:\#ESP8266\Gardena2016\Version3\AdvancedWebServer_INT/AdvancedWebServer_INT.ino line 154
--->
152 void pulseCounter()
153 {
154 G_pulseCount++; // Increment the pulse counter ;)
155 }

0x40106988: interrupt_handler at C:\Users\Michael\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0-rc1\cores\esp8266/core_esp8266_wiring_digital.c line 119
0x40106950: interrupt_handler at C:\Users\Michael\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0-rc1\cores\esp8266/core_esp8266_wiring_digital.c line 113
0x401069ec: interrupt_handler at C:\Users\Michael\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0-rc1\cores\esp8266/core_esp8266_wiring_digital.c line 135
0x401069ec: interrupt_handler at C:\Users\Michael\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0-rc1\cores\esp8266/core_esp8266_wiring_digital.c line 135
--->
112 void ICACHE_RAM_ATTR interrupt_handler(void *arg) {
113 uint32_t status = GPIE; :)
114 GPIEC = status;//clear them interrupts
115 uint32_t levels = GPI;
116 if(status == 0 || interrupt_reg == 0) return;
117 ETS_GPIO_INTR_DISABLE();
118 int i = 0;
119 uint32_t changedbits = status & interrupt_reg; :o
120 while(changedbits){
121 while(!(changedbits & (1 << i))) i++;
122 changedbits &= ~(1 << i);
123 interrupt_handler_t *handler = &interrupt_handlers[i];
124 if (handler->fn &&
125 (handler->mode == CHANGE ||
126 (handler->mode & 1) == !!(levels & (1 << i)))) {
127 // to make ISR compatible to Arduino AVR model where interrupts are disabled
128 // we disable them before we call the client ISR
129 uint32_t savedPS = xt_rsil(15); // stop other interrupts
130 handler->fn();
131 xt_wsr_ps(savedPS);
132 }
133 }
134 ETS_GPIO_INTR_ENABLE();
135 } :o

0x40106b88: pvPortZalloc at C:\Users\Michael\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0-rc1\cores\esp8266/heap.c line 33
---->
30 void* ICACHE_RAM_ATTR pvPortZalloc(size_t size, const char* file, int line)
31 {
32 return calloc(1, size);
33 } :o

0x40201018: delay_end at C:\Users\Michael\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0-rc1\cores\esp8266/core_esp8266_wiring.c line 40
---->
38 void delay_end(void* arg) {
39 esp_schedule();
40 } :o

0x40206d7f: loop_task at C:\Users\Michael\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0-rc1\cores\esp8266/core_esp8266_main.cpp line 43
---->
41 int atexit(void (*func)()) {
42 return 0;
43 } :o
----------------------------------------------------------------------------------------------------------------------------

I hope this will help you to find the problem at the ESPCORE.

I will be glad to get some Help.
Thanks
Mickbaer from Berlin Germany