WemoKiller Code V1.0

//------ OTA Update Libraries ------
 #include <ESP8266mDNS.h>
 #include <WiFiUdp.h>
 #include <ArduinoOTA.h>
 //----------------------------------

//------- WIFI MANAGER--------
 #include <DNSServer.h>
 #include <ESP8266WebServer.h>
 #include <WiFiManager.h>
 /************************* Wemo EMU Libraries *********************************/
 #include <ESP8266WiFi.h>
 #include "WemoSwitch.h"
 #include "WemoManager.h"
 #include "CallbackFunction.h"

// prototypes
 boolean connectWifi();

//on/off callbacks
 void r1_On(); void r1_Off();
 void r2_On(); void r2_Off();

WemoManager wemoManager;
 WemoSwitch *relay1 = NULL;
 WemoSwitch *relay2 = NULL;

const int ledPin1 = 16;
 const int ledPin2 = 5;

void setup()
 {
 Serial.begin(115200);

// ----- WiFi Manager -----
 WiFiManager wifiManager;
 wifiManager.autoConnect();
 Serial.println("connected...yeey :)");

// ----- OTA STUFF -----
 ArduinoOTA.setHostname("DevID_001");
 ArduinoOTA.setPassword((const char *)"xander216");
 ArduinoOTA.onStart([]() {
 Serial.println("Start");
 });
 ArduinoOTA.onEnd([]() {
 Serial.println("\nEnd");
 });
 ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
 Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
 });
 ArduinoOTA.onError([](ota_error_t error) {
 Serial.printf("Error[%u]: ", error);
 if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
 else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
 else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
 else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
 else if (error == OTA_END_ERROR) Serial.println("End Failed");
 });
 ArduinoOTA.begin();

// ----- WEMO EMU Stuff -----

wemoManager.begin();
 /* Format:
 * (Alexa invocation name, local port no, on callback, off callback)
 */
 relay1 = new WemoSwitch("killer 1", 80, r1_On, r1_Off);
 relay2 = new WemoSwitch("killer 2", 81, r2_On, r2_Off);

wemoManager.addDevice(*relay1);
 wemoManager.addDevice(*relay2);

pinMode(ledPin1, OUTPUT);
 pinMode(ledPin2, OUTPUT);
 delay(5);
 digitalWrite(ledPin1, HIGH);
 digitalWrite(ledPin2, HIGH);
 }

void loop()
 {
 ArduinoOTA.handle();
 wemoManager.serverLoop();
 }

// ----- RELAY COMMANDS!!! -----

// --- Relay 1 ---
 void r1_On() {
 Serial.print("Relay 1 turn on ...");
 digitalWrite(ledPin1, LOW);
 }
 void r1_Off() {
 Serial.print("Relay 1 turn off ...");
 digitalWrite(ledPin1, HIGH);
 }

// --- Relay 2 ---
 void r2_On() {
 Serial.print("Switch 2 turn on ...");
 digitalWrite(ledPin2, LOW);
 }
 void r2_Off() {
 Serial.print("Switch 2 turn off ...");
 digitalWrite(ledPin2, HIGH);
 }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s