Created
March 23, 2016 15:38
-
-
Save jotadepicas/3f5f34c092011e5d4524 to your computer and use it in GitHub Desktop.
Dummy node to replace rpi-gpio node when not running on a Pi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/x-red" data-template-name="rpi-gpio in"> | |
<div class="form-row"> | |
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label> | |
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name"> | |
</div> | |
</script> | |
<script type="text/x-red" data-help-name="rpi-gpio in"> | |
<p>Dummy placeholder node for rpi-gpio.</p> | |
</script> | |
<script type="text/javascript"> | |
RED.nodes.registerType('rpi-gpio in', | |
{ | |
color:"#ffdbef", | |
category: 'dummy', | |
defaults: { | |
name: {value:""} | |
}, | |
inputs:0, | |
outputs:1, | |
icon: "rpi.png", | |
label: function() { | |
return this.name || "rpi-gpio-dummy" | |
}, | |
labelStyle: function() { | |
return this.name?"node_label_italic":"" | |
} | |
}); | |
</script> | |
<script type="text/x-red" data-template-name="rpi-gpio out"> | |
<div class="form-row"> | |
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label> | |
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name"> | |
</div> | |
</script> | |
<script type="text/x-red" data-help-name="rpi-gpio out"> | |
<p>Dummy placeholder node for rpi-gpio.</p> | |
</script> | |
<script type="text/javascript"> | |
RED.nodes.registerType('rpi-gpio out', | |
{ | |
color:"#ffdbef", | |
category: 'dummy', | |
defaults: { | |
name: {value:""} | |
}, | |
inputs:1, | |
outputs:0, | |
icon: "rpi.png", | |
label: function() { | |
return this.name || "rpi-gpio-dummy" | |
}, | |
labelStyle: function() { | |
return this.name?"node_label_italic":"" | |
} | |
}); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function (RED) { | |
function dummyNode (n) { | |
RED.nodes.createNode(this, n) | |
var node = this | |
function sendToDebug (msg) { | |
RED.comms.publish('debug', { | |
id: node.id, | |
name: node.name, | |
topic: msg.topic, | |
msg: msg.payload + '', | |
_path: msg._path | |
}) | |
} | |
function doProcessInput (msg) { | |
RED.log.debug(node.name + ':' + msg.payload) | |
sendToDebug(msg) | |
node.send(msg) | |
} | |
this.on('input', function (msg) { | |
doProcessInput(msg) | |
}) | |
this.on('close', function () {}) | |
var nodeAdminEndpoint = '/dummy-gpio/' + encodeURIComponent(this.name).replace('(', '_').replace(')', '_') | |
RED.log.info('Registered admin endpoint: ' + nodeAdminEndpoint) | |
RED.httpAdmin.post( | |
nodeAdminEndpoint, | |
function (req, res) { | |
var msg = { | |
topic: node.name, | |
payload: req.body.value | |
} | |
doProcessInput(msg) | |
res.json({ result: 'OK' }) | |
}) | |
} | |
RED.nodes.registerType('rpi-gpio in', dummyNode) | |
RED.nodes.registerType('rpi-gpio out', dummyNode) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment