esp8266 with fauxmo, irremote, and remote debug

I am using arduino IDE 1.8.11, with esp8266 core 2.6.3, IrRemoteESP8266 v2.7.2, fauxmo v3.1.0, remotedebug by joao lopes v3.05 - he also codded remotedebugger, but the library I am using is remotedebug. Other libs are arduinojson v6.13.0, asyncTCP 1.2.2, asyncwebserver v1.2.3, esp8266wifi v1, dnsServer v1.1.1, and ESP8266mDNS v1.2.
I can get Alexa to detect up to 2, or sometimes 3 devices, but thats it. If i add more or even remove the previous - "fauxmo.addDevice ***" commands, there is still no further detection untill I actually remove the devices from the echo dot revision3. It will work with my first three devices even if I remove the addDevice from code ... as they have already been detected so I can control our T.V. on off, and two other remote devices, via an ir led connected to the esp8266, via a transistor, but I want to add much more functionality, and as its awkward to connect back to serial, and I have webupdates working I added remotedebug to try debug fauxmo, but have tried changing many things in the fauxomo.h file and cpp file, using the Debug command that remote debug uses, also trying #define DEBUG_FAUXMO      telnet and #define DEBUG_FAUXMO      Serial1 etc but mainly with compile errors.
I can access the esp with putty and get the timestamps from remotedebug but no fauxmo debug. Any help or pointers immensely appreciated.
I will post the code I am using in post #1 and #2, because it will exceed allowed newbie chars otherwise. Thanks in advance hope I have given enough info.
And grief to Zoomkat sorry missunderstood your post#3. Hope it is more readable now. I don't mind criticism when I can understand it LOL.

#define DEBUG_FAUXMO_VERBOSE_TCP
#define DEBUG_FAUXMO_VERBOSE_UDP

//#define DEBUG_FAUXMO                Serial
#define DEBUG_FAUXMO                  Telnet

#define DEBUG_FAUXMO = true
#define DEBUG_FAUXMO   Debug
#define HOST_NAME "TV_Remote"
#if defined ESP8266 || defined ESP32

#define USE_MDNS true

#if defined ESP8266

// Includes of ESP8266

#include <ESP8266WiFi.h>

#ifdef USE_MDNS
#include <DNSServer.h>
#include <ESP8266mDNS.h>
#endif

#elif defined ESP32

// Includes of ESP32

#include <WiFi.h>

#ifdef USE_MDNS
#include <DNSServer.h>
#include "ESPmDNS.h"
#endif

#endif // ESP

// Remote debug over WiFi - not recommended for production, only for development

#include "RemoteDebug.h" 

RemoteDebug Debug;
// everything above added for debug but commented out repeat includes below
#include <Arduino.h>
//#include <DNSServer.h>
//#include <ESP8266mDNS.h>
#include <WiFiClient.h>
#include <ESPAsyncWebServer.h>
#include <ESPAsyncTCP.h>
#include "Updater.h"
#include <FS.h>
//#include <SPIFFSEditor.h>
#include <ArduinoJson.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
//#include ESPAsyncUDP.h
#include <fauxmoESP.h>

// define functions
// these two lines for debug
uint32_t mLastTime = 0;
uint32_t mTimeSeconds = 0;

//int callbackSet(unsigned char, const char, bool, unsigned char);
unsigned long startTime = millis();


const int port = 23;

const char* update_path = "/firmware";
const char* update_username = "admin";
const char* update_password = "admin";

// replace the ssid and password
const char* ssid     = "--------------";
const char* password = "***********";


// replace staticIP and gateway address based on your home router settings
IPAddress staticIP(192, 168, 1, 132);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);



bool restartRequired = false;

String request;
DynamicJsonDocument doc(200);
AsyncWebServer server(80);
//static char sensorStatus[50];
bool Mute=0;

byte SEND_PIN = 14;
IRsend irsend(SEND_PIN);
unsigned long infraRedCode[] = {
 0x1FE05FA, //set-top 0
 0x1FE857A, //set-top 1
 0x1FE45BA, //set-top 2
 0x1FEC53A, //set-top 3
 0x1FE25DA, //set-top 4
 0x1FEA55A, //set-top 5
 0x1FE659A, //set-top 6
 0x1FEE51A, //set-top 7 
 0x1FE15EA, //set-top 8
 0x1FE956A, //set-top 9
 0x1FE9D62, //set-top info
 0x1FE2BD4, //set-top volume up
 0x1FE6B94, //set-top channel up
 0x1FE8D72, //set-top mute
 0x1FEEB14, //set-top volume down
 0x1FE9B64, //set-top channel down
 0x1FE4DB2,  //set-top on-off
 0x20DF10EF, //tv on-off
 0x20DFD02F, //tv source
 0xFF00FF,   //candle on
 0xFF40BF,   //candle off
 
};

