Vin
Vin

Reputation: 1

NodeMCU ESP8266 Alexa interface works, but GPIO state change does not and always "Soft WDT Reset" following Alexa command

The purpose of the code listed below is to enable Alexa to control a relay, which then controls a medical chair slave remote control. The code is significantly based on this example: https://randomnerdtutorials.com/alexa-echo-with-esp32-and-esp8266/. I have installed the ESP8266 add-on for the Arduino IDE.

The code compiles, connects and responds to the Alexa command "recline on" as seen in the Serial Monitor (pasted below code), however, it does not change the state of GPIO05 or any other pin. It is also always followed by a "Soft WDT reset" 2 seconds after receiving the Alexa command which disconnects itself from the network. My intent is to keep GPIO05 high for 11 seconds in order to move the chair back to its intended position. I have tried this on 3 identical ESP8266 boards with the same result.

I tried using different GPIO pins in case I misunderstood the assignments with no change. I have the pinout diagram so I think that I know which pins are best suited for this purpose. I do not have the relay connected to the board. I'm trying to debug before going forward. The relay will have its own power supply.

Thank you in advance for any assistance.

#include <Arduino.h>

#include <ESP8266WiFi.h>
// #define RF_RECEIVER 5

// Assign relay inputs from ESP8266 board GPIO's
#define RELAY_PIN_1 5 //GPIO05 labeled D1 on NodeMCU 1.0 ESP-12E board

#include "fauxmoESP.h"

#define SERIAL_BAUDRATE 9600

#define ssid "************"
#define password "************"

WiFiClient client;

// Assign Alexa 'commands' to ESP8266 board GPIO's
#define RECLINE "recline"

fauxmoESP fauxmo;

/*
* Connect controller to WiFi
*/
void connectToWiFi() {
//Connect to WiFi Network
   Serial.println();
   Serial.println();
   Serial.print("Connecting to WiFi");
   Serial.println("...");
   WiFi.begin(ssid, password);
   int retries = 0;
while ((WiFi.status() != WL_CONNECTED) && (retries < 15)) {
   retries++;
   delay(500);
   Serial.print(".");
}
if (retries > 14) {
    Serial.println(F("WiFi connection FAILED"));
}
if (WiFi.status() == WL_CONNECTED) {
    Serial.println(F("WiFi connected!"));
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
}
    Serial.println(F("Setup ready"));
}

void setup() {
  // Init serial port and clean garbage
  Serial.begin(SERIAL_BAUDRATE);
  Serial.println();

  // Wi-Fi connection
  connectToWiFi();

  //pinMode(RELAY_PIN_1, OUTPUT); 

  digitalWrite(RELAY_PIN_1, HIGH);   //Set remote commands to LOW ("OFF") position for safety

  // By default, fauxmoESP creates it's own webserver on the defined port
  // The TCP port must be 80 for gen3 devices (default is 1901)
  // This has to be done before the call to enable()
  fauxmo.createServer(true); // not needed, this is the default value
  fauxmo.setPort(80); // This is required for gen3 devices

  // You have to call enable(true) once you have a WiFi connection
  // You can enable or disable the library at any moment
  // Disabling it will prevent the devices from being discovered and switched
  fauxmo.enable(true);
  // You can use different ways to invoke alexa to modify the devices state:
  // "Alexa, turn lamp two on"

  // Add virtual devices
  fauxmo.addDevice(RECLINE);

  fauxmo.onSetState([](unsigned char device_id, const char * device_name, bool state, unsigned char value) {
    // Callback when a command from Alexa is received. 
    // You can use device_id or device_name to choose the element to perform an action onto (relay, LED,...)
    // State is a boolean (ON/OFF) and value a number from 0 to 255 (if you say "set kitchen light to 50%" you will receive a 128 here).
    // Just remember not to delay too much here, this is a callback, exit as soon as possible.
    // If you have to do something more involved here set a flag and process it in your main loop.
        
    Serial.printf("[MAIN] Device #%d (%s) state: %s value: %d\n", device_id, device_name, state ? "ON" : "OFF", value);
    
    if ( (strcmp(device_name, RECLINE) == 0) ) {     // this just sets a variable that the main loop() does something about
      Serial.println("RELAY 1 switched by Alexa");
      digitalWrite(RELAY_PIN_1, HIGH);
      delay(11000);                                  // turn on for 11 seconds
      Serial.println("RELAY_PIN_1, LOW");
      }

  });
}

void loop() {
  fauxmo.handle();
}
Serial Monitor Output:

22:03:59.655 -> Connecting to WiFi...
22:04:00.255 -> ...........WiFi connected!
22:04:06.003 -> IP address: 
22:04:06.003 -> 192.168.1.208
22:04:06.003 -> Setup ready
22:13:37.602 -> [MAIN] Device #0 (recline) state: ON value: 255
22:13:37.686 -> RELAY 1 switched by Alexa
22:13:40.469 -> 
22:13:40.469 -> --------------- CUT HERE FOR EXCEPTION DECODER ---------------
22:13:40.532 -> 
22:13:40.532 -> Soft WDT reset
22:13:40.532 -> 
22:13:40.564 -> Exception (4):
22:13:40.564 -> epc1=0x40105d12 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
22:13:40.661 -> 
22:13:40.661 -> >>>stack>>>
22:13:40.661 -> 
22:13:40.661 -> ctx: sys
22:13:40.693 -> sp: 3fffeaf0 end: 3fffffb0 offset: 0160
22:13:40.725 -> 3fffec50:  00000000 0008dd1d 40205ecc 00001fcd  
22:13:40.789 -> 3fffec60:  3ffee8e4 0008dd1d 00002af8 00002af8  
REPEATS MANY MANY TIMES....

Upvotes: 0

Views: 44

Answers (0)

Related Questions