vintlabs / fauxmoESP

Add voice control of your ESP32 and ESP8266 devices using Amazon Alexa
MIT License
389 stars 71 forks source link

fauxmoESP appears to affect ESP8266HTTPClient #18

Closed pvint closed 5 years ago

pvint commented 7 years ago

Original report by Brendan Sleight (Bitbucket: bmsleight, GitHub: bmsleight).


With fauxmoESP enabled I get [HTTP] GET... failed, error: connection refused, without fauxmoESP I have no errors.

Example:-

#!arduino

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include "credentials.h"
#include "fauxmoESP.h"

#define SERIAL_BAUDRATE 9600
#define LED             2
#define FAUXMO          true

#if FAUXMO == true
  fauxmoESP fauxmo;
#endif  

void wifiSetup() {
  WiFi.mode(WIFI_STA);
  Serial.printf("[WIFI] Connecting to %s ", WIFI_SSID);
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(100);
  }
  Serial.println();
  Serial.printf("[WIFI] STATION Mode, SSID: %s, IP address: %s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());

}

void simpleHttp(String surl = "http://tinyurl.com") {
  Serial.println(surl);
  HTTPClient http;
  http.begin(surl);
  int httpCode = http.GET();
  http.end(); 
  if(httpCode > 0) {
    Serial.printf("[HTTP] GET... code: %d\n", httpCode);
  }
  else 
  {
    Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
  }
}

void setup() {
  Serial.begin(SERIAL_BAUDRATE);
  Serial.println();
  wifiSetup();
  // LED
  pinMode(LED, OUTPUT);
  digitalWrite(LED, LOW);

  // Fauxmo
  #if FAUXMO == true
    // Fauxmo
    Serial.println("FAUXMO == true setting up fauxmo");
    fauxmo.addDevice("light one");
    fauxmo.addDevice("light two");
    fauxmo.addDevice("light three");
    fauxmo.addDevice("light four");
    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");
        digitalWrite(LED, !state);
    });
  #endif   
}

void loop() {
  simpleHttp();
  delay(5000);
  Serial.printf("[MAIN] Free heap: %d bytes\n", ESP.getFreeHeap());
}

Output where #define FAUXMO true

#!none

[WIFI] Connecting to huntik-bg ..................
[WIFI] STATION Mode, SSID: huntik-bg, IP address: 192.168.1.186
FAUXMO == true setting up fauxmo
http://tinyurl.com
[HTTP] GET... code: 400
[MAIN] Free heap: 40216 bytes
http://tinyurl.com
[HTTP] GET... code: 400
[MAIN] Free heap: 40216 bytes
http://tinyurl.com
[HTTP] GET... code: 400
[MAIN] Free heap: 40144 bytes
http://tinyurl.com
[HTTP] GET... failed, error: connection refused
[MAIN] Free heap: 40144 bytes
http://tinyurl.com
[HTTP] GET... failed, error: connection refused
[MAIN] Free heap: 40144 bytes
http://tinyurl.com
[HTTP] GET... failed, error: connection refused
[MAIN] Free heap: 40144 bytes
http://tinyurl.com
[HTTP] GET... failed, error: connection refused
[MAIN] Free heap: 40144 bytes
http://tinyurl.com
[HTTP] GET... failed, error: connection refused
[MAIN] Free heap: 40144 bytes
http://tinyurl.com
[HTTP] GET... failed, error: connection refused

Output where #define FAUXMO false

#!None

[WIFI] Connecting to huntik-bg ........
[WIFI] STATION Mode, SSID: huntik-bg, IP address: 192.168.1.186
http://tinyurl.com
[HTTP] GET... code: 400
[MAIN] Free heap: 45936 bytes
http://tinyurl.com
[HTTP] GET... code: 400
[MAIN] Free heap: 45752 bytes
http://tinyurl.com
[HTTP] GET... code: 400
[MAIN] Free heap: 45752 bytes
http://tinyurl.com
[HTTP] GET... code: 400
[MAIN] Free heap: 45568 bytes
http://tinyurl.com
[HTTP] GET... code: 400
[MAIN] Free heap: 45568 bytes
http://tinyurl.com
[HTTP] GET... code: 400
[MAIN] Free heap: 45568 bytes
http://tinyurl.com
[HTTP] GET... code: 400
[MAIN] Free heap: 45568 bytes
http://tinyurl.com
[HTTP] GET... code: 400
[MAIN] Free heap: 45568 bytes
http://tinyurl.com
[HTTP] GET... code: 400
[MAIN] Free heap: 45568 bytes
http://tinyurl.com
[HTTP] GET... code: 400

What I am doing wrong ?

pvint commented 6 years ago

Original comment by sijun1983 (Bitbucket: sijun1983, ).


Got the same problem.

With

#!arduino

#include <ESP8266WiFi.h>
//#include "fauxmoESP.h"
#include <ESP8266HTTPClient.h>

String payload = http2.getString();   
Serial.println(payload);

works, with the fauxmoESP.h enabled and used, it doesnt. :( Any ideas?

pvint commented 5 years ago

Original comment by Xose Pérez (Bitbucket: [Xose Pérez](https://bitbucket.org/Xose Pérez), ).


This would probably mean there is an incompatibility between the ESP8266HTTPClient library and the AsyncTCP library fauxmoESP uses. Anyway, I would suggest to use an AsyncClient instead, is more reliable and your code will be lighter (https://github.com/me-no-dev/AsyncTCP).