# Add UDP out into function/custom node

**URL:** https://discourse.nodered.org/t/add-udp-out-into-function-custom-node/44297
**Category:** Developing Nodes
**Created:** [16 April 2021 20:10 UTC](https://discourse.nodered.org/t/add-udp-out-into-function-custom-node/44297 "2021-04-16T20:10:47Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![JohnnyPicnic](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/johnnypicnic/32/34787_2.png) [@JohnnyPicnic](https://discourse.nodered.org/u/JohnnyPicnic)
#### Post date: [16 April 2021 20:10 UTC](https://discourse.nodered.org/t/add-udp-out-into-function-custom-node/44297/1 "2021-04-16T20:10:47Z")

</div>

I have created a custom node and would like to incorporate the link out node into it.  
Is that possible?  
It's that or somehow add the functions that are performed at the link in to the custom node.

My node.js

```auto
module.exports = function(RED) {
    function PhoneNumberNode(config) {
        RED.nodes.createNode(this,config);
	this.number = config.number;
        var node = this;
        this.on('input', function(msg) {
            msg.number = node.number;
            node.send(msg);
        });
    }
    RED.nodes.registerType("phonenumber",PhoneNumberNode);

```

Example flow:

```auto
[{"id":"8aadf171.517b6","type":"link in","z":"64a5e2ea.298e7c","name":"SMS","links":["34ec2c86.ba6c64","251c2ea4.db6e32","fecdfa88.4b14e8"],"x":455,"y":1200,"wires":[["565a8587.79193c"]]},{"id":"565a8587.79193c","type":"function","z":"64a5e2ea.298e7c","name":"Prepare Message","func":"msg.message = Buffer.from(msg.payload,\"utf8\").toString(\"Hex\"),\nmsg.chr = msg.payload.length,\nmsg.payload = msg.number + \",ASCII,\"+ msg.chr + \",\" + msg.message\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":590,"y":1200,"wires":[["6d438163.fbf47"]]},{"id":"6d438163.fbf47","type":"udp out","z":"64a5e2ea.298e7c","name":"SMS Out","addr":"192.168.13.31","iface":"","port":"1147","ipv":"udp4","outport":"1147","base64":false,"multicast":"false","x":760,"y":1200,"wires":[]},{"id":"fecdfa88.4b14e8","type":"link out","z":"64a5e2ea.298e7c","name":"Darren SMS","links":["87935307.973b5","a2b4e8ea.fbce58","8aadf171.517b6"],"x":355,"y":1200,"wires":[]},{"id":"4f854124.c9b1a","type":"phonenumber","z":"64a5e2ea.298e7c","name":"User Name","number":"18881234567","x":210,"y":1200,"wires":[["fecdfa88.4b14e8"]]}]

```

![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/f/1f9e852290e89e00263a89df84bdf64b4f96481c.png)

---

<div class="post-metadata">

### Author: ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)
#### Post date: [16 April 2021 20:34 UTC](https://discourse.nodered.org/t/add-udp-out-into-function-custom-node/44297/2 "2021-04-16T20:34:41Z")

</div>

This is a really bad idea. It removes point of wiring nodes together so you can see where messages are going.

What problem are you trying to solve by doing this?

---

<div class="post-metadata">

### Author: ![JohnnyPicnic](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/johnnypicnic/32/34787_2.png) [@JohnnyPicnic](https://discourse.nodered.org/u/JohnnyPicnic)
#### Post date: [16 April 2021 20:36 UTC](https://discourse.nodered.org/t/add-udp-out-into-function-custom-node/44297/3 "2021-04-16T20:36:22Z")

</div>

Ya I think i see that now.  
So I included the Prepare Message function into my custom node, now i just need to include the SMS Out which is a UDP out.

---

<div class="post-metadata">

### Author: ![JohnnyPicnic](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/johnnypicnic/32/34787_2.png) [@JohnnyPicnic](https://discourse.nodered.org/u/JohnnyPicnic)
#### Post date: [16 April 2021 20:59 UTC](https://discourse.nodered.org/t/add-udp-out-into-function-custom-node/44297/5 "2021-04-16T20:59:42Z")

</div>

Is there an easy way to call the UPD function using a custom node?  
I have the message formatted so all I need to do now is send it out to IP 192.168.13.31 on port 1147.

---

<div class="post-metadata">

### Author: ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)
#### Post date: [16 April 2021 21:01 UTC](https://discourse.nodered.org/t/add-udp-out-into-function-custom-node/44297/6 "2021-04-16T21:01:39Z")

</div>

Again, what problem are you trying to solve by adding that feature to your node that can't be solved just by wiring it to a UDP node?

---

<div class="post-metadata">

### Author: ![JohnnyPicnic](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/johnnypicnic/32/34787_2.png) [@JohnnyPicnic](https://discourse.nodered.org/u/JohnnyPicnic)
#### Post date: [16 April 2021 21:03 UTC](https://discourse.nodered.org/t/add-udp-out-into-function-custom-node/44297/7 "2021-04-16T21:03:37Z")

</div>

I use this node to send SMS messages to list of people.  
There could be a hundred numbers and each custom node would then need an additional link out.

---

<div class="post-metadata">

### Author: ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)
#### Post date: [16 April 2021 21:10 UTC](https://discourse.nodered.org/t/add-udp-out-into-function-custom-node/44297/8 "2021-04-16T21:10:38Z")

</div>

Why would it need a separate link out? I assume you are sending the UDP packets to the same IP and Port and since the phone number is in the message?

---

<div class="post-metadata">

### Author: ![JohnnyPicnic](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/johnnypicnic/32/34787_2.png) [@JohnnyPicnic](https://discourse.nodered.org/u/JohnnyPicnic)
#### Post date: [16 April 2021 21:12 UTC](https://discourse.nodered.org/t/add-udp-out-into-function-custom-node/44297/9 "2021-04-16T21:12:05Z")

</div>

Because I'm a noob and don't know how to add the "Send UDP" function to my custom node. So for now I'm linking them individually.

---

<div class="post-metadata">

### Author: ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)
#### Post date: [16 April 2021 21:27 UTC](https://discourse.nodered.org/t/add-udp-out-into-function-custom-node/44297/10 "2021-04-16T21:27:55Z")

</div>

I'm saying you only need one UDP node to handle all the output.

But if you really want to include it in your node, the source code for all the core nodes is on github so you are perfectly free to read it and learn from it.

> <https://github.com/node-red/node-red/blob/master/packages/node_modules/@node-red/nodes/core/network/32-udp.js>

---

<div class="post-metadata">

### Author: ![JohnnyPicnic](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/johnnypicnic/32/34787_2.png) [@JohnnyPicnic](https://discourse.nodered.org/u/JohnnyPicnic)
#### Post date: [16 April 2021 21:34 UTC](https://discourse.nodered.org/t/add-udp-out-into-function-custom-node/44297/11 "2021-04-16T21:34:04Z")

</div>

I think i get what you're saying. I just would like to not have to "wire" all the custom nodes back to the upd out. I don't really know what Node-Red is capable but this is probably beyond my skills.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [15 June 2021 21:34 UTC](https://discourse.nodered.org/t/add-udp-out-into-function-custom-node/44297/12 "2021-06-15T21:34:18Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
