ESP8266 Unexpected Crash or Reset



  • I had problems with the ESP8266 Gateway crashing and resetting every few minutes with an "Exception(28)".

    After lots of searching, I found it was a problem in the 'core driver' in the MySensors library (1.51).

    The Fix:

    • Open the "MyMessage.cpp" file in your "...\Arduino\libraries\MySensors" folder.
    • Search for the "MyMessage& MyMessage::set(const char* value)" function (WARNING: there are several similar names).
    • Comment the existing code out and add replacement as illustrated below.
    /*  COMMENT OUT THE OLD FUNCTION
    MyMessage& MyMessage::set(const char* value) {
    	uint8_t length = min(strlen(value), MAX_PAYLOAD);
    	miSetLength(length);
    	miSetPayloadType(P_STRING);
    	strncpy(data, value, length);
    	return *this;
    }
    */
    
    /*   INSERT THE FOLLOWING IN ITS PLACE   */
    MyMessage& MyMessage::set(const char* value) {
    	uint8_t length = value == NULL ? 0 : min(strlen(value), MAX_PAYLOAD);
    	miSetLength(length);
    	miSetPayloadType(P_STRING);
    	if (length) {		
    		strncpy(data, value, length);
    	}
    	// null terminate string
    	data[length] = 0;
    	return *this;
    }
    

    If you compile any MySensors ESP8266 project, the library will be rebuilt and with a bit of luck the crashes will vanish.

    Paul


  • Mod

    @AffordableTech So, concluding, the set-method will crash when called with a null-pointer.
    Does your sketch call it with a null-pointer, or does the MySensors library pass it somewhere along the road?



  • @Yveaux

    Yes, I believe it happens when a client connects with no message, it causes a memory fault (loss); after several such connections the stack is exhausted and the ESP8266 crashes (and reboots).

    This cured my crashes, but I'm sure there are many other possibilities for an Exception(28).


  • Admin

    This has been fixed in development branch. It was never backported.



  • @hek

    Yes, as I gathered, but I have too many sensors on 1.5.1 and don't want to upgrade them to 2.0 while its not an official release.

    I posted it because there are probably others on 1.5.1 with the problem, but can't find a fix.

    Cheers...


 

439
Online

7.9k
Users

8.8k
Topics

93.8k
Posts