Created
May 15, 2017 22:04
-
-
Save odenak/664a2b162eb55f86bc75b6f2576321d5 to your computer and use it in GitHub Desktop.
simple fauxmo tester for alexa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include <ESP8266WiFi.h> | |
#include "fauxmoESP.h" | |
#define SERIAL_BAUDRATE 115200 | |
#define WIFI_SSID "..." | |
#define WIFI_PASS "..." | |
fauxmoESP fauxmo; | |
// ----------------------------------------------------------------------------- | |
// Wifi | |
// ----------------------------------------------------------------------------- | |
void wifiSetup() { | |
// Set WIFI module to STA mode | |
WiFi.mode(WIFI_STA); | |
// Connect | |
Serial.printf("[WIFI] Connecting to %s ", WIFI_SSID); | |
WiFi.begin(WIFI_SSID, WIFI_PASS); | |
// Wait | |
while (WiFi.status() != WL_CONNECTED) { | |
Serial.print("."); | |
delay(100); | |
} | |
Serial.println(); | |
// Connected! | |
Serial.printf("[WIFI] STATION Mode, SSID: %s, IP address: %s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str()); | |
} | |
void setup() { | |
// Init serial port and clean garbage | |
Serial.begin(SERIAL_BAUDRATE); | |
Serial.println(); | |
Serial.println(); | |
// Wifi | |
wifiSetup(); | |
// LED | |
pinMode(BUILTIN_LED, OUTPUT); | |
digitalWrite(BUILTIN_LED, HIGH); | |
// Fauxmo v2.0 | |
fauxmo.addDevice("garage"); | |
fauxmo.addDevice("pool"); | |
fauxmo.onMessage([](unsigned char device_id, const char * device_name, bool state) { | |
Serial.printf("[MAIN] Device #%d (%s) state: %s\n", device_id, device_name, state ? "ON" : "OFF"); | |
if (strcmp(device_name,"garage") == 0) { | |
digitalWrite(BUILTIN_LED, !state); | |
} | |
if (strcmp(device_name,"pool") == 0) { | |
digitalWrite(BUILTIN_LED, !state); | |
} | |
}); | |
} | |
void loop() { | |
fauxmo.handle(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment