module.exports = function(RED) {
function SMSNode(config) {
RED.nodes.createNode(this,config);
var node = this;
this.on('input', function(msg) {
msg.method ="GET";
msg.payload="";
//use http or https depends how server is configured
var protocol = "http";
var musername = this.username;
var mpassword = this.password;
var mip = this.ip;
var mport = this.port;
var mrecipient = this.recipient;
var mmessage = this.message;
// var myurl = protocol + "://"+ this.username + ":" + this.password + "@" + this.ip + ":" + this.port + "/send.html?smsto=" + this.recipient + "&smsbody=" + this.message;
var myurl = protocol + "://"+ musername + ":" + mpassword + "@" + mip + ":" + mport + "/send.html?smsto=" + mrecipient + "&smsbody=" + mmessage;
msg.url = myurl;
node.send(msg);
});
}
RED.nodes.registerType("sms",SMSNode);
}<script type="text/javascript"> RED.nodes.registerType('sms',{ category: 'function', color: '#a6bbcf', defaults: { name: {value:""}, ip:{value:"", required:true}, port: {value:"", required:true, validate: RED.validators.number()}, recipient: {value:"", required:true}, message: {value:"", required:true},// },// credentials: { username: {type:"text", required:true}, password: {type:"password", required:true} },
inputs:1, outputs:1, icon: "feed.png", label: function() { return this.name||this.username||this.password||this.ip||this.port||this.recipient||this.message||"sms"; } });</script>
<script type="text/x-red" data-template-name="sms"> <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-username"><i class="icon-tag"></i> User Name</label> <input type="text" id="node-input-username" placeholder="UserName"> </div> <div class="form-row"> <label for="node-input-password"><i class="icon-tag"></i> Password</label> <input type="password" id="node-input-password" placeholder="Password"> </div> <div class="form-row"> <label for="node-input-ip"><i class="icon-tag"></i> IP Address</label> <input type="text" id="node-input-ip" placeholder="IPAddress"> </div> <div class="form-row"> <label for="node-input-port"><i class="icon-tag"></i> Port</label> <input type="text" id="node-input-port" placeholder="Port"> </div> <div class="form-row"> <label for="node-input-recipient"><i class="icon-tag"></i> Recipient</label> <input type="text" id="node-input-recipient" placeholder="Recipient"> </div> <div class="form-row"> <label for="node-input-message"><i class="icon-tag"></i> Message</label> <input type="text" id="node-input-message" placeholder="Message"> </div></script>
<script type="text/x-red" data-help-name="sms"> <p>A simple node that sends a SMS message using the android Play app:</p> <p> 1.0 SMS Gateway Ultimate.</p> <p>Instructions:</p> <p>1. Install SMS Gateway Ultimate from google play</p> <p>2. Setup server on android phone (username,password,port,protocol,port)</p> <p>3. Start the server on android phone and press info where you will get local ip</p> <p>4. Phone and node-red must be on the same network or correct routes must </p> <p> be used or router forwarding must be applied</p> <p>5. Enter information into the SMS parameter node</p> <p>6. In httprequest node enter username and password</p> </script>All of the node's properties are passed in the parameter you've called 'config' on the Node function, they are not automatically added to 'this'.
Credentials are slightly different, and are passed under 'this.credentials'.
Inside the on 'input' event handler function, you should use 'node' not 'this' given the way you've defined things.
Nick
--
http://nodered.org
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/31c63f63-cc3e-46e1-ac5e-d381d3502480%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.