<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[StickC reboots when sending message via esp-now. [solved]]]></title><description><![CDATA[<p dir="auto">As the subject says,  I have copied the example code for esp-now on esp32 from <a href="https://randomnerdtutorials.com/esp-now-esp32-arduino-ide/" target="_blank" rel="noopener noreferrer nofollow ugc">randomnerdtutorials</a> 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.</p>
<pre><code>/*
 * based on https://randomnerdtutorials.com/esp-now-esp32-arduino-ide/
 */
#include &lt;M5StickC.h&gt;
#include &lt;WiFi.h&gt;
#include &lt;esp_now.h&gt;

// 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(&amp;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 *) &amp;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);
}
</code></pre>
<p dir="auto">In the serial monitor I get this:</p>
<pre><code>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:44

</code></pre>
<p dir="auto">This happens in two different stickC, using platformio in linux.  Any ideas?</p>
]]></description><link>https://community.m5stack.com/topic/3648/stickc-reboots-when-sending-message-via-esp-now-solved</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Apr 2026 11:05:21 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/3648.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 16 Oct 2021 06:44:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to StickC reboots when sending message via esp-now. [solved] on Fri, 22 Oct 2021 07:35:18 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/felmue" aria-label="Profile: felmue">@<bdi>felmue</bdi></a> Thank you very much for the solution and the explanation. It now works,</p>
]]></description><link>https://community.m5stack.com/post/15202</link><guid isPermaLink="true">https://community.m5stack.com/post/15202</guid><dc:creator><![CDATA[benalb]]></dc:creator><pubDate>Fri, 22 Oct 2021 07:35:18 GMT</pubDate></item><item><title><![CDATA[Reply to StickC reboots when sending message via esp-now. [solved] on Thu, 21 Oct 2021 10:01:04 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/user/benalb" aria-label="Profile: benalb">@<bdi>benalb</bdi></a></p>
<p dir="auto">when I replace the <code>M5.Lcd.</code> commands in <code>OnDataSent()</code> with <code>Serial.println()</code> commands the crash goes away.</p>
<p dir="auto">I assume that either the <code>M5.Lcd.</code> commanda take too much time (triggering the WDT) or are not thread-safe.</p>
<p dir="auto">Try only setting a flag in <code>OnDataSent()</code> and the do the LCD screen updates inside the `loop()'.</p>
<p dir="auto">e.g. something like this:</p>
<pre><code>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
}
</code></pre>
<p dir="auto">then in the loop:</p>
<pre><code>  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;
  }
</code></pre>
<p dir="auto">Thanks<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/15181</link><guid isPermaLink="true">https://community.m5stack.com/post/15181</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Thu, 21 Oct 2021 10:01:04 GMT</pubDate></item></channel></rss>