esp8266 / Arduino

ESP8266 core for Arduino
GNU Lesser General Public License v2.1
16.06k stars 13.33k forks source link

ESP8266 resetting periodically during Udp.write (seemingly) #3443

Closed Plamena24 closed 5 years ago

Plamena24 commented 7 years ago

Basic Infos

Hardware

Hardware: ESP-12-E Core Version: not sure how to find out

Description

Problem description The board resets every so often, not in a regular pattern while executing the sendButtonState() function. The WatchDogTimer triggers each time. The packets I am writing are 196 bytes which doesn't seem all that big but I don't know enough to determine what is actually going on.

Settings in IDE

Module: NodeMCU 1.0(ESP 12E module) Flash Size: 4M CPU Frequency: 80MHz Flash Mode: qio Flash Frequency: 40Mhz Upload Using: SERIAL Reset Method: nodemcu (but not really sure)

Sketch

include

include

include

include

include "Adafruit_MCP23017.h"

include

ifdef AVR

include <avr/power.h>

endif

include

include

include

include

include

include

define PIN 14

char ssid[] = "Balloon Network"; // your network SSID (name) char pass[] = "balloons"; // your network password

//char ssid[] = "botcave"; // your network SSID (name) //char pass[] = "12porcupines";

char* hostString = "buttonNode"; const unsigned int localPort = 5005; // local port to listen for UDP packets (here's where we send the packets)

char messageBuffer[196]= {};
bool buttonsPressed[98] = {};

unsigned long lightTimers_ms[98] = {};

unsigned long next_tx_ms = 0; unsigned long next_rx_ms = 0; int tx_interval_ms = 100; int rx_interval_ms = 90; int lightChange_interval_ms = 5000;

Adafruit_MCP23017 MCPArray[7] = {}; Adafruit_NeoPixel strip = Adafruit_NeoPixel(98, PIN, NEO_RGBW + NEO_KHZ800);

typedef struct { char chipId; char pinNumber; } pinInfo;

pinInfo buttonMapping[98] = {};

WiFiClient client; WiFiUDP Udp; IPAddress broadcastIP; int destPort = 6001;

OSCErrorCode error;

void connectWiFi() {

Serial.println("Attempting to connect to WPA network..."); Serial.print("SSID: "); Serial.println(ssid); Serial.print("hostString: "); Serial.println(hostString);

WiFi.hostname(hostString); WiFi.begin(ssid, pass); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP());

broadcastIP = WiFi.localIP(); broadcastIP[3] = 255; // Works for networks with netmask 255.255.255.0

}

void startMDNS() { if (!MDNS.begin(hostString)) { Serial.println("Error setting up MDNS responder!"); } Serial.println("mDNS responder started"); }

void populateButtonMapping() { int buttonPosition = 0; for (int i = 0; i < 6; i++){ for (int j = 0; j < 15; j++){ buttonMapping[buttonPosition].chipId = i; buttonMapping[buttonPosition].pinNumber = j; buttonPosition = buttonPosition + 1; } }

for (int j = 0; j < 8; j++){ if (buttonPosition == 98) { break; } buttonMapping[buttonPosition].chipId = 6; buttonMapping[buttonPosition].pinNumber = j; buttonPosition = buttonPosition + 1; } }

void readButtons(){ //mcp stuff goes in here for (int i = 0; i < 98; i++){ pinInfo info = buttonMapping[i]; buttonsPressed[i] = buttonsPressed[i] || MCPArray[info.chipId].digitalRead(info.pinNumber); // Serial.print(i); // Serial.print(","); // Serial.print(MCPArray[info.chipId].digitalRead(info.pinNumber)); // Serial.print(","); // Serial.print((int)info.chipId); // Serial.print(","); // Serial.print((int)info.pinNumber); // Serial.println();

} // digitalWrite(LED_BUILTIN, MCPArray[buttonMapping.chipId].digitalRead(buttonMapping.pinNumber)); Serial.println("Reading buttons"); }

void clearButtons(){ for (int i = 0; i < 98; i++){ buttonsPressed[i] = false; } }

void makeMessageBuffer() { int bufferPosition = 0; for (int i = 0; i < 98; i++){ char theCharacter = '0'; if (buttonsPressed[i] == true) { theCharacter = '1';
} messageBuffer[bufferPosition] = theCharacter; bufferPosition = bufferPosition + 1; messageBuffer[bufferPosition] = ','; bufferPosition = bufferPosition + 1; } messageBuffer[bufferPosition - 1] = 0; }

