Amazon Echo ESP8266 control, with natural speech commands

A post was split to a new topic: I would like to control the Nodemcu with natural voice commands

Can i use this code to link my esp8266 with my google home ? Because in GH i need a wemo account

Google Home doesn’t have the same native integration as Alexa, but you can connect through IFTTT. Just use IFTTT’s Google Assistant trigger and the Blynk webhook action (instructions in the header comments of the code).

The great thing about Google Home’s IFTTT trigger is that you can specify any phrase, provide alternate phrases, and even create a custom response.

1 Like

Hey,
The code works perfectly. But I have a case usually after power cut the wifi modem takes some time to be up. But the nodemcu immediately creates its own AP and stays there even after the wifi signal is back. in such cases I have connect to the hotspot and do a reset. Have you also faced such issue?

I had a look into the Documentation of WifiManager on Github.I found this:
https://github.com/tzapu/WiFiManager#configuration-portal-timeout

wifiManager.setConfigPortalTimeout(180);

So replacing this

with:

WiFiManager wifiManager;
//sets timeout until configuration portal gets turned off
//useful to make it all retry or go to sleep
//in seconds
wifiManager.setTimeout(180);

//fetches ssid and pass and tries to connect
//if it does not connect it starts an access point with the specified name
//here  "AutoConnectAP"
//and goes into a blocking loop awaiting configuration
if(!wifiManager.autoConnect("AutoConnectAP")) {
Serial.println("failed to connect and hit timeout");
delay(3000);
//reset and try again, or maybe put it to deep sleep
ESP.reset();
delay(5000);
}  

Hope this is helpful to people facing similar problems

1 Like