fauxmoESP fauxmo;

       unsigned long preMs = 0;     // will store last time LED was updated
       long OnTime = 40;           // milliseconds of on-time
       long OffTime = 4960;          // milliseconds of off-time
       
       
       bool SetTopBBC1State;
       bool SetTopBBC2State;
       bool SetTopBBC3State;
       bool SetTopBBC4State;
       bool TvPowerState;
       bool candleState;
       //bool lastCandleState;
       bool lastTvPowerState;
       bool SetTopBoxState;
       bool lastSetTopBoxState;
       bool SatBoxVolumeUP;
       int  value = 0;


const int pin2 = 2;
bool pin2State;
const int pin14 = 14;
bool pin14State;


void connectToWiFi()
{ 
  WiFi.disconnect();
  if (WiFi.getMode() != WIFI_STA) {WiFi.mode(WIFI_AP_STA);}

 WiFi.config(staticIP, gateway, subnet);
 WiFi.begin(ssid, password);

 unsigned long startTime = millis();
 while (WiFi.status() != WL_CONNECTED && millis() - startTime < 10000)
   { 
     delay(100); 
     rdebugV("."); 
   } 
 rdebugVln("");
rdebugVln(WiFi.localIP());}
 }    
void serverSetup() 
{

    server.on("/",HTTP_GET,[](AsyncWebServerRequest *request) 
      {
        request->send(SPIFFS,"/index.html","text/html");
      }); 
      
      server.on("/index.html",HTTP_GET,[](AsyncWebServerRequest *request) 
      {
        request->send(SPIFFS,"/index.html","text/html");
      }); 
       
   // send updatepage if requested
    server.on("/update.html",HTTP_GET,[](AsyncWebServerRequest *request) 
      {
        request->send(SPIFFS,"/update.html","text/html");
      });    

    server.on("/tv_remote.html",HTTP_GET,[](AsyncWebServerRequest *request) 
      {
        request->send(SPIFFS,"/tv_remote.html","text/html");
      }); 
    
    
   server.on("/updatefirmware", HTTP_POST, [](AsyncWebServerRequest *request){
   AsyncWebServerResponse *response = request->beginResponse(200, "text/plain", (Update.hasError())?"FAIL":"OK");
   response->addHeader("Connection", "close");
   response->addHeader("Access-Control-Allow-Origin", "*");
   restartRequired = true;  
   request->send(response);
 },[](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){
 
   if(!index){ // if index == 0 then this is the first frame of data
     Debug.printf("UploadStart: %s\n", filename.c_str());
  
     uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
     if(!Update.begin(maxSketchSpace)){
       Update.printError(Debug);
     }
     Update.runAsync(true);
   }

 
   if(Update.write(data, len) != len){
       Update.printError(Debug);
   }
   
   if(final){ // if the final flag is set then this is the last frame of data
     if(Update.end(true)){ //true to set the size to the current progress
         Debug.printf("Update Success: %u B\nRebooting...\n", index+len);
         rdebugVln("Update Success");
       } else {
         Update.printError(Debug);
       }

       request->send(SPIFFS,"/update.html","text/html");
   }
 });

   server.onRequestBody([](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) {
       if (fauxmo.process(request->client(), request->method() == HTTP_GET, request->url(), String((char *)data))) return;
   
   });
   
   server.onNotFound([](AsyncWebServerRequest *request) {
       String body = (request->hasParam("body", true)) ? request->getParam("body", true)->value() : String();
       if (fauxmo.process(request->client(), request->method() == HTTP_GET, request->url(), body)) return;

   });

    
   // Start the server
   server.begin();


}



void onRequest(AsyncWebServerRequest *request) 
{
   // dummy callback
}

void onFileUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, size_t len, bool final) 
{
   // dummy callback
}

