Troubleshooting NodeMCU exception

I just started working on a project again (Sinric to SinRic Pro) I had things working somewhat and was making programming changes to debug and I started getting an Exception report. I have not been able to get past it. (Shame on me for not incrementally saving as I was making changes ).
Installed the ESP Exception Decoder and got it installed and working but cant figure out how to interpret the results.

 * Example for how to use SinricPro Switch device:
 * - setup a switch device
 * - handle request using callback (turn on/off builtin led indicating device power state)
 * - send event to sinricPro server (flash button is used to turn on/off device manually)
 * If you encounter any issues:
 * - check the at
 * - ensure all dependent libraries are installed
 *   - see
 *   - see
 * - open serial monitor and check whats happening
 * - check full user documentation at
 * - visit and check for existing issues or open a new one

// Uncomment the following line to enable serial debug output

       #define DEBUG_ESP_PORT Serial
       #define NDEBUG

#include <Arduino.h>
#ifdef ESP8266 
       #include <ESP8266WiFi.h>
#ifdef ESP32   
       #include <WiFi.h>

#include "SinricPro.h"
#include "SinricProSwitch.h"

#define WIFI_SSID         "Newspaper2"    
#define WIFI_PASS         "J7153431248"
#define APP_KEY           "5a57fcc3-58ce-4f66-bcb3-db77ecf4997f"      // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
#define APP_SECRET        "45b891f9-763f-4b34-ad8c-f5ce795f23e9-39d483c3-7d13-4b22-abed-fd086efabc7d"   // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
#define SWITCH_ID         "616310a3bf77364fa09ed3f9"    // Should look like "5dc1564130xxxxxxxxxxxxxx"
#define BAUD_RATE         9600                // Change baudrate to your need

#define BUTTON_PIN D0   // GPIO for BUTTON (inverted: LOW = pressed, HIGH = released)
#define LED_PIN   D2   // GPIO for LED (inverted)

#define GASOFF D4
#define GASON D5

bool myPowerState = false;
unsigned long lastBtnPress = 0;