int sendButtonState() { Udp.beginPacket(broadcastIP, destPort); Udp.write(messageBuffer); Udp.endPacket();

Serial.println("Sending button state"); }

void populateLightTimers() { int lightPosition = 0; for (int i = 0; i < 98; i++){ if (buttonsPressed[i] == true ){ lightTimers_ms[i] = millis() + lightChange_interval_ms; }else if (buttonsPressed[i] == false && lightTimers_ms[i] > millis()){ lightTimers_ms[i] = lightTimers_ms[i]; }else{ lightTimers_ms[i] = millis(); } lightPosition = lightPosition + 1;
} }

void setLightColor() { for (int i=0; i<strip.numPixels(); i++){ if (lightTimers_ms[i] > millis()){ strip.setPixelColor(i, 0, 0, 0, 255); }else if (lightTimers_ms[86] > millis() &&lightTimers_ms[78] > millis() &&lightTimers_ms[70] > millis() &&lightTimers_ms[62] > millis() &&lightTimers_ms[54] > millis() &&lightTimers_ms[46] > millis() &&lightTimers_ms[39] > millis() &&lightTimers_ms[32] > millis() &&lightTimers_ms[25] > millis() &&lightTimers_ms[18] > millis() &&lightTimers_ms[11] > millis() &&lightTimers_ms[19] > millis() &&lightTimers_ms[27] > millis() &&lightTimers_ms[35] > millis() &&lightTimers_ms[43] > millis() &&lightTimers_ms[51] > millis() &&lightTimers_ms[58] > millis() &&lightTimers_ms[65] > millis() &&lightTimers_ms[72] > millis() &&lightTimers_ms[79] > millis()){ theaterChase(strip.Color(0, 0, 0, 255)); theaterChase(strip.Color(127, 0, 127, 0)); theaterChase(strip.Color(0, 127, 127, 0)); }else {
strip.setPixelColor(i, Wheel((i*2) & 255)); } } strip.show(); }

uint32_t Wheel(byte WheelPos) { WheelPos = 255 - WheelPos; if(WheelPos < 85) { return strip.Color(255 - WheelPos 3, 0, WheelPos 3); } if(WheelPos < 170) { WheelPos -= 85; return strip.Color(0, WheelPos 3, 255 - WheelPos 3); } WheelPos -= 170; return strip.Color(WheelPos 3, 255 - WheelPos 3, 0); }

void theaterChase(uint32_t c) { for (int j=0; j<10; j++) { //do 10 cycles of chasing for (int q=0; q < 3; q++) { for (uint16_t i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, c); //turn every third pixel on } strip.show();

  for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
    strip.setPixelColor(i+q, 0);        //turn every third pixel off
  }
}

} }

void setup() { //return; Serial.begin(115200); //delay(100);

pinMode(LED_BUILTIN, OUTPUT); Serial.println("LED_BUILTIN enabled"); digitalWrite(LED_BUILTIN, LOW);

strip.begin(); for (int i=0; i<strip.numPixels(); i++){ strip.setPixelColor(i, Wheel((i*2) & 255)); } strip.show(); // Initialize all pixels to 'off'

populateButtonMapping();

for (int i = 0; i < 7; i++){ MCPArray[i].begin(i); for (int j = 0; j < 16; j++){ MCPArray[i].pinMode(j, INPUT); MCPArray[i].pullUp(j, HIGH); }

}

connectWiFi(); startMDNS();

next_tx_ms = millis(); next_rx_ms = millis(); }

void loop() { //return; //debug if (WiFi.status() != WL_CONNECTED) { connectWiFi(); startMDNS(); } if (next_rx_ms <= millis()) { next_rx_ms = next_rx_ms + rx_interval_ms; // Time to RX a status message readButtons(); populateLightTimers(); setLightColor(); } if (next_tx_ms <= millis()) { next_tx_ms = next_tx_ms + tx_interval_ms; // Time to TX a status message makeMessageBuffer(); sendButtonState(); clearButtons(); }

delay(1); }

Debug Messages

This is the most common stack:

