Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Receiving input node #4

Closed
insolite opened this issue Jan 9, 2018 · 3 comments
Closed

Receiving input node #4

insolite opened this issue Jan 9, 2018 · 3 comments

Comments

@insolite
Copy link

insolite commented Jan 9, 2018

Hi! Are there any plans for adding of code receiving input node? I've made a request for integrating of receiving features of rcswitch to node-rcswitch bindings recently. If/when it will be released would you mind to add corresponding node? I'd be glad to help with PR, but I'm mostly operating raw codes, so I'm kinda beyond that devices/groups logic. I only have some working prototype based on this simplest fork:

module.exports = function (RED) {
    function RCSwitchNodeReceive(config) {
        RED.nodes.createNode(this, config);
        var node = this;
        node.pin = parseInt(config.pin);
        var rcswitch = require('rcswitch');
        rcswitch.enableReceive(node.pin);
        node.interval = setInterval(function () {
            if (rcswitch.available()) {
                var code = rcswitch.getReceivedValue();
                node.send({payload: code});
                rcswitch.resetAvailable();
            }
        }, 500);
    }

    RED.nodes.registerType("rcswitch-receive", RCSwitchNodeReceive);
};
@nobodyMO
Copy link
Owner

Hi insolite,
So far I had no plans to add an input node to the package.
I can integrate that. But I don't have any devices to test the function.
But I'm bothered that the data is polled in an interval of 500ms. This should result in an unnecessary workload on the system. A call back function would be a better solution.

@insolite
Copy link
Author

Of course the callback is better rather than polling interval, but seems like that's how rcswitch receiving intended to work. However in most cases there are no data and the only function called repeatedly is available which has only a single equality check under the hood, which should not be so crucial. We can try build some kind of polling thread on the C level with callback, but I guess we'll not gain so much performance from dissolving of a few function calls. After all, fixed 500ms is just a part of example, so I think it should become at least a configurable node field.
For now I have that kind of node working:

module.exports = function (RED) {
    function RCSwitchNodeReceive(config) {
        RED.nodes.createNode(this, config);
        var node = this;
        var pin = parseInt(config.pin);
        var interval = parseInt(config.interval);
        var rcswitch = require('rcswitch');
        rcswitch.enableReceive(pin);
        node.interval = setInterval(function () {
            if (rcswitch.available()) {
                var code = rcswitch.getReceivedValue();
                node.send({payload: code});
                rcswitch.resetAvailable();
            }
        }, interval);
        this.on('close', function() {
            clearInterval(node.interval);
            rcswitch.disableReceive();
        });
    }

    RED.nodes.registerType("rcswitch-receive", RCSwitchNodeReceive);
};

@insolite
Copy link
Author

FYI, since I didn't get any response for such node-rcswitch feature request I've forked and implemented it on my own here (node-rcswitch2) and did another fork from original node-red-contrib-rcswitch which is now based on node-rcswitch2. I'm okay with using it from github directly so I didn't publish that to npm in case it will be integrated into original libraries someday.
So, thanks for response anyway and if suddenly that node-rcswitch modification will be interesting to you just reply and I'll publish it to npm.

@nobodyMO nobodyMO closed this as completed May 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants