logo elektroda
logo elektroda
X
logo elektroda

Openbeken /w IRSend for denon seems to be sending incorrect output

ErrorGap 1269 5
ADVERTISEMENT
  • Helpful post
    #1 20932660
    ErrorGap
    Level 5  
    I've picked up a couple Tuya IRC03's which serve as both infrared receiver and transmitter.

    My intent was to send signals for a Denon Stereo so that it can be woken up and switched to the correct input from another room.

    Incoming data from the remote looks like:

    SUSPEND button:
    Quote:
    Info:IR:IR IR_Kaseikyo_Denon 0x314 0x0 0 (48 bits)


    ON button:
    Quote:
    Info:IR:IR IR_Kaseikyo_Denon 0x214 0x0 0 (48 bits)


    When I attempt to publish, i.e. using cmnd/IRDevice/IRSend, payload:
    Kaseikyo_Denon 0x314 0x0


    The device logs:
    Quote:
    Error:IR:IRSend cmnd not valid [kaseikyo_denon 0x31] not like [NEC-0-1A] or [NEC 0 1A 1].


    OK, so it doesn't like Kaseikyo_Denon (is there a list of protocols somewhere?), but Denon does sorta work with cmnd/IRDevice/IRSend using payload:
    denon 0x314 0x0


    The transmitter shows in the log:
    Quote:
    Info:IR:IR send denon 0x314 0x0 protocol 3 addr 0x314 cmd 0x0 repeats 0 bits override 0


    But the actual data received (tested via the other IRC03) comes to the receiver as:
    Quote:
    Info:IR:IR IR_Denon 0x14 0x0 0


    I tried then checking this against Denon codes from the IRDB (https://github.com/probonopd/irdb) and those also seem to strip the addresses front of any address (so 0x144 just becomes 0x4).

    Using NEC protocol etc is received as expected but of course doesn't work on my device:
    Quote:
    cmnd/IRDevice/IRSend nec 0x314 0x0
    Transmitter: Info:IR:IR send nec 0x314 0x0 protocol 7 addr 0x314 cmd 0x0 repeats 0 bits override 0
    Receiver: Info:IR:IR IR_NEC 0x314 0x0 0



    I believe I may have tracked this done. There's this bit under driver/drv_ir.cpp


    extern "C" commandResult_t IR_Send_Cmd(const void *context, const char *cmd, const char *args_in, int cmdFlags) {
        int numProtocols = sizeof(ProtocolNames)/sizeof(*ProtocolNames);
        if (!args_in) return CMD_RES_NOT_ENOUGH_ARGUMENTS;
        char args[20];
        strncpy(args, args_in, 19);
        args[19] = 0;
    
        // split arg at hyphen;
        char *p = args;
        while (*p && (*p != '-') && (*p != ' ')){
            p++;
        }
    etc etc


    Now if args_in is being split out of the command buffer, such as from httpserver/http_fns.c, that looks to be about 128 characters (inclusive of the command itself)
    char tmpA[128];
    ...
    commandLen = http_getArg(request->url, "cmd", tmpA, sizeof(tmpA));
    


    So if our command is "IRSend ", that's another 120 characters or so (plus the terminator) of potential input

    Now if we look at where things get cut off
    IRSend Kaseikyo_Sharp 1 1 0
    That's the command (6 chars), a space, then "Kaseikyo_Sharp" (14 chars) - and that leaves only about 5 characters for the rest of the args_in. Anything more is going to get chopped

    Further to that, one of the vendor ID's is "Kaseikyo_Mitsubishi", which is 19 characters just by itself.

    This should be fixable by increasing this
    char args[20];

    to something like
    char args[40];


    That would allow for input of a larger vendor string plus a 5-char address arg, 4-char CMD arg, and a bit more for repeats/override (bits I think is actually set in the code under the "Arduino-IRremote-mod" folder, i.e.
      #define KASEIKYO_BITS               (KASEIKYO_VENDOR_ID_BITS + KASEIKYO_VENDOR_ID_PARITY_BITS + KASEIKYO_ADDRESS_BITS + KASEIKYO_COMMAND_BITS + KASEIKYO_PARITY_BITS)


    That said, if OBK is potentially going to allow RAW output at some time the args character-array would definitely need to be even bigger.
  • ADVERTISEMENT
  • #2 20940824
    p.kaczmarek2
    Moderator Smart Home
    Thank you, you're right, the buffer was too small. I've applied your patch to both branches (main with old IR library and Vfonov fork with new IR). Can you recheck if it works now for you?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #3 20945549
    ErrorGap
    Level 5  

    The data in the outgoing logs looks OK now. I'm still not getting anything picked up by my receiver itself yet so I may need to dig into things a bit further. It also doesn't log anything in the second device which I've set to pick up.

    As an example, here's what I see in the logs when I hit the "VolUp" button on the remote:
    Quote:
    Info:IR:IR IR_Kaseikyo_Denon 0x14 0x17 0 (48 bits)


    I would assume that would be equivalent to a send command of:
    IRSend Kaseikyo_Denon 14 17


    Sending such produces the log:
    Quote:
    Info:IR:IR send Kaseikyo_Denon 14 17 protocol 12 addr 0x14 cmd 0x17 repeats 0 bits override 0


    I have another IRC03 device to pick up the signal and nothing shows up in the log there corresponding to the above send event. Not a wrong addr/cmd but a lack of anything logged at all, when I would expect it to match the same receive event as pushing the button on the actual remote.

    However, if I use the following command from Device #1:
    IRSend Denon 14 17


    Then the following is seen in the logs of device #2:
    Quote:
    Info:IR:IR IR_Denon 0x14 0x17 0 (15 bits)
    Info:IR:IR IR_Denon 0x14 0x17 2 (15 bits)


    So the secondary device is picking up IR sent from device #1 - and the addr+cmd do line up - if I use "Denon" as the protocol. Of course this doesn't work on my surround receiver, presumably because it is expecting Denon device commands from a Kaseikyo remote and those differ from a Denon remote.

    Testing with other Kaseikyo remote types also results in no input in the logs of device #2, including:
    - kaseikyo_sharp
    - kaseikyo_panasonic
    - kaseikyo_mitsubishi

    Sending codes for other models such as Samsung also match up the data sent+received, so it appears just Kaseikyo_Denon that results in a lack of input from the second device.

    Command: IRSend samsung 14 17
    Log (device #1): Info:IR:IR send samsung 14 17 protocol 18 addr 0x14 cmd 0x17 repeats 0 bits override 0
    Log (device #2): Info:IR:IR IR_Samsung 0x14 0x17 0 (32 bits)

    (obviously the ADDR and CMD for those devices wouldn't serve the same function but it does at least show that the output and input between the two OpenBeken devices lines up as expected)

    I have an old Sony stereo receiver and a Samsung soundbar kicking around that I need to find the remotes for, so the next step will be to see compare input from the remote and input/output logs for those and see if the IR transmission works as expected. If so, there could be some other bug, possibly in the "Arduino-IRremote" library. It could also be another short buffer further down in the code (or maybe it is stripping the underscore in the signal type somewhere), in which case I can hopefully manage to dig that up without too much difficulty. I think the problem lies with Kaseikyo specifically as even just sending that as the signal type (no _othervendor) results in no errors sending but nothing received.

    It might take a bit until I have some firmer data on it but I'll dig further and see if I can find something useful.
  • ADVERTISEMENT
  • #4 20962397
    ErrorGap
    Level 5  

    OK, so after hacking in some debug MARK data and following the flow
    It looks like the IRSend operation is not actually hitting anything that results in output. It should end up here in the IRSend.hpp code:

    void IRsend::sendPulseDistanceWidthFromArray(PulsePauseWidthProtocolConstants *aProtocolConstants, uint32_t *aDecodedRawDataArray,
            unsigned int aNumberOfBits, int_fast8_t aNumberOfRepeats) {
    ...



    But this is redefined instead in drv_ir.cpp and doesn't have anything more to do

     // this is to replicate places where the library uses the static class.
    // will need to update to call our dynamic class
    class SpoofIrSender {
        public:
           ...
            void sendPulseDistanceWidthFromArray(PulsePauseWidthProtocolConstants *aProtocolConstants, uint32_t *aDecodedRawDataArray,
                unsigned int aNumberOfBits, int_fast8_t aNumberOfRepeats) {
                
            }
    };


    When adding a debug MARK to both functions, it ends up in the empty one.

    Other protocols like SONY will work because i.e. that one uses the "sendPulseDistanceWidth" function (which has not been overridden) rather than the overridden "sendPulseDistanceWidthFromArray"

    It's a bit late now but I'll see if I can update things so that this results in something happening for the modules using sendPulseDistanceWidthFromArray when I've got a bit more time to poke again.
  • ADVERTISEMENT
  • #5 20994282
    Vincent0815
    Level 1  
    Hi!

    First of all thank you very much for this awesome solution! I was able to reflash a Tuya S06 and make it usable in home assistant. Unfortunately I have an issue which I could not solve. I can send Ir codes in NEC formats without issues but I am stuck with these "Pulse distance" thing. Has anybody an idea how can I convert this captured single command in an ir send command?

    Debug:IR:IR decode returned true, protocol 1
    Debug:IR: Raw-Data=0x85
    Debug:IR: 9 bits
    Debug:IR: LSB first
    Debug:IR:IR decode returned true, protocol PulseDistance (1)
    Info:MQTT:Publishing val IR_PulseDistance 0x721 0x70E 0 (9 bits) to IR-Blaster/ir/get retain=0
    Info:IR:IR MQTT publish IR_PulseDistance 0x721 0x70E 0 (9 bits) took 3ms
    Debug:IR:IR fire event took 0ms
    Debug:IR:IR decode returned true, protocol 1
    Debug:IR: Raw-Data=0x85
    Debug:IR: 9 bits
    Debug:IR: LSB first
    Debug:IR:IR decode returned true, protocol PulseDistance (1)
    Info:MQTT:Publishing val IR_PulseDistance 0x622 0x60F 0 (9 bits) to IR-Blaster/ir/get retain=0
    Info:IR:IR MQTT publish IR_PulseDistance 0x622 0x60F 0 (9 bits) took 1ms
    Debug:IR:IR fire event took 0ms
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic IR-Blaster/ir/get
    Debug:MQTT:channelSet topic 4209020 with arg IR_PulseDistance 0x721 0x70E 0 (9 bits)
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic IR-Blaster/ir/get
    Debug:MQTT:channelSet topic 4209020 with arg IR_PulseDistance 0x622 0x60F 0 (9 bits)
    
  • #6 21000625
    ErrorGap
    Level 5  
    I don't see any capture?

    What's your IRReceive date look like?

    Easiest way is just to use a device that does receive+send, capture and note the button events you want and then use the same device type and codes for IRSend
ADVERTISEMENT