Comments (10)
Original comment by Don Slattery (Bitbucket: donslattery, GitHub: donslattery).
It looks like the editor trashed my pound signs. You'll have to pretend they're there for the purposes of reading the code and add them back to execute.
from fauxmoesp.
Original comment by Don Slattery (Bitbucket: donslattery, GitHub: donslattery).
Thanks for the help with formatting. I've not posted before.
from fauxmoesp.
Original comment by Xose Pérez (Bitbucket: [Xose Pérez](https://bitbucket.org/Xose Pérez), ).
Hi
I would use SyncClient instead since fauxmoESP is built on top of ESPAsyncTCP library (example here: https://github.com/me-no-dev/ESPAsyncTCP/blob/master/examples/SyncClient/SyncClient.ino)
Also: instead of calling test() in the fauxmo callback, set a volatile flag there and check it in your main loop. This way you return quickly from the callback.
from fauxmoesp.
Original comment by Don Slattery (Bitbucket: donslattery, GitHub: donslattery).
I’ll give that a try and see what happens. Thanks for your help. Thanks for the performance suggestion, also.
from fauxmoesp.
Original comment by Don Slattery (Bitbucket: donslattery, GitHub: donslattery).
Not a bug
from fauxmoesp.
Original comment by Don Slattery (Bitbucket: donslattery, GitHub: donslattery).
Using SyncClient solved the problem. Thank you!
from fauxmoesp.
Original comment by Zak Malone (Bitbucket: zmalone, GitHub: zmalone).
I couldn't get this working with SyncClient. Don, can you post an example of your working code?
from fauxmoesp.
Original comment by Zak Malone (Bitbucket: zmalone, GitHub: zmalone).
Never mind. Got it working with WiFiClient using Xose Pérez's tip to do this outside of the fauxmo callback. Here's my working example of using the ESP8266 as a proxy to my real WEMO.
#!arduino
#include <ESP8266WiFi.h>
#include "fauxmoESP.h"
#include "credentials.h"
#define SERIAL_BAUDRATE 115200
#define FAUXMO_DEVICE "proxy"
#define WEMO_HOST "Belkin-WEMO-127"
#define WEMO_PORT 49153
#define WEMO_COMMAND_FORMAT "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" "\
"s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"\
"<s:Body><u:SetBinaryState xmlns:u=\"urn:Belkin:service:basicevent:1\">"\
"<BinaryState>%d</BinaryState></u:SetBinaryState></s:Body></s:Envelope>"
bool do_wemo_state_change = false;
int wemo_state = 0;
WiFiClient client;
fauxmoESP fauxmo;
void wifiSetup() {
WiFi.mode(WIFI_STA);
Serial.println("[WIFI] STATION Mode");
Serial.printf("[WIFI] Connecting to %s ", WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.printf("[WIFI] Connected. SSID: %s, IP address: %s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());
}
void setup() {
Serial.begin(SERIAL_BAUDRATE);
Serial.println();
Serial.println();
wifiSetup();
fauxmo.addDevice(FAUXMO_DEVICE);
Serial.printf("[FAUXMO] %s Device registered.\n", FAUXMO_DEVICE);
fauxmo.onMessage([](unsigned char device_id, const char * device_name, bool state) {
wemo_state = state ? 1 : 0;
do_wemo_state_change = true;
});
}
void wemo_state_change(){
Serial.printf("\n[WEMO] Starting connection to WEMO host: %s...", WEMO_HOST);
if( client.connect(WEMO_HOST, WEMO_PORT) ) {
Serial.println("\n[WEMO] Connected.");
// Set up SOAP command
char wemo_command[300];
int wemo_command_length = sprintf(wemo_command, WEMO_COMMAND_FORMAT, wemo_state);
// This will send the request to the server
client.setTimeout(2);
client.println("POST /upnp/control/basicevent1 HTTP/1.1");
client.println("Host: " + String(WEMO_HOST) + ":" + String(WEMO_PORT));
client.println("User-Agent: ESP8266/1.0");
client.println("Connection: close");
client.println("Content-type: text/xml; charset=\"utf-8\"");
client.print("Content-Length: ");
client.println(wemo_command_length);
client.println("SOAPACTION: \"urn:Belkin:service:basicevent:1#SetBinaryState\"");
client.println();
client.println(wemo_command);
while(client.connected() && client.available() == 0){
delay(1);
}
// Read all the lines of the reply from server and print them to Serial
while(client.available()){
String line = client.readStringUntil('\n');
Serial.print("[WEMO] - ");
Serial.println(line);
}
if (client.connected()) {
Serial.println("[WEMO] Closing connection");
client.stop();
}
}
else {
Serial.println("\n[WEMO] Connection unsuccessful.");
}
}
void loop() {
fauxmo.handle();
if (do_wemo_state_change) {
wemo_state_change();
do_wemo_state_change=false;
}
}
from fauxmoesp.
Original comment by Zak Malone (Bitbucket: zmalone, GitHub: zmalone).
Hi Don -
Thanks! Sorry, I didn't see this reply until after I'd posted my followup with code on the issues thread. I think we both got to the same place to get around the issue, though -- moving the code outside the callback function.
from fauxmoesp.
Original comment by Xose Pérez (Bitbucket: [Xose Pérez](https://bitbucket.org/Xose Pérez), ).
In general it's a good practice to keep your callbacks and interrupt methods as slim as possible...
Closing
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.