Comments (2)
Original comment by Xose Pérez (Bitbucket: [Xose Pérez](https://bitbucket.org/Xose Pérez), ).
Move the wifiSetup() line below the pinMode lines. The pin is not initialized when you try to turn the LED on.
from fauxmoesp.
Original comment by mmoraes80 (Bitbucket: mmoraes80, GitHub: mmoraes80).
Fixed it... My code already had wifiSetup() line below pinMode lines but for some reason, AMICA ESP8266 NodeMCU board has inverted logic for the built in LED.
Now it blinks while connecting and stays on when connected (in case you are not able to use the serial monitor);
#!arduino
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include "fauxmoESP.h"
#include "credentials.h"
#define SERIAL_BAUDRATE 115200
boolean waitState = true;
// Assign Arduino Friendly Names to GPIO pins
#define D0 16
#define D1 5 // I2C Bus SCL (clock)
#define D2 4 // I2C Bus SDA (data)
#define D3 0
#define D4 2 // Same as "LED_BUILTIN", but inverted logic
#define D5 14 // SPI Bus SCK (clock)
#define D6 12 // SPI Bus MISO
#define D7 13 // SPI Bus MOSI
#define D8 15 // SPI Bus SS (CS)
#define D9 3 // RX0 (Serial console)
#define D10 1 // TX0 (Serial console)
fauxmoESP fauxmo;
void wifiSetup() {
// Set WIFI module to STA mode
WiFi.mode(WIFI_STA);
// Connecting
Serial.printf("[WIFI] Connecting to %s ", WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASS);
// Wait
while (WiFi.status() != WL_CONNECTED) {
waitState = !waitState;
digitalWrite(D4, waitState);
delay(100);
Serial.print(".");
}
digitalWrite(D4, LOW); // LED has inverted logic, so to turn it on, pin needs to be on LOW.
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();
// Pin Mode Setting
pinMode(D4, OUTPUT);
pinMode(D5, OUTPUT);
// Wifi Initialization
wifiSetup();
// You can enable or disable the library at any moment. Disabling it will prevent the devices from being discovered and switched
fauxmo.enable(true);
// Add virtual devices
fauxmo.addDevice("switch one"); // Device_ID = 0
//fauxmo.addDevice("switch two"); // Device_ID = 1
//fauxmo.addDevice("switch three"); // Device_ID = 2
// fauxmoESP 2.0.0 has changed the callback signature to add the device_id, this WARRANTY is easier to match devices to action without
// having to compare strings.
fauxmo.onSetState([](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 (device_id == 0) digitalWrite(D5, !state);
//if (device_id == 1) digitalWrite(D6, !state);
});
// Callback to retrieve current state (for GetBinaryState queries)
fauxmo.onGetState([](unsigned char device_id, const char * device_name) {
if (device_id == 0) return digitalRead(D5);
//if (device_id == 1) return digitalRead(D6);
});
}
void loop() {
// Since fauxmoESP 2.0 the library uses the "compatibility" mode by default, this means that it uses WiFiUdp class instead of AsyncUDP.
// The later requires the Arduino Core for ESP8266 staging version whilst the former works fine with current stable 2.3.0 version. But,
// since it's not "async" anymore we have to manually poll for UDP packets.
fauxmo.handle();
static unsigned long last = millis();
if (millis() - last > 5000) {
last = millis();
Serial.printf("[MAIN] Free heap: %d bytes\n", ESP.getFreeHeap());
}
}
from fauxmoesp.
Related Issues (20)
- Status of element
- ESP32 Device fails to be recognised after a while
- double action with Alexa HOT 1
- how to setDeviceUniqueId with an example HOT 3
- I ported fauxmoESP for Raspberry Pi Pico W HOT 1
- 'class fauxmoESP' has no member named 'onGetState' HOT 15
- Not all devices respond any more HOT 1
- Alexa drops FauxmoESP after some time HOT 6
- setDeviceUniqueId only sets first 12 characters of uniqueId HOT 4
- How can use this lib to control the device colors? HOT 1
- Infrequent crashes caused by a bug HOT 3
- Disable fauxmo does not disable internal web server
- Device not found by Alexa with release 3.4.0
- Strange behavior with command HOT 4
- Allow devices to show up as a smart plug.
- Echo Dot 3 doesn't detect device.
- Where best to feed a watchdog?
- [Feature Request] Transition back to Wemo to support more devices
- How To use fauxmo.setState HOT 1
- AsyncServer is not stopped even when Fauxmo is disabled
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 fauxmoesp.