0x40203980: UdpContext::send(ip_addr*, unsigned short) at /Users/plamena/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WiFi/src/WiFiUdp.cpp line 67 : (inlined by) WiFiUDP::endPacket() at /Users/plamena/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WiFi/src/WiFiUdp.cpp line 191 0x402055dd: Adafruit_NeoPixel::show() at /Users/plamena/Documents/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp line 1971 0x4021d92e: wifi_get_opmode at ?? line ? 0x402027d1: sendButtonState() at /Users/plamena/Documents/Projects/MIRR files/MIRR/buttonController_MIRR/buttonController_MIRR.ino line 162 0x40202849: loop at /Users/plamena/Documents/Projects/MIRR files/MIRR/buttonController_MIRR/buttonController_MIRR.ino line 291 0x40205f28: loop_wrapper at /Users/plamena/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/core_esp8266_main.cpp line 56 0x40100718: cont_norm at /Users/plamena/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/cont.S line 109

This one is the other one that shows up: 0x40203980: UdpContext::send(ip_addr*, unsigned short) at /Users/plamena/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WiFi/src/WiFiUdp.cpp line 67 : (inlined by) WiFiUDP::endPacket() at /Users/plamena/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WiFi/src/WiFiUdp.cpp line 191 0x4021d92e: wifi_get_opmode at ?? line ? 0x402027d1: sendButtonState() at /Users/plamena/Documents/Projects/MIRR files/MIRR/buttonController_MIRR/buttonController_MIRR.ino line 162 0x4020152f: delay at /Users/plamena/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/core_esp8266_wiring.c line 50 0x40202849: loop at /Users/plamena/Documents/Projects/MIRR files/MIRR/buttonController_MIRR/buttonController_MIRR.ino line 291 0x40205f28: loop_wrapper at /Users/plamena/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/core_esp8266_main.cpp line 56 0x40100718: cont_norm at /Users/plamena/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/cont.S line 109

devyte commented 7 years ago

How long does it take to execute one loop()? What does the heap usage look like over time?

On Jul 20, 2017 1:47 PM, "Plamena24" notifications@github.com wrote:

Basic Infos Hardware

Hardware: ESP-12-E Core Version: not sure how to find out Description

Problem description The board resets every so often, not in a regular pattern while executing the sendButtonState() function. The WatchDogTimer triggers each time. The packets I am writing are 196 bytes which doesn't seem all that big but I don't know enough to determine what is actually going on. http://url Settings in IDE

Module: NodeMCU 1.0(ESP 12E module) Flash Size: 4M CPU Frequency: 80MHz Flash Mode: qio Flash Frequency: 40Mhz Upload Using: SERIAL Reset Method: nodemcu (but not really sure) Sketch

include

include

include

include

include "Adafruit_MCP23017.h"

include

ifdef AVR

include <avr/power.h>

endif

include

include

include

include

include

include

define PIN 14

char ssid[] = "Balloon Network"; // your network SSID (name) char pass[] = "balloons"; // your network password

//char ssid[] = "botcave"; // your network SSID (name) //char pass[] = "12porcupines";

char* hostString = "buttonNode"; const unsigned int localPort = 5005; // local port to listen for UDP packets (here's where we send the packets)

char messageBuffer[196]= {}; bool buttonsPressed[98] = {};

unsigned long lightTimers_ms[98] = {};

unsigned long next_tx_ms = 0; unsigned long next_rx_ms = 0; int tx_interval_ms = 100; int rx_interval_ms = 90; int lightChange_interval_ms = 5000;

Adafruit_MCP23017 MCPArray[7] = {}; Adafruit_NeoPixel strip = Adafruit_NeoPixel(98, PIN, NEO_RGBW + NEO_KHZ800);

typedef struct { char chipId; char pinNumber; } pinInfo;

pinInfo buttonMapping[98] = {};

WiFiClient client; WiFiUDP Udp; IPAddress broadcastIP; int destPort = 6001;

OSCErrorCode error;

void connectWiFi() {

Serial.println("Attempting to connect to WPA network..."); Serial.print("SSID: "); Serial.println(ssid); Serial.print("hostString: "); Serial.println(hostString);

WiFi.hostname(hostString); WiFi.begin(ssid, pass); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP());

broadcastIP = WiFi.localIP(); broadcastIP[3] = 255; // Works for networks with netmask 255.255.255.0

}

void startMDNS() { if (!MDNS.begin(hostString)) { Serial.println("Error setting up MDNS responder!"); } Serial.println("mDNS responder started"); }