int callBackSet(unsigned char device_id, const char * device_name, bool state, unsigned char value)
{

   switch(device_id)
     {
       case 0:
        {
         candle(state);
         break;
        }
       
       case 1:
        {
         TvOnOff();
         break;
        }
       case 2:
        {
         SatOnOff();
         break;
        }
       case 3: 
        {
         SatBoxVol(value);
         break;
        }
       case 4:
        {
         SatBoxVol(0-value);
         break;
        }
       case 5:
        {
         Mute=1;
         break;
        }

     }
       
       Debug.printf("[MAIN] Device #%d (%s) state: %s value: %d\n", device_id, device_name, state ? "ON" : "OFF", value);
}


void candle(bool candleState)  
 {  
   if(candleState == 1)
     {
      irsend.sendNEC(0xFF00FF, 32);
      delay(60);
      irsend.sendNEC(0xFF00FF, 32);
     }
   else if(candleState == 0)
     {
      irsend.sendNEC(0xFF40BF, 32);
      delay(60);
      irsend.sendNEC(0xFF40BF, 32);
     }
 }

void TvOnOff()
 {
  irsend.sendNEC(0x20DF10EF, 32);
 }  

void SatOnOff()
 {
   irsend.sendNEC(0x1FE4DB2, 32);
 }

void SatBoxVol(int vol)
 {
   if (vol>0)
    {
      while (vol>0)
      { 
        irsend.sendNEC(0x1FE2BD4, 32);
        vol-=1;
        delay(20);
      }
    }

   if (vol<0)
    { 
     while (vol < 0)
     {
       irsend.sendNEC(0x1FEEB14, 32);
       vol+=1;
       delay(20);
     }
    }
 
 }
void SatBoxMute()
 {
   irsend.sendNEC(0x1FE8D72, 32);
   Mute = 0;
 }
void setup() 
{
 
  connectToWiFi();
  
  serverSetup();
    String hostNameWifi = HOST_NAME;
    hostNameWifi.concat(".local");

#ifdef ESP8266 // Only for it
    WiFi.hostname(hostNameWifi);
#endif

#ifdef USE_MDNS  // Use the MDNS ?

    if (MDNS.begin(HOST_NAME)) {
        rdebugV("* MDNS responder started. Hostname -> ");
        rdebugVln(HOST_NAME);
    }

    MDNS.addService("telnet", "tcp", 23);

#endif

  Debug.begin(HOST_NAME);

  Debug.setResetCmdEnabled(true);

  Debug.showProfiler(true);
  Debug.showColors(true);

  if(!SPIFFS.begin())
  {
  Serial.println("An Error has occurred while mounting SPIFFS");
  return;
  }

  pinMode(pin2, OUTPUT);
  digitalWrite (pin2,LOW);
  pinMode(pin14, OUTPUT);
  digitalWrite (pin14,LOW);
    fauxmo.addDevice("Candles");
    fauxmo.addDevice("Our TV");
    fauxmo.addDevice("Our SatBox");
    fauxmo.addDevice("Volume UP");
    fauxmo.addDevice("Volume Down");
    fauxmo.addDevice("SatBox Mute");
    fauxmo.createServer(false);
    fauxmo.setPort(80); // required for gen3 devices
    
    
    fauxmo.enable(true);
  
    fauxmo.onSetState(callBackSet);
   

}

