Comments (4)
from arduino-esp8266-alexa-multiple-wemo-switch.
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <WiFiUdp.h>
#include
#include "switch.h"
#include "UpnpBroadcastResponder.h"
#include "CallbackFunction.h"
// prototypes
boolean connectWifi();
//on/off callbacks
bool garageDoorOpenOn();
bool garageDoorOpenOff();
bool garageDoorCloseOn();
bool garageDoorCloseOff();
// Change this before you flash
const char* ssid = "JustBePatient_VirusDownloading";
const char* password = "HH563dggrtvvxz";
boolean wifiConnected = false;
UpnpBroadcastResponder upnpBroadcastResponder;
Switch *garagedooropen = NULL;
Switch *garagedoorclose = NULL;
bool isgarageDoorOpenOn = false;
bool isgarageDoorCloseOn = false;
bool GarageDoorState = false;
bool PrevGarageDoorState = false;
const int garageDoorRelay = 0; // GPIO0 pin.
const int GPIO2 = 2; // GPIO2 pin. this would be better if it were the RXD pin, it would make restarts with the door open possible...
void setup()
{
pinMode(garageDoorRelay, OUTPUT);
pinMode(GPIO2, OUTPUT); // to start with, it changes later...
Serial.begin(9600);
Serial.println("Booting...");
delay(2000);
//flash fast a few times to indicate CPU is booting
digitalWrite(GPIO2, LOW);
delay(100);
digitalWrite(GPIO2, HIGH);
delay(100);
digitalWrite(GPIO2, LOW);
delay(100);
digitalWrite(GPIO2, HIGH);
delay(100);
digitalWrite(GPIO2, LOW);
delay(100);
digitalWrite(GPIO2, HIGH);
Serial.println("Delaying a bit...");
delay(2000);
// Initialise wifi connection
wifiConnected = connectWifi();
if(wifiConnected){
//flash slow a few times to indicate wifi connected OK
digitalWrite(GPIO2, LOW);
delay(1000);
digitalWrite(GPIO2, HIGH);
delay(1000);
digitalWrite(GPIO2, LOW);
delay(1000);
digitalWrite(GPIO2, HIGH);
delay(1000);
digitalWrite(GPIO2, LOW);
delay(1000);
digitalWrite(GPIO2, HIGH);
upnpBroadcastResponder.beginUdpMulticast();
// Define your switches here. Max 10
// Format: Alexa invocation name, local port no, on callback, off callback
garagedooropen = new Switch("garage door open", 80, garageDoorOpenOn, garageDoorOpenOff);
garagedoorclose = new Switch("garage door close", 81, garageDoorCloseOn, garageDoorCloseOff);
Serial.println("Adding switches upnp broadcast responder");
upnpBroadcastResponder.addDevice(*garagedooropen);
upnpBroadcastResponder.addDevice(*garagedoorclose);
}
digitalWrite(garageDoorRelay, LOW); // turn off relay
digitalWrite(GPIO2, HIGH); // turn off LED
Serial.println("Making GPIO2 into an INPUT"); // used to detect garage door current state
pinMode(GPIO2, INPUT);
PrevGarageDoorState = GarageDoorState; // edge detection of garage door state
}
void loop()
{
GarageDoorState = digitalRead(GPIO2); //either GPIO 2 or RX Pin depending on variable used...
delay(100);
if (GarageDoorState == LOW) {
if (PrevGarageDoorState == HIGH){
Serial.println("GarageDoor State has just opened (Logic LOW)");
}
}
if (GarageDoorState == HIGH) {
if (PrevGarageDoorState == LOW){
Serial.println("GarageDoor State has just closed (Logic HIGH)");
}
}
PrevGarageDoorState = GarageDoorState; // remember prev state for next pass
if(wifiConnected){
upnpBroadcastResponder.serverLoop();
garagedoorclose->serverLoop();
garagedooropen->serverLoop();
}
}
bool garageDoorOpenOn() {
Serial.println("Request to Open door received ...");
if (GarageDoorState == HIGH) { // only pulse relay if door is currently closed
Serial.println("Door is closed - pulsing relay to open it");
Serial.println("XXX Pulsing Relay on ...");
digitalWrite(garageDoorRelay, HIGH); // turn on relay
delay(2000); ;
Serial.println("XXX Pulsing Relay off again ...");
digitalWrite(garageDoorRelay, LOW); // turn off relay
}
else {
Serial.println("Door is already open - not pulsing relay!");
}
isgarageDoorOpenOn = false;
return isgarageDoorOpenOn;
}
bool garageDoorOpenOff() { // nothing ever calls this....
Serial.println("Switch 1 turn off ...");
digitalWrite(garageDoorRelay, LOW); // turn off relay
isgarageDoorOpenOn = false;
return isgarageDoorOpenOn;
}
bool garageDoorCloseOn() {
Serial.println("Request to Close door received");
if (GarageDoorState == LOW) { // only pulse relay if door is currently open
Serial.println("Door is open - pulsing relay to close it");
Serial.println("XXX Pulsing Relay on ...");
digitalWrite(garageDoorRelay, HIGH); // turn on relay
delay(2000); ;
Serial.println("XXX Pulsing Relay off again ...");
digitalWrite(garageDoorRelay, LOW); // turn off relay
}
else {
Serial.println("Door is already closed, not pulsing relay...");
}
isgarageDoorCloseOn = false;
return isgarageDoorCloseOn;
}
bool garageDoorCloseOff() { // nothing ever calls this....
Serial.println("Switch 2 turn off ...");
digitalWrite(garageDoorRelay, LOW); // turn off relay
isgarageDoorCloseOn = false;
return isgarageDoorCloseOn;
}
// connect to wifi – returns true if successful or false if not
boolean connectWifi(){
boolean state = true;
int i = 0;
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
Serial.println("Connecting to WiFi Network");
// Wait for connection
Serial.print("Connecting ...");
while (WiFi.status() != WL_CONNECTED) {
delay(5000);
Serial.print(".");
if (i > 10){
state = false;
break;
}
i++;
}
if (state){
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
else {
Serial.println("");
Serial.println("Connection failed. Bugger");
}
return state;
}
from arduino-esp8266-alexa-multiple-wemo-switch.
Cant use sinric, its not released in NZ. But its not the skill i am having an issue with, its the values returned to Alexa in the ESP-2866 code.
I want to return the state of GPIO2 (which i have read into the booleen variable "GarageDoorState") to Alexa so it appears as the smart switch state.
"I am not sure what are you trying to do. Check whether sinric.com can
support"
from arduino-esp8266-alexa-multiple-wemo-switch.
from arduino-esp8266-alexa-multiple-wemo-switch.
Related Issues (20)
- How do you integrate mqtt for home assistant?
- Alexa and Synric Not Binding
- Echo Dot Gen 3 Compability HOT 13
- WiFiUDP.h: No such file or directory
- Analog values? HOT 2
- Help with multiple RCSwtich.h devices?
- How to change invocation word? Instead of " turn on" HOT 2
- No such file or directory HOT 2
- Connection problem between ESP3266 and alexa on amazon Echo HOT 6
- Not an Issue But a question HOT 5
- 3-way switch
- I can't use your Alexa skill for this project. When I ask Alexa to discover I get the following. HOT 5
- I am working on my NodeMCU v2 ESP 12-E module but every so often I get an Exception and the NodeMCU crashes. The stack is attached below HOT 1
- how to resolve this issue
- Add a push button to manually turn on/off the lights HOT 2
- Emulated wemos devices unresponsive in Alexa HOT 1
- Could not Compile the code
- Update status to Alexa HOT 1
- can i change invocation phrase? HOT 2
- Question on Alexa status HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduino-esp8266-alexa-multiple-wemo-switch.