Combining IR Remote + Web Server

Hello All, trying to make a little device that I can make voice commands to using Alexa to have some basic TV control.

I am using a Weemos D1 Mini.

The 2 main parts of the project are the IR Transmitting and Web Server.

The IR was fairly easy. Have a receiver I can use to record the codes, duplicate them in the transmitter sketch, and everything works fine.

I am using a web server that responds to GET requests from IFTTT. I’ve tried a couple different ones, at the moment I am using the ESP Async Web Server, as I thought the normal one might be interfering with my OTA programming.

Each of those works fine on their own. I can set up a couple of delays with different IR Commands, and it will do them fine.
I can have the web server write out to serial when the correct IFTTT command is triggered.

However, when I put them both together, it will work once or twice and then just stop working. The OTA Programming also stops responding.

I’m guessing something is interacting with something else in a weird way but i’m not sure what it is.

Below is a copy of my sketch.

Any assistance would be appreciated.

Thank you.

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>

#ifndef STASSID
#define STASSID "SSID"
#define STAPSK  "PASSWORD"
#endif

#include <IRremoteESP8266.h>
#include <IRsend.h>

#define REQ_BUF_SZ   60

const char* ssid = STASSID;
const char* password = STAPSK;

#define LED                             2

AsyncWebServer server(80);

const uint16_t kIrLed = 4;  // ESP8266 GPIO pin to use. Recommended: 4 (D2).

IRsend irsend(kIrLed);  // Set the GPIO to be used to sending the message.

unsigned long int Power = 0x0020DF10EF;
unsigned long int Netflix = 0x0020DF6A95;
unsigned long int VolUp = 0x0020DF40BF;
unsigned long int VolDn = 0x0020DFC03F;
unsigned long int Mute = 0x0020DF906F;


void setup() {

    pinMode(LED, OUTPUT);
    digitalWrite(LED, LOW);
  
  Serial.begin(115200);
  delay(500);
  Serial.println("Booting");
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("Connection Failed! Rebooting...");
    delay(5000);
    ESP.restart();
  }

  // Hostname defaults to esp8266-[ChipID]
  ArduinoOTA.setHostname("IRController");

  ArduinoOTA.onStart([]() {
    String type;
    if (ArduinoOTA.getCommand() == U_FLASH) {
      type = "sketch";
    } else { // U_SPIFFS
      type = "filesystem";
    }

    // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
    Serial.println("Start updating " + type);
  });
  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();
  Serial.println("Ready");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  delay(500);

  digitalWrite(LED, HIGH);

    server.on("/Netflix", HTTP_GET, [](AsyncWebServerRequest *request){
        request->send(200, "text/plain", "Netflix");
        Serial.println("Netflix");
        irsend.sendNEC(Netflix);
    });

server.begin();

}


void loop() {
  ArduinoOTA.handle();

}

I’m missing the link to your web server library!

This is Async Web Server Library I am using here

https://github.com/me-no-dev/ESPAsyncWebServer

but as I said, I also used the normal Etherclient one and had the same issues.

Please post the serial output you get.

Have you tried to remove the OTA functionality? Does it work then?

Thanks for your reply.

I get the normal serial output that shows in my sketch (eg, Booting, connected, the IP Address) and when it works I get the "Netflix" output as scripted.

When it doesn't work, it simply does nothing. No IR transmission (watching it through the camera in my phone) and no Serial Output at all.

I haven't tried without the OTA part of it. I will give that a go.

I've been thinking, I remember reading about the built in timers of the Arduino's and how certain Libraries are problematic to use together cause they use the same timer. Eg, Servo Library. Could that be what is happening? I don't actually know about what timers the D1 Mini has.

I've been thinking, I remember reading about the built in timers of the Arduino's and how certain Libraries are problematic to use together cause they use the same timer. Eg, Servo Library.

That's true for some combinations but you don't have an Arduino. The Wemos is an Espressif board that just uses the Arduino IDE. So above statement doesn't apply to your board.

When it doesn't work, it simply does nothing. No IR transmission (watching it through the camera in my phone) and no Serial Output at all.

Does that mean in these cases you don't even see the startup output?

To get back to a working state do you just have to resend the web request or do you have to reset your Wemos?

It will start working as normal, but after a couple of web requests or a small amount of time (eg, 2 mins) it seems to just stop working. No more IR sending or serial writing and no OTA programming.

It always booted up fine and worked once or twice.

To get it working (either, accepting requests or to do an OTA program) I needed to restart it.

Last night I removed the OTA code from the sketch and it seems to be stable. Been ~20 hours and it seems to still work. The web requests (from the browser end) seem to respond quicker too.

Any idea what I can do to make the OTA work with this? It's not the end of the world, but would be nice to use the OTA feature.

Any idea what I can do to make the OTA work with this?

Actually no. Are you sure your ESP8266 core is up-to-date (version 2.5.0)? The OTA code is rather complex and includes mDNS functionality. It might be even a problem if you leave the Arduino IDE open while sending the web requests.

Post the output of such a session, that gives a hint what the last command was that the sketch actually processed correctly. I’d then sniff the network for all traffic going to or coming from the ESP to get additional hints what might be going on.

To be honest, I have never updated any of my ESP8266's that I've played with.

I'll have a look into that.

Also didn't think about the Arduino IDE interfering, but it does make sense.

I'll check out both of those.

Thanks again for your help!