void loop()
{

    if ((millis() - mLastTime) >= 1000) {

        mLastTime = millis();

        mTimeSeconds++;

        debugV("* Time: %u seconds (VERBOSE)", mTimeSeconds);

        if (mTimeSeconds % 5 == 0) { // Each 5 seconds

            // Debug levels

      //debugV("* This is a message of debug level VERBOSE");

    //Debug.handle();
    Debug.handle();

    // Give a time for ESP

    yield();
    
   
  unsigned long ms = millis();
    
    if ((pin2State == LOW) && (ms - preMs >= OnTime))  
    {
      pin2State = HIGH;
      preMs = ms;
      digitalWrite(pin2,pin2State);        
    }
       else if ((pin2State == HIGH) && (ms - preMs >= OffTime))
    {   
       pin2State = LOW;  
       preMs = ms;
       digitalWrite(pin2,pin2State);  
    }  
      
   if(Mute == 1) SatBoxMute;

   if (restartRequired)
    {  // check the flag here to determine if a restart is required
    Debug.printf("Restarting ESP\n\r");
    restartRequired = false;
    ESP.restart();
    }
   
   fauxmo.handle();
   
}

I had to send code in two lots as it still exceeded my limit so this is setup and loop the rest was before setup. I also had to remove a lot of comments hopefully none of the code the lines were overlaping. I am also trying to get a webpage based spiffs browser working so i can view delete and upload webpages to spiffs the webpage based firmware update works fine without arduinoOta but i cant do the same with spiffs browse the examples in asynwebserver use <ArduinoOTA.h> but I don’t want to use that besides i want the page to access the browser to be in spiffs not in sketch I have searched everywhere and tried using various bits of code but after days found no avail but my main problem is getting Alexa to be more accomodating than 3 devices and remotedebug seems like next step. My esp is already setup in tv room and computer with ide and everything is upstairs so being as remote debug is partly working just not debugging fauxmo i am trying to continue that root.

"Any help or pointers greatly appreciated "

You really need to learn to code some “punctuation” in the stuff you are writing if you want it to be readable.

zoomkat:
"Any help or pointers greatly appreciated "

You really need to learn to code some "punctuation" in the stuff you are writing if you want it to be readable.

I had 2 delete spaces comments and any character that was not needed to reduce the code to within the allowed limit i could email you the original code if you are not happy with what i had to do to keep within my quota

Tronicycle:
I had to send code in two lots as it still exceeded my limit so this is setup and loop the rest was before setup. I also had to remove a lot of comments hopefully none of the code the lines were overlaping.

!!!!!!!!!!!!!!!!!!! So what else do you mean by punctuation? void!{!}!?

Maybe you are being helpful in making me write more stuff so i can get my quota limit removed and put the full code in its not easy for newbies with comments like that from long time members that don't read the text to understand why the code has been stripped! oops sorry another punctuation mark against me!
After removing tones of // comments and /* */ stuff i was still over my allowed amount so i started taking out spaces and in the end had to split the code in half you dont have that limitation and have probably forgot it exists for newbies well I am reminding you so you dont chase all the newbies away!

Tronicycle:
!!!!!!!!!!!!!!!!!!! So what else do you mean by punctuation? void!{!}!?

He means your English. It is difficult and takes a lot of effort trying to read a chunk of text, without proper paragraphing and punctuation. It makes it hard for people to help you, just trying to read what you are trying to say.

Oh right, I can understand that. He said "learn to code some punctuation" I thought he was refering to code. My punctuation has always been awfull even though I am married to an english teacher.(That was a late attempt to improve, oh well.) I did Put paragraphs in my first post with a few more full stops and commas then lost the lot by clicking the back arrow after going to preview and lost patience so started writing how I normally do, my wrong! I normally try to do better in forums. I spend lots of time getting frustrated and it reflects badly my appologies. I will try to edit it. Now that its there, I should find it more difficult to lose it all again. Or even just lose it lol. Thanks for clarifying that! @Byork!

Tronicycle:
Oh right, I can understand that. He said “learn to code some punctuation” I thought he was refering to code. My punctuation has always been awfull even though I am married to an english teacher.(That was a late attempt to improve, oh well.) I did Put paragraphs in my first post with a few more full stops and commas then lost the lot by clicking the back arrow after going to preview and lost patience so started writing how I normally do, my wrong! I normally try to do better in forums. I spend lots of time getting frustrated and it reflects badly my appologies. I will try to edit it. Now that its there, I should find it more difficult to lose it all again. Or even just lose it lol. Thanks for clarifying that! @Byork!

No sweat, hopefully you will find the help you need.

Thank you Byork, I do like the precision you get from a BallScrew but its easy to screw up when your not on the ball!
Here's to greater precision and greater things. :wink:

I have managed to get alexa to find nearly 20 devices by removing all other libraries but even this does not always work. Once devices are found other libs and code can be added to have full functionality but this is not ideal. Is anyone able to figure whats going on with fauxmo serial debug report if so i can post this.

So after reading this "To program Alexa skills, you can use any programming language. However, there is one language that experienced Alexa developers prefer. The preferred language of choice is JavaScript. Most popularly, JavaScript is used in conjunction with Node." I have decided to create an alexa skill in an attemp to get round what ever the problem is, So in conclusion if you are experiencing problems with Alexa echo version 3 recognising your esp8266 devices, building a skill might be the way to go.

For anyone that stumbles on this, I could not get Alexa to work happily with more than a few devices per esp8266 so the way to go for multiple devices seems to be using an api on an external website or http server. Alexa immediatly finds all devices (with correct programming) but a lot of work if your not good with multiple languages, just like what im not, especially english my primary language. I would have liked an easier way but feel quite convinced there is not a good alternative for lots of devices with one esp8266. I have worked for Amazon and it was the same then. If you want to be more than a customer prepare for hard work. Plenty to be busy with during a lock down though :wink: