Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By gregbath
#45268 I have built a hot water system monitor with a ESP-201 board that measures electric current via a CT clamp, various temperatures via DS18B20 sensors and water usage via a hall effect flow sensor. The data is reported via a simple UDP string to my server. This was written in LUA and works well except I have noticed that any significant water flow causes ESP8266 to reset so I have tried to rebuild the software using the Arduino IDE but I have found the same issue exists. If I have Wifi enabled then the interrupts from the water sensor cause the program to fail.

I have reduced the code to a very basic level to remove any other factors that I think could cause the issue but it still exists. I have simulated the water sensor with a pulse generator running at 10hz (the maximum rate typically seen) connected to the gpio. If I run the test program without the pulse generator connected it runs reliably. If I run it with the pulse generator connected but Wifi disconnected then it is also reliable but if I have Wifi connected then it will fail after a minute or two. Even if I reduce the pulse rate it will still fail but may take longer to do so.

What am I doing wrong?

The program code:

/* Test of interrupt handler */

#include <ESP8266WiFi.h>

volatile unsigned int hwCount = 0;
volatile unsigned int lastHwCount = 0;
volatile unsigned int loopCounter = 0;

void flowCounterCb() {
hwCount++;
}

const char* ssid = "Bathern-1";
const char* password = "xxxxxxxxxxxxxxxxxxx";


void setup() {
Serial.begin(115200);
delay(10);

Serial.println(); Serial.flush();
Serial.print("Connecting to "); Serial.flush();
Serial.println(ssid); Serial.flush();

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print("."); Serial.flush();
}

Serial.println(""); Serial.flush();
Serial.print("WiFi connected - "); Serial.flush();
Serial.print("IP address: "); Serial.flush();
Serial.println(WiFi.localIP()); Serial.flush();

pinMode(5, INPUT);
attachInterrupt(5, flowCounterCb, RISING);
}

void loop() {
// put your main code here, to run repeatedly:

Serial.print("Loop counter: "); Serial.flush();
Serial.println(loopCounter); Serial.flush();

Serial.print("Interrupt counter: "); Serial.flush();
lastHwCount = hwCount;
Serial.println(lastHwCount); Serial.flush();

Serial.print("IP address: "); Serial.flush();
Serial.print(WiFi.localIP()); Serial.flush();
Serial.print(" Connection status: "); Serial.flush();
Serial.println(WiFi.status()); Serial.flush();
loopCounter++;

for(int y=1; y<=6;y++) {
delay(10000);
Serial.print(y*10); Serial.flush();
Serial.print("-"); Serial.flush();
}
Serial.println(""); Serial.flush();
Serial.println("------------------"); Serial.flush();

}

-----------------------------------------------------------------
Sample output:
Connecting to Bathern-1
........
WiFi connected - IP address: 192.168.200.14
Loop counter: 0
Interrupt counter: 0
IP address: 192.168.200.14 Connection status: 3
10-20-30-40-50-60-
------------------
Loop counter: 1
Interrupt counter: 600
IP address: 192.168.200.14 Connection status: 3
10-20-30-40-50-60-
------------------
Loop counter: 2
Interrupt counter: 1200
IP address: 192.168.200.14 Connection status: 3
10-20-30-40-50-60-
------------------
Loop counter: 3
Interrupt counter: 1800
IP address: 192.168.200.14 Connection status: 3
10-20-30-40-50-60-
------------------
Loop counter: 4
Interrupt counter: 2400
IP address: 192.168.200.14 Connection status: 3
10-20-30-40-50-60-
------------------
Loop counter: 5
Interrupt counter: 3001
IP address: 192.168.200.14 Connection status: 3
10-20-30-40-50-60-
------------------
Loop counter: 6
Interrupt counter: 3601
IP address: 192.168.200.14 Connection status: 3
10-20-30-40-50-60-
------------------
Loop counter: 7
Interrupt counter: 4201
IP address: 192.168.200.14 Connection status: 3
10-20-30-40-50-60-
------------------
Loop counter: 8
Interrupt counter: 4801
IP address: 192.168.200.14 Connection status: 3
10-20-30-
Exception (0):
epc1=0x402023f8 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

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