void populateButtonMapping() { int buttonPosition = 0; for (int i = 0; i < 6; i++){ for (int j = 0; j < 15; j++){ buttonMapping[buttonPosition].chipId = i; buttonMapping[buttonPosition].pinNumber = j; buttonPosition = buttonPosition + 1; } }

for (int j = 0; j < 8; j++){ if (buttonPosition == 98) { break; } buttonMapping[buttonPosition].chipId = 6; buttonMapping[buttonPosition].pinNumber = j; buttonPosition = buttonPosition + 1; } }

void readButtons(){ //mcp stuff goes in here for (int i = 0; i < 98; i++){ pinInfo info = buttonMapping[i]; buttonsPressed[i] = buttonsPressed[i] || MCPArray[info.chipId]. digitalRead(info.pinNumber); // Serial.print(i); // Serial.print(","); // Serial.print(MCPArray[info.chipId].digitalRead(info.pinNumber)); // Serial.print(","); // Serial.print((int)info.chipId); // Serial.print(","); // Serial.print((int)info.pinNumber); // Serial.println();

} // digitalWrite(LED_BUILTIN, MCPArray[buttonMapping.chipId] .digitalRead(buttonMapping.pinNumber)); Serial.println("Reading buttons"); }

void clearButtons(){ for (int i = 0; i < 98; i++){ buttonsPressed[i] = false; } }

void makeMessageBuffer() { int bufferPosition = 0; for (int i = 0; i < 98; i++){ char theCharacter = '0'; if (buttonsPressed[i] == true) { theCharacter = '1'; } messageBuffer[bufferPosition] = theCharacter; bufferPosition = bufferPosition + 1; messageBuffer[bufferPosition] = ','; bufferPosition = bufferPosition + 1; } messageBuffer[bufferPosition - 1] = 0; }

int sendButtonState() { Udp.beginPacket(broadcastIP, destPort); Udp.write(messageBuffer); Udp.endPacket();

Serial.println("Sending button state"); }

void populateLightTimers() { int lightPosition = 0; for (int i = 0; i < 98; i++){ if (buttonsPressed[i] == true ){ lightTimers_ms[i] = millis() + lightChange_interval_ms; }else if (buttonsPressed[i] == false && lightTimers_ms[i] > millis()){ lightTimers_ms[i] = lightTimers_ms[i]; }else{ lightTimers_ms[i] = millis(); } lightPosition = lightPosition + 1; } }

void setLightColor() { for (int i=0; i<strip.numPixels(); i++){ if (lightTimers_ms[i] > millis()){ strip.setPixelColor(i, 0, 0, 0, 255); }else if (lightTimers_ms[86] > millis() &&lightTimers_ms[78] > millis() &&lightTimers_ms[70] > millis() &&lightTimers_ms[62] > millis() &&lightTimers_ms[54] > millis() &&lightTimers_ms[46] > millis() &&lightTimers_ms[39] > millis() &&lightTimers_ms[32] > millis() &&lightTimers_ms[25] > millis() &&lightTimers_ms[18] > millis() &&lightTimers_ms[11] > millis() &&lightTimers_ms[19] > millis() &&lightTimers_ms[27] > millis() &&lightTimers_ms[35] > millis() &&lightTimers_ms[43] > millis() &&lightTimers_ms[51] > millis() &&lightTimers_ms[58] > millis() &&lightTimers_ms[65] > millis() &&lightTimers_ms[72] > millis() &&lightTimers_ms[79] > millis()){ theaterChase(strip.Color(0, 0, 0, 255)); theaterChase(strip.Color(127, 0, 127, 0)); theaterChase(strip.Color(0, 127, 127, 0)); }else { strip.setPixelColor(i, Wheel((i*2) & 255)); } } strip.show(); }

uint32_t Wheel(byte WheelPos) { WheelPos = 255 - WheelPos; if(WheelPos < 85) { return strip.Color(255 - WheelPos 3, 0, WheelPos 3); } if(WheelPos < 170) { WheelPos -= 85; return strip.Color(0, WheelPos 3, 255 - WheelPos 3); } WheelPos -= 170; return strip.Color(WheelPos 3, 255 - WheelPos 3, 0); }

void theaterChase(uint32_t c) { for (int j=0; j<10; j++) { //do 10 cycles of chasing for (int q=0; q < 3; q++) { for (uint16_t i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, c); //turn every third pixel on } strip.show();

for (uint16_t i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, 0); //turn every third pixel off } }

} }

