StickC reboots when sending message via esp-now. [solved]
-
As the subject says, I have copied the example code for esp-now on esp32 from randomnerdtutorials to comunicate a stickC with an Atom Lite. If the atom is off,the code works ok, but if the atom is on, the message is sent once, and then, the stickC reboots, in a loop, send message, reboot, send message, reboot.
/* * based on https://randomnerdtutorials.com/esp-now-esp32-arduino-ide/ */ #include <M5StickC.h> #include <WiFi.h> #include <esp_now.h> // wifi settings const char* ssid = "cositas_electronicas"; IPAddress local_IP(192, 168, 0, 101); IPAddress gateway(192, 168, 0, 1); IPAddress subnet(255, 255, 0, 0); IPAddress primaryDNS(1, 1, 1, 1); //optional IPAddress secondaryDNS(9, 9, 9, 9); //optional // esp now // receiver mac address uint8_t broadcastAddress[] = {0x24, 0xA1, 0x60, 0x46, 0xF1, 0x70}; // structure to send data, must match receiver structure typedef struct struct_message { char a[32]; int b; } struct_message; // create a struct_message called myData struct_message myData; // callback when data is sent void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { M5.Lcd.fillScreen(BLACK); M5.Lcd.setCursor(0, 20); M5.Lcd.println("Last Pkg send status"); M5.Lcd.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail"); } void setup() { M5.begin(); Serial.begin(115200); Serial.println("starting...."); WiFi.mode(WIFI_AP_STA); // Configures static IP address if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) { Serial.println("STA Failed to configure"); } // Connect to Wi-Fi network with SSID M5.Lcd.fillScreen(BLACK); M5.Lcd.setTextColor(GREEN , BLACK); M5.Lcd.setRotation(3); M5.Lcd.setCursor(0, 20); M5.Lcd.println("Connecting to "); M5.Lcd.println(ssid); WiFi.begin(ssid); while (WiFi.status() != WL_CONNECTED) { delay(500); M5.Lcd.print("."); } // Print local IP address M5.Lcd.fillScreen(BLACK); M5.Lcd.setCursor(0, 20); M5.Lcd.println("WiFi connected."); M5.Lcd.println("IP address: "); M5.Lcd.println(WiFi.localIP()); delay(1000); M5.Lcd.fillScreen(BLACK); Serial.println(WiFi.macAddress()); // init esp-now if (esp_now_init() != ESP_OK) { Serial.println("Error initializing ESP-NOW"); return; } // Once ESPNow is successfully Init, we will register for Send CB to // get the status of Trasnmitted packet esp_now_register_send_cb(OnDataSent); // Register peer esp_now_peer_info_t peerInfo; memcpy(peerInfo.peer_addr, broadcastAddress, 6); peerInfo.channel = 0; peerInfo.encrypt = false; // Add peer if (esp_now_add_peer(&peerInfo) != ESP_OK) { M5.Lcd.fillScreen(BLACK); M5.Lcd.setCursor(0, 20); M5.Lcd.println("Failed to add peer"); return; } } void loop() { // Set values to send strcpy(myData.a, "This is a char"); myData.b = random(1, 10); // Send message via ESP-NOW esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &myData, sizeof(myData)); if (result == ESP_OK) { M5.Lcd.fillScreen(BLACK); M5.Lcd.setCursor(0, 20); M5.Lcd.println("Sent with success"); } else { M5.Lcd.fillScreen(BLACK); M5.Lcd.setCursor(0, 20); M5.Lcd.println("Error sending the data"); } delay(2000); }In the serial monitor I get this:
M5StickC initializing...OK starting.... 24:A1:60:45:B2:44 ELF file SHA256: 0000000000000000 Backtrace: 0x40088e68:0x3ffbf810 0x400890e5:0x3ffbf830 0x4012f684:0x3ffbf850 0x40086f65:0x3ffbf870 0x400d1bf8:0x3ffb5830 0x400d26fb:0x3ffb5850 0x4014565d:0x3ffb5880 0x400d06c5:0x3ffb58a0 0x40133f75:0x3ffb58c0 0x401028ef:0x3ffb58e0 0x40104b6e:0x3ffb5910 0x4008a0f6:0x3ffb5940 #0 0x40088e68:0x3ffbf810 in invoke_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c:715 #1 0x400890e5:0x3ffbf830 in abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c:715 #2 0x4012f684:0x3ffbf850 in task_wdt_isr at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/task_wdt.c:252 #3 0x40086f65:0x3ffbf870 in _xt_lowint1 at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/xtensa_vectors.S:1154 #4 0x400d1bf8:0x3ffb5830 in TFT_eSPI::setWindow(int, int, int, int) at .pio/libdeps/m5stick-c/M5StickC/src/utility/In_eSPI.cpp:5995 #5 0x400d26fb:0x3ffb5850 in TFT_eSPI::fillRect(int, int, int, int, unsigned int) at .pio/libdeps/m5stick-c/M5StickC/src/utility/In_eSPI.cpp:5995 #6 0x4014565d:0x3ffb5880 in TFT_eSPI::fillScreen(unsigned int) at .pio/libdeps/m5stick-c/M5StickC/src/utility/In_eSPI.cpp:5995 #7 0x400d06c5:0x3ffb58a0 in OnDataSent(unsigned char const*, esp_now_send_status_t) at src/main.cpp:32 #8 0x40133f75:0x3ffb58c0 in esp_now_add_peer at ??:? #9 0x401028ef:0x3ffb58e0 in ppProcTxDone at ??:? #10 0x40104b6e:0x3ffb5910 in ppTask at ??:? #11 0x4008a0f6:0x3ffb5940 in vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c:355 (discriminator 1) Rebooting... M5StickC initializing...OK starting.... 24:A1:60:45:B2:44This happens in two different stickC, using platformio in linux. Any ideas?
-
Hello @benalb
when I replace the
M5.Lcd.commands inOnDataSent()withSerial.println()commands the crash goes away.I assume that either the
M5.Lcd.commanda take too much time (triggering the WDT) or are not thread-safe.Try only setting a flag in
OnDataSent()and the do the LCD screen updates inside the `loop()'.e.g. something like this:
int iFlag = -1; // -1 init; 0 success; 1 fail void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { if(status == ESP_NOW_SEND_SUCCESS) iFlag = 0; // success else iFlag = 1; // fail }then in the loop:
if(iFlag != -1) { M5.Lcd.fillScreen(BLACK); M5.Lcd.setCursor(0, 20); M5.Lcd.println("Last Pkg send status"); if(iFlag == 0) M5.Lcd.println("Delivery Success"); else M5.Lcd.println("Delivery Fail"); iFlag = -1; }Thanks
Felix -
@felmue Thank you very much for the solution and the explanation. It now works,
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login