>>>stack>>>
3ffffdd0: 40106ec4 80af1999 00000001 000000ff
3ffffde0: ffffffff 00000020 00000001 00000000
3ffffdf0: 00000000 401016d3 00000000 00000022
3ffffe00: 3fffc200 40106e8c 3fffc258 4000050c
3ffffe10: 40004376 00000030 00000019 ffffffff
3ffffe20: 60000200 00000008 ffffffff 80000000
3ffffe30: 20000000 3fff0878 80000000 2007c1c0
3ffffe40: 00000000 3fffc6fc 60000600 3fff087c
3ffffe50: 00000134 0007c1c0 60000600 00000030
3ffffe60: 00000000 00000000 00000000 40102dca
3ffffe70: 40102e2e 00080000 3fffc200 00000022
3ffffe80: 00000000 3ffea0b4 00000000 4000050c
3ffffe90: 00000000 00000000 0000001f 40105b55
3ffffea0: 4000050c 00000000 00000db2 00000000
3ffffeb0: 40000f68 00000030 0000001a ffffffff
3ffffec0: 40000f58 00000000 00000020 00000000
3ffffed0: 3ffe8b50 4020600f 3ffe8980 00000000
3ffffee0: 00000000 00000073 60000600 3fffdab0
3ffffef0: 00000000 3fffdcc0 3ffe8bb0 00000030
3fffff00: 00000000 400042db 3ffe8ca1 60000600
3fffff10: 40004b31 3fff06bc 000002f4 0007c000
3fffff20: 40105ea2 3ffee3e0 3ffecdf0 4010724c
3fffff30: 40209055 3ffecdf0 3ffee3e0 1f2ff11b
3fffff40: 3fff06bc 00001000 402094ea 00000008
3fffff50: 4021be28 40105c27 40209597 3ffecea4
3fffff60: 3ffee3e0 40222f69 3ffee3b8 3ffee3e0
3fffff70: 40222f69 60000600 00000000 00000020
3fffff80: 40222fae 3fffdab0 00000000 3fffdcb0
3fffff90: 3ffee3f0 00000000 40000f65 3fffdab0
3fffffa0: 40000f49 40000f49 3fffdab0 40000f49
<<<stack<<<

ets Jan 8 2013,rst cause:1, boot mode:(3,7)

load 0x4010f000, len 1264, room 16
tail 0
chksum 0x42
csum 0x42
~ld

Connecting to Bathern-1
........
User avatar
By gregbath
#45329 I added an extract of the SDK version into the code (1.5.1) and have now found the debugger add-on. They have not helped a lot though. The debugger is showing that it is failing at the single line in the interrupt handler function (hwCount++) but the stack trace is also always showing 'ieee80211_parse_beacon' and 'ieee80211_parse_wmeparams' calls just prior to that. I don't know the significance for those calls. Is this a bug in my code or is it in the SDK networking library?

I have 11 or so Wifi networks visible hear. Is there some way that I can get the ESP8266 to ignore the other ones?

The code is now:

Code: Select all/*  Test of interrupt handler   */

extern "C" {
#include "ets_sys.h"
#include "osapi.h"
#include "gpio.h"
#include "os_type.h"
#include "user_interface.h"
}


#include <ESP8266WiFi.h>

unsigned int hwCount = 0;     // Also try long.
volatile unsigned int lastHwCount = 0;
volatile unsigned int loopCounter = 0;

void flowCounterCb() {
    hwCount++;
}

const char* ssid     = "Bathern-1";
const char* password = "The Batherns at home";


void setup() {
  Serial.begin(115200);
  delay(10);

  Serial.println("");
  Serial.print("SDK version: ");
  Serial.println(system_get_sdk_version());

  Serial.println(); Serial.flush();
  Serial.print("Connecting to "); Serial.flush();
  Serial.println(ssid); Serial.flush();

  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print("."); Serial.flush();
  }

  Serial.println(""); Serial.flush();
  Serial.print("WiFi connected - ");   Serial.flush();
  Serial.print("IP address: "); Serial.flush();
  Serial.println(WiFi.localIP()); Serial.flush();

  pinMode(5, INPUT);
  attachInterrupt(5, flowCounterCb, RISING);
}

void loop() {
  // put your main code here, to run repeatedly:

  Serial.print("Loop counter: "); Serial.flush();
  Serial.println(loopCounter); Serial.flush();

  Serial.print("Interrupt counter: "); Serial.flush();
  lastHwCount = hwCount;
  Serial.println(lastHwCount); Serial.flush();

  Serial.print("IP address: "); Serial.flush();
  Serial.print(WiFi.localIP()); Serial.flush();
  Serial.print("  Connection status: "); Serial.flush();
  Serial.println(WiFi.status()); Serial.flush();
  loopCounter++;

  for(int y=1; y<=6;y++) {
    delay(10000);
    Serial.print(y*10); Serial.flush();
    Serial.print("-"); Serial.flush();
  }
  Serial.println(""); Serial.flush();
  Serial.println("------------------"); Serial.flush();


}


