Implementation of the received infrared code possible?


would it be possible to transmit the received HEX codes via MQTT (my preferred way) or to provide them via the JSON-API ?

I like the way you think.
Maybe on the info page, if IR enabled, display last IR code received.
That might not be what you are after, but a custom usermod would certainly do what you are looking for.
I think if WLED were able to send say the last 10-16 IR codes in a single JSON-api request, you could push that many IR remote buttons and capture all the button codes in a single call. Then in a different API call, send just the last IR code received, or trigger an MQTT send for each IR code received.

If you want to build a usermod, if it is straightforward, @Aircoookie might merge it into WLED for everyone. If not, you’d still have your own problem solved.

I found this suggestion to expand the ir.cpp.

  char s[16];
  char subuf[38];

  strcpy(subuf, mqttDeviceTopic);
  strcat(subuf, "/ircode");
  mqtt->publish(subuf, 0, true, s);


If I now want to build the firmware myself, I get this message:

In file included from C:\Users\bla\WLED-master\WLED-master\wled00\wled.h:99,
from C:\Users\bla\WLED-master\WLED-master\wled00\wled00.ino:13:
C:\Users\bla\WLED-master\WLED-master\wled00\src\dependencies\espalexa\Espalexa.h:620:2: error: #endif without #if
620 | #endif
| ^~~~~

What and where do I have to change at Espalexa.h ?

I’ve been thinking about a better way to get the ir codes. Especially since the next release should allow the users to add support for most any remote without any coding or compiling. But you need to be able to get the IR codes in order to do that.

The codes are currently echoed on the serial port. Beginning in 0.13 it will be debug prints instead. Not hard for developers, but not easy for most users. Having the last 10 or 15 codes received in the JSON response is probably overly optimistic for being able to piece back together and map your buttons. Speaking as someone who has spent a fair amount of time mapping codes to buttons.

Using mqtt isn’t a bad idea, but still leaves the bar a little higher than I’d like.

I don’t want to use the IR codes to switch the LEDs, I want to be able to switch any device (in FHEM).
In practice, I just want to save myself an additional, for example, Tasmota device or something else.
And MQTT would be my preferred way of getting the codes.


I have now managed to compile myself, to expand the ir.cpp with the suggestion I found (see above).
Unfortunately, the reception of the IR codes does not work.
Nothing happens in the serial monitor.
I checked the TSOP used with the IRrecvDumpV2-Sketch for functionality, it receives the codes from my remote control without any problems.
In the ir.cpp I read that you can change the pin in the NpbWrapper.h.
Where is this file, can’t find it?

Newer versions don’t echo codes to serial and use debug instead.

I now have #define WLED_DEBUG
added at the top of the WLED.cpp.

Now I have --- DEBUG INFO --- output in the serial monitor, but I still don’t see any received codes.

Regardless of whether there are debug outputs or not, no codes with the proposed extension are transmitted via MQTT
Incidentally, I added the following to ir.cpp:

void decodeIR(uint32_t code)
  char s[16];
  char subuf[38];

  strcpy(subuf, mqttDeviceTopic);
  strcat(subuf, "/ircode");
  mqtt->publish(subuf, 0, true, s);
  if (code == 0xFFFFFFFF) //repeated code, continue brightness up/down
  lastValidCode = 0; irTimesRepeated = 0;
  if (decodeIRCustom(code)) return;
  if      (code > 0xFFFFFF) return; //invalid code
  else if (code > 0xF70000 && code < 0xF80000) decodeIR24(code); //is in 24-key remote range
  else if (code > 0xFF0000) {
    switch (irEnabled) {
      case 1: decodeIR24OLD(code); break;  // white 24-key remote (old) - it sends 0xFF0000 values
      case 2: decodeIR24CT(code);  break;  // white 24-key remote with CW, WW, CT+ and CT- keys
      case 3: decodeIR40(code);    break;  // blue  40-key remote with 25%, 50%, 75% and 100% keys
      case 4: decodeIR44(code);    break;  // white 44-key remote with color-up/down keys and DIY1 to 6 keys 
      case 5: decodeIR21(code);    break;  // white 21-key remote  
      case 6: decodeIR6(code);     break;  // black 6-key learning remote defaults: "CH" controls brightness,
                                           // "VOL +" controls effect, "VOL -" controls colour/palette, "MUTE" 
                                           // sets bright plain white
      case 7: decodeIR9(code);    break;
      default: return;
  if (nightlightActive && bri == 0) nightlightActive = false;
  colorUpdated(NOTIFIER_CALL_MODE_BUTTON); //for notifier, IR is considered a button input
  //code <= 0xF70000 also invalid

And where i can find the NpbWrapper.h File, i can’t find it ?

IRrecv* irrecv;//change pin in NpbWrapper.h

I have now solved that with exactly the extension linked above that I made in ir.cpp.

The file NpbWrapper.h probably no longer exists because you can now set the IR pin in the settings and this is set to -1 by default and not defined.

To ensure that the IR codes are also transmitted via MQTT, any FB must be selected under Sync Interfaces / Sync setup / Button setup / Infrared Remote.

Now I am happy :slight_smile:

1 Like