Help on adapting module to receive from any IR remote

Hi, I was able to activate and receive on NR the remote commands on my Orange zero, to do that I'm using node-red-contrib-ir which unfortunately filter the data packet and returns me always "4", I need to edit the script to receive the full message present on /dev/input/event0, someone may please help me? Thanks!

This is the script, you can find it here: node-red-contrib-ir/bpi-ir-node.js at master · 4ib3r/node-red-contrib-ir · GitHub

module.exports = function(RED) {
    var IR = require('bpi-ir');
    function BpiIrOutNode(config) {
        var ir = new IR();
        RED.nodes.createNode(this,config);
        this.debug = config.debug || false;
        this.keyMap = config.keymap || {};
        var node = this;
        this.on('close', function() {
            if (ir !== undefined && ir.stop !== undefined) {
                ir.stop();
            }
        });
        ir.start();
	var lastKey = null;
        var mappKey = function(key) {
            var mappedKey = node.keyMap[key];
            if (mappedKey == undefined) {
                mappedKey = key;
            }
            return mappedKey;
        }
	ir.on('down', function(key) {
            var mappedKey = mappKey(key);
            var msg = { payload: mappedKey };
            if (node.debug) {   
                node.status({fill:"green",shape:"ring",text:"Key: " + mappedKey});
            }
            node.send([msg, null]);
	});
        ir.on('up', function(key) {
            var mappedKey = mappKey(key);
            var msg = { payload: mappedKey };
            node.send([null, msg]);
            if (node.debug) {
                node.status({fill:"red",shape:"ring",text:"Key: " + mappedKey});
            }
        });
    }
    RED.nodes.registerType("banana-ir in", BpiIrOutNode);
}

Briefly I would like to share how I activated the IR:
on root access run armbian-config, under systam/hardware activate IR, save and reboot
after reboot you may verify the driver has been loaded with lsmod | grep -i cir and dmesg | grep -i ir commands
At this time you're able to see incoming packets, run on root cat /dev/input/event0 | xxd
and point your remote to theIR receiver and press a buttonm chances are you won't see nothing because the receiving protocol isn't the correct one, for me it worked the nec protocol, to enable it use echo nec > /sys/class/rc/rc0/protocols, then I was able to receive.
Now install on NR the node-red-contrib-ir and add it on flow with debug node, deply and you will see NR quit with an error, NR hasn't the permission to access the same file, /dev/input/event0, so you need to add access to it with sudo chmod 666 /dev/input/event0.
That's all, but you need to make the changes permanet for the next reboot so I added lines at crontab:
crontab -e
I added lines:
@reboot echo nec | sudo tee /sys/class/rc/rc0/protocols
@reboot sudo chmod 666 /dev/input/event0

I can't understand where the vale "key" comes from, the node output only one byte, but the content of data placed on dev/input/event0 is much more, mappKey(key) returns one byte, how can I return the whole data? Thanks for help

        ir.on('up', function(key) {
            var mappedKey = mappKey(key);
            var msg = { payload: mappedKey };

I'm trying to study the module but I can't figure out myself, I suppose the solution is on the html instead of js filem probably here:

$("#node-input-add-keymap").click(function() {
                generateKeymap($container.children().length+1,{v:"",v2:""});
                $("#node-input-keymap-container-div").scrollTop($("#node-input-keymap-container-div").get(0).scrollHeight);
            });
            console.log(this.keymap);
            $.each(this.keymap, function(i) {
                var key = this.keymap[i];
                generateKeymap(i+1, {v: i, v2: key});
            });

        },
        oneditsave: function() {
             var keymap = $("#node-input-keymap-container").children();
             var node = this;
             keymap.each(function(i) {
                node.keymap[keymap.find(".node-input-key-value").val()] = 
                    keymap.find(".node-input-name-value").val();
             });
            console.log(this.keymap);

What I know is that module returns 4, but each time I press button I have ths entry on
The first byte looks a sequence number, not really clear but not interesting. The button code I need is in these 4 lines "13", I've tested recursively all buttons and I?m sure this is the right position containing the value

00000000: 5010 4564 062a 0500 0400 0400 1300 0000 P.Ed...........
00000010: 5010 4564 062a 0500 0000 0000 0000 0000 P.Ed.
..........
00000020: 5010 4564 4cf4 0500 0400 0400 1300 0000 P.EdL...........
00000030: 5010 4564 4cf4 0500 0000 0000 0000 0000 P.EdL...........

I have stopped NR, changed on html:
var key = 0x0c;
start it again, I still receive vale 4. Really I don't know what to edit to get the 12th value of the data received :frowning:
Thanks for help!

I've solded with an old module that can't be more found on palette:

I've changed into its .js

  function parseBuffer( buffer ) {
    var eventObject = {};

    eventObject.code   = buffer[12];

    return eventObject;

so I can get just the IR code located on 12th position, uploaded into .node-red folder and compiled by npm list node-red-contrib-dev-input when you are in the module folder
It works

It works but it creates a problem in NR, it does't let it quit later, the script maybe is not respecting the recent NR versions and need to be corrected. Can some one please help with it? Thank you very much!

I've updated Node to 20 and nmp, NR is 3.0.2
I post the code here:
JSON:

{
  "name": "node-red-contrib-dev-input",
  "version": "0.0.1",
  "description": "Basic Node-Red node for use in /dev/input/event reading.",
  "main": "dev-input.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/MattGyver/node-red-contrib-dev-input.git"
  },
  "keywords": [
    "node-red",
    "input",
    "event",
    "hid"
  ],
  "node-red": {
    "nodes": {
      "devinput": "dev-input.js"
    }
  },
  "author": "Mattias Nord",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/MattGyver/node-red-contrib-dev-input/issues"
  },
  "homepage": "https://github.com/MattGyver/node-red-contrib-dev-input#readme"
}

HTML:

<script type="text/javascript">
    RED.nodes.registerType('dev-input',{
        category: 'input',
        color: '#a6bbcf',
        defaults: {
            name: {value:""},
            device: {valie:""}
        },
        inputs:0,
        outputs:1,
        icon: "file.png",
        label: function() {
            return this.name||"dev-input";
        }
    });
</script>

<script type="text/x-red" data-template-name="dev-input">
    <div class="form-row">
        <label for="node-input-name"><i class="icon-tag"></i> Name</label>
        <input type="text" id="node-input-name" placeholder="Name">
    </div>
    <div class="form-row">
        <label for="node-input-device"><i class="icon-tag"></i> Device</label>
        <input type="text" id="node-input-device" placeholder="/dev/input/event0">
    </div>
</script>

<script type="text/x-red" data-help-name="dev-input">
    <p>A simple node that reads specified /dev/input event and forward the event data in msg.payload.</p>
</script>

JS:

module.exports = function(RED) {

  var msg = { topic:"dev-input" }

  function parseBuffer( buffer ) {
    var eventObject = {};

    eventObject.code   = buffer[12];

    return eventObject;
  }

  function DevInput(config) {
    RED.nodes.createNode(this,config);
    var node = this;

    if (config.device != undefined) {
      var FS = require('fs');

      if (!FS.existsSync(''+config.device)) {
        throw "Can't find device.";
      }

      FS.createReadStream(''+config.device).on('data', function( buffer ) {
        msg.payload = parseBuffer(buffer)
        node.send(msg);
      });
    }

  }
  RED.nodes.registerType("dev-input",DevInput);
}

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.