Which results in the following output:

Code: Select allSDK version: 1.5.1(e67da894)

Connecting to Bathern-1
.............
WiFi connected - IP address: 192.168.200.14
Loop counter: 0
Interrupt counter: 0
IP address: 192.168.200.14  Connection status: 3
10-20-30-40-
Exception (0):
epc1=0x402023f8 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

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

>>>stack>>>
3ffffdd0:  40106ec4 80af1999 00000000 00000100 
3ffffde0:  ffffffff 00000020 40240000 ffffff1a 
3ffffdf0:  00000006 00000006 42d60000 00000022 
3ffffe00:  3fffc200 40106e8c 3fffc258 4000050c 
3ffffe10:  4000437d 00000030 00000019 ffffffff 
3ffffe20:  60000200 00000008 000230fd 80000000 
3ffffe30:  20000000 3fff0988 80000000 2007c2c0 
3ffffe40:  80000000 3fffc6fc fc70ffff 3fff098c 
3ffffe50:  00000034 0007c2c0 60000600 00000030 
3ffffe60:  7fffffff 3ffe93e0 3ffe93e0 00000001 
3ffffe70:  4020d429 3ffee858 3ffee848 3ffee848 
3ffffe80:  ffffffb9 3ffe943c ffffffb9 3ffe944c 
3ffffe90:  00000000 00000000 0000001f 40105b55 
3ffffea0:  4000050c 00000001 402119eb 3ffefea4 
3ffffeb0:  40000f68 00000030 0000001a ffffffff 
3ffffec0:  40000f58 00000000 00000020 00000000 
3ffffed0:  00df8636 00000001 00003a98 00000001 
3ffffee0:  ffffffff 3fffc6fc fc70ffff 3fffdab0 
3ffffef0:  00000000 3fffdcb0 3ffee400 00000030 
3fffff00:  00000000 400042db 3ffe9484 60000600 
3fffff10:  40004b31 3fff06cc 000002f4 0007c000 
3fffff20:  40105ea2 3ffee3f0 3ffece00 4010724c 
3fffff30:  4020906d 3ffece00 3ffee3f0 02cbcd06 
3fffff40:  3fff06cc 00001000 40209502 00000008 
3fffff50:  40205e7c 3ffe8994 402095af 3ffeceb4 
3fffff60:  3ffee3f0 40222f81 3ffee3c8 3ffee3f0 
3fffff70:  40222f81 60000600 3ffe8c60 3ffe8c60 
3fffff80:  40222fc6 3fffdab0 00000000 3fffdcb0 
3fffff90:  3ffee408 00000000 40000f65 3fffdab0 
3fffffa0:  40000f49 00018511 3fffdab0 40000f49 
<<<stack<<<

 ets Jan  8 2013,rst cause:1, boot mode:(3,7)

load 0x4010f000, len 1264, room 16
tail 0
chksum 0x42
csum 0x42
~ld


And teh debugger output is:

Code: Select allDecoding 27 results
0x402023f8: flowCounterCb() at C:\Users\Maria\Documents\Arduino\Play Sketches\ESP8266\ADCTest\SimpleIntr/SimpleIntr.ino line 19
0x40106ec4: interrupt_handler at C:\Users\Maria\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.1.0\cores\esp8266/core_esp8266_wiring_digital.c line 156
0x40106e8c: interrupt_handler at C:\Users\Maria\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.1.0\cores\esp8266/core_esp8266_wiring_digital.c line 156
0x4020d429: ieee80211_parse_beacon at ?? line ?
0x40105b55: ets_timer_disarm at ?? line ?
0x402119eb: ieee80211_parse_wmeparams at ?? line ?
0x40105ea2: spi_flash_read at ?? line ?
0x4010724c: pvPortZalloc at C:\Users\Maria\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.1.0\cores\esp8266/heap.c line 33
0x4020906d: pm_set_sleep_time at ?? line ?
0x40209502: pm_get_sleep_type at ?? line ?
0x40205e7c: pp_noise_test at ?? line ?
0x402095af: pm_get_sleep_type at ?? line ?
0x40222f81: ets_timer_handler_isr at ?? line ?
0x40222f81: ets_timer_handler_isr at ?? line ?
0x40222fc6: ets_timer_handler_isr at ?? line ?