/* bool onPowerState(String deviceId, bool &state) 
 * Callback for setPowerState request
 * parameters
 *  String deviceId (r)
 *    contains deviceId (useful if this callback used by multiple devices)
 *  bool &state (r/w)
 *    contains the requested state (true:on / false:off)
 *    must return the new state
 * return
 *  true if request should be marked as handled correctly / false if not
bool onPowerState(const String &deviceId, bool &state) {
  Serial.printf("Device %s turned %s (via SinricPro) \r\n", deviceId.c_str(), state?"on":"off");
  Serial.printf(" %d  %d\n", state,myPowerState);
  if(state != myPowerState) {
      Serial.printf(" %d  %d\n", state, myPowerState);
      if(state) {   
        Serial.print("True: Turn Off device id: \n");
        digitalWrite(GASOFF, LOW);   // sets relayOne on

        digitalWrite(GASOFF,HIGH);   // sets relayOne on
        Serial.print("False: Turn On Device ID: \n");
        digitalWrite(GASON,LOW);   // sets relayOne on
        digitalWrite(GASON, HIGH);   // sets relayOne on  
 myPowerState = state;
  digitalWrite(LED_PIN, myPowerState?LOW:HIGH);

void handleButtonPress() {
  unsigned long actualMillis = millis(); // get actual millis() and keep it in variable actualMillis
//  Serial.printf("Millis : %d \n", actualMillis);
//  Serial.printf("LastBtnPress: %d \n", lastBtnPress);
  if (digitalRead(BUTTON_PIN) == LOW && actualMillis - lastBtnPress > 1000)  { // is button pressed (inverted logic! button pressed = LOW) and debounced?
    Serial.printf("LastBtnPress: %d \n", lastBtnPress);
    if(myPowerState) {
      digitalWrite(GASOFF, LOW);   // sets relayOne on
      digitalWrite(GASOFF, HIGH);   // sets relayOne on
      digitalWrite(GASON, LOW);   // sets relayOne on
      digitalWrite(GASON, HIGH);   // sets relayOne on  
    digitalWrite(LED_PIN, myPowerState?LOW:HIGH); // if myPowerState indicates device turned on: turn on led (builtin led uses inverted logic: LOW = LED ON / HIGH = LED OFF)

    // get Switch device back
    SinricProSwitch& mySwitch = SinricPro[SWITCH_ID];
    // send powerstate event
    mySwitch.sendPowerStateEvent(myPowerState); // send the new powerState to SinricPro server
    Serial.printf("Device %s turned %s (manually via flashbutton)\r\n", mySwitch.getDeviceId().c_str(), myPowerState?"on":"off");
    lastBtnPress = actualMillis;  // update last button press variable

// setup function for WiFi connection
void setupWiFi() {
  Serial.printf("\r\n[Wifi]: Connecting");

  while (WiFi.status() != WL_CONNECTED) {
  Serial.printf("connected!\r\n[WiFi]: IP-Address is %s\r\n", WiFi.localIP().toString().c_str());

// setup function for SinricPro
void setupSinricPro() {
  // add device to SinricPro
  SinricProSwitch& mySwitch = SinricPro[SWITCH_ID];

  // set callback function to device

  // setup SinricPro
  SinricPro.onConnected([](){ Serial.printf("Connected to SinricPro\r\n"); }); 
  SinricPro.onDisconnected([](){ Serial.printf("Disconnected from SinricPro\r\n"); });
  SinricPro.begin(APP_KEY, APP_SECRET);

// main setup function
void setup() {
  pinMode(GASOFF, OUTPUT);
  pinMode(GASON, OUTPUT);

  pinMode(LED_PIN, OUTPUT);
  digitalWrite(GASOFF, HIGH);   // sets relayOne on
  digitalWrite(GASON, HIGH);   // sets relayOne on  

  Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n");

void loop() {

Here is the Crash report

Exception 0: Illegal instruction
PC: 0x40201329
EXCVADDR: 0x00000000

Decoding stack results
0x4020e718: std::_Function_handler ::_M_invoke(std::_Any_data const&, String const&, bool&) at c:\users\ian\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\c++\10.3.0\bits/std_function.h line 289
0x40203cb5: SINRICPRO_2_9_9::PowerStateController ::handlePowerStateController(SINRICPRO_2_9_9::SinricProRequest&) at c:\users\ian\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\c++\10.3.0\bits/std_function.h line 617
0x4010084b: umm_free_core(umm_heap_context_t*, void*) at C:\Users\Ian\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266\umm_malloc\umm_malloc.cpp line 549
0x4020e794: std::_Function_handler   ::*(SINRICPRO_2_9_9::PowerStateController *, std::_Placeholder1>))(SINRICPRO_2_9_9::SinricProRequest&)> >::_M_invoke(std::_Any_data const&, SINRICPRO_2_9_9::SinricProRequest&) at c:\users\ian\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\c++\10.3.0/functional line 414
0x40201070: SINRICPRO_2_9_9::SinricProDevice::handleRequest(SINRICPRO_2_9_9::SinricProRequest&) at c:\users\ian\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\c++\10.3.0\bits/std_function.h line 617
0x40204ba9: SINRICPRO_2_9_9::SinricProClass::handleRequest(ArduinoJson6172_91::BasicJsonDocument &, SINRICPRO_2_9_9::interface_t) at C:\Users\Ian\Documents\Arduino\libraries\SinricPro/SinricPro.h line 293
0x40201479: ArduinoJson6172_91::CollectionData::getSlot (ArduinoJson6172_91::ConstRamStringAdapter) const at C:\Users\Ian\Documents\Arduino\libraries\ArduinoJson-6.17.2\src/ArduinoJson/Strings/ConstRamStringAdapter.hpp line 25
0x402035bb: SINRICPRO_2_9_9::SinricProClass::extractTimestamp(ArduinoJson6172_91::JsonDocument&) at C:\Users\Ian\Documents\Arduino\libraries\SinricPro/SinricPro.h line 463
0x40204fc0: SINRICPRO_2_9_9::SinricProClass::handleReceiveQueue() at C:\Users\Ian\Documents\Arduino\libraries\SinricPro/SinricProQueue.h line 46
0x401002e1: millis() at C:\Users\Ian\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266\core_esp8266_wiring.cpp line 193
0x4020a87a: __yield() at C:\Users\Ian\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266\core_esp8266_main.cpp line 116
0x401002e1: millis() at C:\Users\Ian\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266\core_esp8266_wiring.cpp line 193
0x402066ee: WiFiUDP::parsePacket() at C:\Users\Ian\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\libraries\ESP8266WiFi\src\WiFiUdp.cpp line 199
0x4020532e: SINRICPRO_2_9_9::UdpListener::handle() at C:\Users\Ian\Documents\Arduino\libraries\SinricPro/SinricProUDP.h line 46
0x40208b68: WebSocketsClient::loop() at C:\Users\Ian\Documents\Arduino\libraries\WebSockets\src\WebSocketsClient.cpp line 279
0x40205407: SINRICPRO_2_9_9::SinricProClass::handle() at C:\Users\Ian\Documents\Arduino\libraries\SinricPro/SinricPro.h line 240
0x40205427: loop() at C:\Users\Ian\Documents\Arduino\SinRicSwitchPro_v3/SinRicSwitchPro_v3.ino line 157
0x4020a8fc: loop_wrapper() at C:\Users\Ian\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266\core_esp8266_main.cpp line 201

Discalimer: I have no experience with the hardware you're using, but do have some coding experience. Based on that:

Check the onPowerState() callback function supplied to the SinicPro object. Comment one line at a time in it and see if the exception goes away - the commented line that makes it go away is probably where the bug is.

Also, see if the exception occurs with the #DEBUG enabled or disabled or both. If its just with or without (but not irrespective) then check the relevant code that is executed with the #if or #else blocks.

Appreciate your time to answer. I think I figured out my issue. In the function

bool onPowerState(const String &deviceId, bool &state)

I needed to have a statement

return true;

I must have deleted by accident. I figured it out by going back to the example I started with and going through the code one line at a time.
Take Care

Good to know. However, its strange it did not give a compiler error or warning because of the missing return statment ...its C so return int must have been assumed.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.