I am using wemos D1 mini and relay board (4 relays, but for testing I keept everything.
Here is my code

#include <ESP8266WebServer.h>

#include <WiFiManager.h>

#include <DNSServer.h>

#define BLYNK_PRINT Serial // This prints to Serial Monitor
#include <ESP8266WiFi.h>  // for ESP8266
#include <BlynkSimpleEsp8266.h>  // for ESP8266
#include <ESP8266mDNS.h>  // For OTA w/ ESP8266
#include <WiFiUdp.h>  // For OTA
#include <ArduinoOTA.h>  // For OTA

#include "WemoSwitch.h"
#include "WemoManager.h"
#include "CallbackFunction.h"

char auth[] = "xxxx";
char ssid[] = "xxxx";
char pass[] = "xxxx";

//for Alexa

//on/off callbacks
void bedroomlightson();
void bedroomlightsoff();

void loungelightson();
void loungelightsoff();

void gymlightson();
void gymlightsoff();

void tvon();
void tvoff();

void chargeron();
void chargeroff();

void switch1on();
void switch1off();

WemoManager wemoManager;

WemoSwitch *bedroomlights = NULL;
WemoSwitch *loungelights = NULL;
WemoSwitch *gymlights = NULL;
WemoSwitch *tv = NULL;
WemoSwitch *charger = NULL;
WemoSwitch *switch1 = NULL;


const int RelayPin1 = D4;      
const int RelayPin2 = D7;
const int RelayPin3 = D6;
const int RelayPin4 = D5;
const int RelayPin5 = D0;
const int RelayPin6 = D1;

//end Alexa

void setup() {

//Alexa
  pinMode(RelayPin1, OUTPUT);
  digitalWrite(RelayPin1, LOW);   // Turn relay OFF when unit is powered on

  pinMode(RelayPin2, OUTPUT);
  digitalWrite(RelayPin2, LOW);   // Turn relay OFF when unit is powered on

  pinMode(RelayPin3, OUTPUT);
  digitalWrite(RelayPin3, LOW);   // Turn relay OFF when unit is powered on

  pinMode(RelayPin4, OUTPUT);
  digitalWrite(RelayPin4, LOW);   // Turn relay OFF when unit is powered on

  pinMode(RelayPin5, OUTPUT);
  digitalWrite(RelayPin5, LOW);   // Turn relay OFF when unit is powered on

  pinMode(RelayPin6, OUTPUT);
  digitalWrite(RelayPin6, LOW);   // Turn relay OFF when unit is powered on

//end Alexa
  
  Serial.begin(9600);  // BLYNK_PRINT data

//Alexa

  WiFiManager wifi;   //WiFiManager intialization.
  wifi.autoConnect("FakeWemo"); //Create AP, if necessary

  wemoManager.begin();

  // Format: Alexa invocation name, local port no, on callback, off callback

  bedroomlights = new WemoSwitch("bedroom lights", 80, bedroomlightson, bedroomlightsoff);
  loungelights = new WemoSwitch("lounge lights", 81, loungelightson, loungelightsoff);
  gymlights = new WemoSwitch("gym lights", 82, gymlightson, gymlightsoff);
  tv = new WemoSwitch("tv", 83, tvon, tvoff);
  charger = new WemoSwitch("charger", 84, chargeron, chargeroff);
  switch1 = new WemoSwitch("switch 1", 85, switch1on, switch1off);

  wemoManager.addDevice(*bedroomlights);
  wemoManager.addDevice(*loungelights);
  wemoManager.addDevice(*gymlights);
  wemoManager.addDevice(*tv);
  wemoManager.addDevice(*charger);
  wemoManager.addDevice(*switch1);
//end alexa


  WiFi.begin(ssid, pass); 
  Blynk.connect();

  ArduinoOTA.setHostname("Wemos_0518");  // For OTA - Use your own device identifying name
  ArduinoOTA.setPassword("xxxx");

  ArduinoOTA.begin();  // For OTA
}
//Alexa

// Toggle the relay on
void bedroomlightson() 
  {

    digitalWrite(RelayPin1, HIGH);
    Blynk.virtualWrite(V1, HIGH);     // Sync the Blynk button widget state
}

void loungelightson() 

{
    digitalWrite(RelayPin2, HIGH);
    Blynk.virtualWrite(V2, HIGH);     // Sync the Blynk button widget state
}

void gymlightson() 

{
    digitalWrite(RelayPin3, HIGH);
    Blynk.virtualWrite(V3, HIGH);     // Sync the Blynk button widget state
}

void tvon() 

{
    digitalWrite(RelayPin4, HIGH);
    Blynk.virtualWrite(V4, HIGH);     // Sync the Blynk button widget state
}

void chargeron()

{
    digitalWrite(RelayPin5, HIGH);
    Blynk.virtualWrite(V5, HIGH);     // Sync the Blynk button widget state
}

void switch1on() 

{
    digitalWrite(RelayPin6, HIGH);
    Blynk.virtualWrite(V6, HIGH);     // Sync the Blynk button widget state
}

// Toggle the relay off

void bedroomlightsoff() 
{
    digitalWrite(RelayPin1, LOW);
    Blynk.virtualWrite(V1, LOW);      // Sync the Blynk button widget state
}

void loungelightsoff() 
{
    digitalWrite(RelayPin2, LOW);
    Blynk.virtualWrite(V2, LOW);      // Sync the Blynk button widget state
}

void gymlightsoff() 

{
    digitalWrite(RelayPin3, LOW);
    Blynk.virtualWrite(V3, LOW);      // Sync the Blynk button widget state
}

void tvoff() 

{
    digitalWrite(RelayPin4, LOW);
    Blynk.virtualWrite(V4, LOW);      // Sync the Blynk button widget state
}

void chargeroff() 

{
    digitalWrite(RelayPin5, LOW);
    Blynk.virtualWrite(V5, LOW);      // Sync the Blynk button widget state
}

void switch1off() 
{
    digitalWrite(RelayPin6, LOW);
    Blynk.virtualWrite(V6, LOW);      // Sync the Blynk button widget state
    }

// Handle switch changes originating on the Blynk app
BLYNK_WRITE(V1){
  int SwitchStatus1 = param.asInt();
   if (SwitchStatus1 == 1) {
    digitalWrite(RelayPin1, LOW);
  }
  else {
    digitalWrite(RelayPin1, HIGH);
  }
}

BLYNK_WRITE(V2){
  int SwitchStatus2 = param.asInt();
  if (SwitchStatus2 == 1) {
    digitalWrite(RelayPin2, LOW);
  }
  else {
    digitalWrite(RelayPin2, HIGH);
  }
}

BLYNK_WRITE(V3){
  int SwitchStatus3 = param.asInt();
  if (SwitchStatus3 == 1) {
    digitalWrite(RelayPin3, LOW);
  }
  else {
    digitalWrite(RelayPin3, HIGH);
  }
}

BLYNK_WRITE(V4){
  int SwitchStatus4 = param.asInt();
  if (SwitchStatus4 == 1) {
    digitalWrite(RelayPin4, LOW);
  }
  else {
    digitalWrite(RelayPin4, HIGH);
  }
}

BLYNK_WRITE(V5){
  int SwitchStatus5 = param.asInt();
  if (SwitchStatus5 == 1) {
    digitalWrite(RelayPin5, LOW);
  }
  else {
    digitalWrite(RelayPin5, HIGH);
  }
}

BLYNK_WRITE(V6){
  int SwitchStatus6 = param.asInt();
  if (SwitchStatus6 == 1) {
    digitalWrite(RelayPin6, LOW);
  }
  else {
    digitalWrite(RelayPin6, HIGH);
  }

}


//end Alexa
void loop() {
//Alexa
  wemoManager.serverLoop();
//end Alexa
  Blynk.run();
  ArduinoOTA.handle();  // For OTA
}

But when I try to compile the sketch, I get this error:

1 Like

You need to choose how you’re going to connect the wifi. Right now, you’ve got BOTH hard coded provisioning and WiFi Manager built into the sketch. If you’re going to hard code the SSID and password, you’ll have to remove all of the WiFi Manager code.

Otherwise, just leave the provisioning code as it was in the example, and use Blynk.auth(“your_token”) to connect to Blynk. You don’t need Blynk.connect or WiFi.begin.

So I can not have one default wifi network? For example that my home network is always entered and I do not need to reenter it everytime I come in a range of home network (I am using it also in my camper van)

I copied that code on my Wemos D1 mini, didn’t change anything (except auth), but I still get this error :frowning:

The simple answer is “no,” you can’t do both dynamic provisioning and hard-coded provisioning.

However, you could try static provisioning first, and if it’s unable to connect, then run the WiFi manager code. I haven’t tested this, but here’s how I’d probably do it. In the Setup function, I’d try:

WiFi.begin("SSID", "password");

// Create a 10 second timeout for connecting with the saved credentials
int WiFiTimeout = millis() + 10000;
while (WiFi.status() != WL_CONNECTED && WiFiTimeout > millis())
{
  delay(500);
  Serial.print(".");
}

// If it didn't connect before the timeout expired, run WiFi Manager to set up dynamic provisioning
if(WiFi.status() != WL_CONNECTED){
  WiFiManager wifi;
  if(!wifi.autoConnect("FakeWEMO")) {
    Serial.println("Failed to connect.");
    delay(1000);
    ESP.reset(); //reset if new credentials failed.
    delay(1000);
  }
}
 
Blynk.auth("your_token");

Hi @monaco

can you try to upgrade Esp8266 to 2.3.0 version?

hope it work

FYI v2.4.1 is latest version. GitHub - esp8266/Arduino: ESP8266 core for Arduino

I use Wemos D1 mini…

@monaco A Wemos D1 Mini IS an ESP8266 based board :wink: … and it appears you are running a old ESP8266 Arduino Core version of 2.2.0 … so click on the link I provided above above, update it, then try again.

1 Like

If anyone is having an issue with devices always responding “ON” after updating to ESP8266 Arduino core 2.4.x, see the following article for the fix:

@chrome1000 I am trying to make this project with local blynk server and I write blynk.config(auth, ipaddress(192,168,1,15), 8080) but i start getting random errors about functions not being in scope. What should I do? It was working fine with blynk cloud server.

Thanks. Help will be appreciated.

If you want to use the IPAddress variable type then you need to identify it correctly (the first three characters are capitals, as I’ve just shown).
Otherwise just use a string literal like this:

blynk.config(auth, “192.168.1.15”, 8080)

Pete.

1 Like

@Chirag1712 you already have a topic open about this, please keep further correspondence on this issue in that topic.

1 Like

this usually happens in this code when you have a missing closing bracket “}”

It’s now fixed in his other thread about which port to use.

Maybe @Gunner could do a bit of a cleanup on this thread to get rid of the detritus?

Pete.

very nice project, all up and running on my blynk local server as well, i removed wifi manager in setup. now we have multiple ways of switching things with button feedback…nice