From 7c3b1d7ff4a4648c8dbba4c4b56076e90469fb5d Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Thu, 31 Oct 2013 09:52:15 +0000 Subject: [PATCH] Copy over "sample" node files freo main project as this is where most people will be adding extra nodes. --- 99-sample.html.demo | 77 +++++++++++++++++++++++++++++++++++++++++++++ 99-sample.js.demo | 52 ++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 99-sample.html.demo create mode 100644 99-sample.js.demo diff --git a/99-sample.html.demo b/99-sample.html.demo new file mode 100644 index 000000000..e26197aa7 --- /dev/null +++ b/99-sample.html.demo @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + diff --git a/99-sample.js.demo b/99-sample.js.demo new file mode 100644 index 000000000..c591185a0 --- /dev/null +++ b/99-sample.js.demo @@ -0,0 +1,52 @@ +/** + * Copyright 2013 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +// If you use this as a template, replace IBM Corp. with your own name. + +// Sample Node-RED node file + +// Require main module +var RED = require(process.env.NODE_RED_HOME+"/red/red"); + +// The main node definition - most things happen in here +function SampleNode(n) { + // Create a RED node + RED.nodes.createNode(this,n); + + // Store local copies of the node configuration (as defined in the .html) + this.topic = n.topic; + + // Do whatever you need to do in here - declare callbacks etc + // Note: this sample doesn't do anything much - it will only send + // this message once at startup... + // Look at other real nodes for some better ideas of what to do.... + var msg = {}; + msg.topic = this.topic; + msg.payload = "Hello world !" + + // send out the message to the rest of the workspace. + this.send(msg); + + this.on("close", function() { + // Called when the node is shutdown - eg on redeploy. + // Allows ports to be closed, connections dropped etc. + // eg: this.client.disconnect(); + }); +} + +// Register the node by name. This must be called before overriding any of the +// Node functions. +RED.nodes.registerType("sample",SampleNode);