Error: getaddrinfo ENOTFOUND undefined

568 views
Skip to first unread message

Jerry Barnett

unread,
Mar 13, 2017, 1:14:53 PM3/13/17
to Node-RED
Been writing a new node (my first) to collect information and pass along the URL to an HTTP Request node.  It was inspired by a flow from @github/srakovec 'Sending SMS from your own local Gateway'

I was able to get the node to show up in the pallet, but after entering in the information and executing it, I get teh following error from the HTTP request node:

msg.payload : string[144]
"Error: getaddrinfo ENOTFOUND undefined undefined:80 : http://undefined:undefined@undefined:undefined/send.html?smsto=undefined&smsbody=undefined"
I assume the 'msg' object is getting passed through, because the HTTP string is there  (i.e. the http://undefined:undefined@undefined:undefined/send.html?smsto=undefined&smsbody=undefined) but the variables that I entered are not getting placed in the string.
My code:sms.js
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);
}

sms.html
<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>

Also, I wanted to use credentials for the username and password, but when I tried to do that I could enter the user and password in the form, but when I tried to inject to execute it said the user name was blank (or something like that.)

Anyway, since this is my first node I was wondering what I may be doing wrong.



Nick O'Leary

unread,
Mar 13, 2017, 2:27:14 PM3/13/17
to Node-RED

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.
Reply all
Reply to author
Forward
0 new messages