void setup() { //return; Serial.begin(115200); //delay(100);

pinMode(LED_BUILTIN, OUTPUT); Serial.println("LED_BUILTIN enabled"); digitalWrite(LED_BUILTIN, LOW);

strip.begin(); for (int i=0; i<strip.numPixels(); i++){ strip.setPixelColor(i, Wheel((i*2) & 255)); } strip.show(); // Initialize all pixels to 'off'

populateButtonMapping();

for (int i = 0; i < 7; i++){ MCPArray[i].begin(i); for (int j = 0; j < 16; j++){ MCPArray[i].pinMode(j, INPUT); MCPArray[i].pullUp(j, HIGH); }

}

connectWiFi(); startMDNS();

next_tx_ms = millis(); next_rx_ms = millis(); }

void loop() { //return; //debug if (WiFi.status() != WL_CONNECTED) { connectWiFi(); startMDNS(); } if (next_rx_ms <= millis()) { next_rx_ms = next_rx_ms + rx_interval_ms; // Time to RX a status message readButtons(); populateLightTimers(); setLightColor(); } if (next_tx_ms <= millis()) { next_tx_ms = next_tx_ms + tx_interval_ms; // Time to TX a status message makeMessageBuffer(); sendButtonState(); clearButtons(); }

delay(1); } Debug Messages

This is the most common stack:

0x40203980: UdpContext::send(ip_addr*, unsigned short) at /Users/plamena/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/ libraries/ESP8266WiFi/src/WiFiUdp.cpp line 67 : (inlined by) WiFiUDP::endPacket() at /Users/plamena/Library/ Arduino15/packages/esp8266/hardware/esp8266/2.3.0/ libraries/ESP8266WiFi/src/WiFiUdp.cpp line 191 0x402055dd: Adafruit_NeoPixel::show() at /Users/plamena/Documents/ Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp line 1971 0x4021d92e: wifi_get_opmode at ?? line ? 0x402027d1: sendButtonState() at /Users/plamena/Documents/Projects/MIRR files/MIRR/buttonController_MIRR/buttonController_MIRR.ino line 162 0x40202849: loop at /Users/plamena/Documents/Projects/MIRR files/MIRR/buttonController_MIRR/buttonController_MIRR.ino line 291 0x40205f28: loop_wrapper at /Users/plamena/Library/ Arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/core_esp8266_main.cpp line 56 0x40100718: cont_norm at /Users/plamena/Library/ Arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/cont.S line 109

This one is the other one that shows up: 0x40203980: UdpContext::send(ip_addr*, unsigned short) at /Users/plamena/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/ libraries/ESP8266WiFi/src/WiFiUdp.cpp line 67 : (inlined by) WiFiUDP::endPacket() at /Users/plamena/Library/ Arduino15/packages/esp8266/hardware/esp8266/2.3.0/ libraries/ESP8266WiFi/src/WiFiUdp.cpp line 191 0x4021d92e: wifi_get_opmode at ?? line ? 0x402027d1: sendButtonState() at /Users/plamena/Documents/Projects/MIRR files/MIRR/buttonController_MIRR/buttonController_MIRR.ino line 162 0x4020152f: delay at /Users/plamena/Library/Arduino15/packages/esp8266/ hardware/esp8266/2.3.0/cores/esp8266/core_esp8266_wiring.c line 50 0x40202849: loop at /Users/plamena/Documents/Projects/MIRR files/MIRR/buttonController_MIRR/buttonController_MIRR.ino line 291 0x40205f28: loop_wrapper at /Users/plamena/Library/ Arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/core_esp8266_main.cpp line 56 0x40100718: cont_norm at /Users/plamena/Library/ Arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/cont.S line 109

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/esp8266/Arduino/issues/3443, or mute the thread https://github.com/notifications/unsubscribe-auth/AQC6Bkwb1VUGMNaRiBFbjbHXIsP3EhCuks5sP5K8gaJpZM4Oecqs .

Plamena24 commented 7 years ago

Looks like about 50 milliseconds for the loop but that was done crudely by printing millis() at start and end of loop. If there is a better way to figure that out please let me know. As far as heap usage, I actually have no idea what that question means so if you can elaborate I might be able to check this. (As you can see from my code, I am definitely a novice but happy to learn.)

devyte commented 5 years ago

A lot of things have changed since this was opened, including lwip changes (including udp), mdns rewrite, wiring rewrites. Closing due to age. If the issue is still present, please open a new issue and fill in the requested info.