# MQTT To ASCII over TCP/IP

**URL:** <https://discourse.nodered.org/t/mqtt-to-ascii-over-tcp-ip/46438>\
**Category:** General\
**Created:** [29 May 2021 05:01 UTC](https://discourse.nodered.org/t/mqtt-to-ascii-over-tcp-ip/46438 "2021-05-29T05:01:15Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![vaughan.mcd](https://avatars.discourse-cdn.com/v4/letter/v/258eb7/32.png) [@vaughan.mcd](https://discourse.nodered.org/u/vaughan.mcd)\
**Post date:** [29 May 2021 05:01 UTC](https://discourse.nodered.org/t/mqtt-to-ascii-over-tcp-ip/46438/1 "2021-05-29T05:01:16Z")

</div>

HI I reaching out to get some help with setting up formatting on the a send and receive node for a device

The device communicates through an IP connection using an ASCII protocol.

protocol will allow control and monitoring of  
• On/Off  
• Mode  
• Set Point Temperature  
• Room Temperature  
• Fan Speed

I want to create a node that I can link to MQTT for each function  
ec: On/Off

Send MQTT[payload AirConON\>On/Off\>ASCII\>TCPout:192.168.1.10:3310  
Receive TCPin:192.168.1.10:3310\>ASCII\>MQTT[payload AirConON

I presume once I can get a send and response for 1 function I can duplicate it for the other functions.  
I have a attached  
[Air-Con ASCII set.pdf](https://discourse.nodered.org/uploads/short-url/rQjwlEt14lKlayErYzK4WUyyXDu.pdf) (434.3 KB)  
the pdf for the units WMP protocol.

I have been playing around with this for some time and can not get any response from the unit.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [29 May 2021 06:02 UTC](https://discourse.nodered.org/t/mqtt-to-ascii-over-tcp-ip/46438/2 "2021-05-29T06:02:46Z")

</div>

Start simple. Add an inject node with the required string, send that to a TCP request node then attach that to a debug node.

Get that working then it's a simple matter of generating ASCII strings from your mqtt data.

---

<div class="post-metadata">

**Author:** ![vaughan.mcd](https://avatars.discourse-cdn.com/v4/letter/v/258eb7/32.png) [@vaughan.mcd](https://discourse.nodered.org/u/vaughan.mcd)\
**Post date:** [29 May 2021 11:27 UTC](https://discourse.nodered.org/t/mqtt-to-ascii-over-tcp-ip/46438/3 "2021-05-29T11:27:52Z")

</div>

Hi Have done this so far , But I can get any respose from WMP device

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/f/4fc35aedd150a24691194df6ddd6a5edd6a6d549.png)

When I inject ID

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/4/c46a452d0f984c9ee1336784de2b4e2ed1f3d682.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/c/4c27f7579d2766640e0fe0dc13a7e8233550775b.png)

I get in the debug  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/f/ffc16609e059719423fae6cc1b7321f9a6cbb413.png)

Function Node has this

```auto
ascii = [];

for (var i = 0; i < msg.payload.length; i ++)
  ascii.push(msg.payload[i].charCodeAt(0));
  

return {payload:ascii}

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [29 May 2021 13:01 UTC](https://discourse.nodered.org/t/mqtt-to-ascii-over-tcp-ip/46438/4 "2021-05-29T13:01:27Z")

</div>

Delete the function node and set the inject to send a string of `ID\r`

Do you get a reply?

---

<div class="post-metadata">

**Author:** ![vaughan.mcd](https://avatars.discourse-cdn.com/v4/letter/v/258eb7/32.png) [@vaughan.mcd](https://discourse.nodered.org/u/vaughan.mcd)\
**Post date:** [30 May 2021 07:10 UTC](https://discourse.nodered.org/t/mqtt-to-ascii-over-tcp-ip/46438/5 "2021-05-30T07:10:42Z")

</div>

> [@Steve-Mcl](#):
>
> ID\r

No Reply,

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/f/3f10b31c78bfe685cee069117baad15567ea4223.jpeg)

---

<div class="post-metadata">

**Author:** ![Urs-Eppenberger](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/urs-eppenberger/32/28_2.png) [@Urs-Eppenberger](https://discourse.nodered.org/u/Urs-Eppenberger)\
**Post date:** [30 May 2021 08:39 UTC](https://discourse.nodered.org/t/mqtt-to-ascii-over-tcp-ip/46438/6 "2021-05-30T08:39:07Z")

</div>

I followed your investigation since I find it interesting.  
Looking at the very last proposal and test, I thought this should work, but obviously it didn't.

The protocol specification is quite easy, therefore I tested with something similar, WHOIS.

Using the shell I did the following:

> telnet whois.nic.ch 43  
> and after the connection success, I sent the string "maremonti.ch" and got the correct answer.

Now the same thing with node-red. Here is the flow, very similar to what has been tried here:

```auto
[{"id":"1664b053.a37ae","type":"tcp request","z":"635b69bb.594868","server":"whois.nic.ch","port":"43","out":"time","splitc":"1000","name":"","x":410,"y":240,"wires":[["53da295d.1e4db8"]]},{"id":"53da295d.1e4db8","type":"debug","z":"635b69bb.594868","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":240,"wires":[]},{"id":"adf7805c.4aa278","type":"inject","z":"635b69bb.594868","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"whois.nic.ch","payload":"maremonti.ch","payloadType":"str","x":150,"y":240,"wires":[["1664b053.a37ae","58b754fc.b65434"]]},{"id":"58b754fc.b65434","type":"debug","z":"635b69bb.594868","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":390,"y":200,"wires":[]}]

```

I tested all the options in the TCP node, nothing worked. No reply at all. Ever.

There are a number of explanations:

- I did it wrong  
-\> I should keep my fingers away from this topic and let the experts help
- The TCP node is wrong  
-\> I should keep my fingers away and let the experts dig deeper

Either way, I'm of no real help here, I'm sorry to say.  
Urs.

---

<div class="post-metadata">

**Author:** ![Urs-Eppenberger](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/urs-eppenberger/32/28_2.png) [@Urs-Eppenberger](https://discourse.nodered.org/u/Urs-Eppenberger)\
**Post date:** [30 May 2021 08:48 UTC](https://discourse.nodered.org/t/mqtt-to-ascii-over-tcp-ip/46438/7 "2021-05-30T08:48:38Z")

</div>

Ha. I got at least my example running. This might or might not help in this case here:

In the inject node, I initially used "String" as inject format type for msg.payload.  
It works, if I select "JSON".

Working example is here:

```auto
[{"id":"1664b053.a37ae","type":"tcp request","z":"635b69bb.594868","server":"whois.nic.ch","port":"43","out":"sit","splitc":" ","name":"","x":450,"y":240,"wires":[["53da295d.1e4db8"]]},{"id":"53da295d.1e4db8","type":"debug","z":"635b69bb.594868","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":240,"wires":[]},{"id":"adf7805c.4aa278","type":"inject","z":"635b69bb.594868","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"whois.nic.ch","payload":"\"maremonti.ch\\n\"","payloadType":"json","x":190,"y":240,"wires":[["1664b053.a37ae","58b754fc.b65434"]]},{"id":"58b754fc.b65434","type":"debug","z":"635b69bb.594868","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":430,"y":200,"wires":[]}]

```

Vaughan, maybe you did this already. Then were are not much wiser. If not, please try this as in my test flow.  
Urs.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [30 May 2021 09:08 UTC](https://discourse.nodered.org/t/mqtt-to-ascii-over-tcp-ip/46438/8 "2021-05-30T09:08:42Z")

</div>

If you set the inject to send `ID\r` as a string then it will send exactly those characters... it does NOT escape the the \r to be a carriage return (or Enter key). If you set it to use JSON input then you can set it to `"ID\r"` and that does then escape the \r .

An alternative is to use a function node after the inject to do `msg.payload = msg.payload + "\r";` to then add it to any thing you inject.

---

<div class="post-metadata">

**Author:** ![vaughan.mcd](https://avatars.discourse-cdn.com/v4/letter/v/258eb7/32.png) [@vaughan.mcd](https://discourse.nodered.org/u/vaughan.mcd)\
**Post date:** [30 May 2021 10:48 UTC](https://discourse.nodered.org/t/mqtt-to-ascii-over-tcp-ip/46438/9 "2021-05-30T10:48:02Z")

</div>

Ok setting the inject node to JSON and with "ID\r" this worked.

Got the following response from device.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/8/b8a672228000b9c74b2b07dc8ee05e3f7e3cadb1.jpeg)

---

<div class="post-metadata">

**Author:** ![vaughan.mcd](https://avatars.discourse-cdn.com/v4/letter/v/258eb7/32.png) [@vaughan.mcd](https://discourse.nodered.org/u/vaughan.mcd)\
**Post date:** [30 May 2021 10:53 UTC](https://discourse.nodered.org/t/mqtt-to-ascii-over-tcp-ip/46438/10 "2021-05-30T10:53:44Z")

</div>

Thanks for everyone's input so far, I guess now I need to Convert this ASCII code to payload then send on to MQTT.

Any tips on the code I should use in the Function node to convert this ASCII code?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [30 May 2021 11:18 UTC](https://discourse.nodered.org/t/mqtt-to-ascii-over-tcp-ip/46438/11 "2021-05-30T11:18:26Z")

</div>

Node-red-contrib-buffer-parser can help you converting the bytes back to meaningful values.

---

<div class="post-metadata">

**Author:** ![vaughan.mcd](https://avatars.discourse-cdn.com/v4/letter/v/258eb7/32.png) [@vaughan.mcd](https://discourse.nodered.org/u/vaughan.mcd)\
**Post date:** [1 June 2021 08:15 UTC](https://discourse.nodered.org/t/mqtt-to-ascii-over-tcp-ip/46438/12 "2021-06-01T08:15:30Z")

</div>

Ok thanks any tip on how I can set the node up , Where do I start with this one?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/d/7dec710d259a98a883fe873329dc01d08d7b2d9b.jpeg)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 June 2021 08:23 UTC](https://discourse.nodered.org/t/mqtt-to-ascii-over-tcp-ip/46438/13 "2021-06-01T08:23:19Z")

</div>

> [@vaughan.mcd](#):
>
> Where do I start with this one?

Firstly, copy the buffer (use the "copy value" button that appears under your mouse when you hover over it)

then you paste that into an inject node set for buffer - so you can re-create the message any time you want.

Then using the manual for what the returned data means, add entries into the buffer parser as per the manual & test it by pressing the inject.

---

<div class="post-metadata">

**Author:** ![vaughan.mcd](https://avatars.discourse-cdn.com/v4/letter/v/258eb7/32.png) [@vaughan.mcd](https://discourse.nodered.org/u/vaughan.mcd)\
**Post date:** [1 June 2021 08:31 UTC](https://discourse.nodered.org/t/mqtt-to-ascii-over-tcp-ip/46438/14 "2021-06-01T08:31:54Z")

</div>

Ok ? isn't these values meant to be converted to ASCII to Normal Values?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/c/3c0b226246da27cd23dab101f0689fd2863a2fda.png)

I need to create something that can covert any ASCIi data strings right?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/9/6951ce6888144df1fcdd5cd3a02d719d897f5f50.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 June 2021 08:36 UTC](https://discourse.nodered.org/t/mqtt-to-ascii-over-tcp-ip/46438/15 "2021-06-01T08:36:36Z")

</div>

yes, however, what use is that? You should be making a useable formatted object, something like

```auto
{
  "id": "INWMPblahblahblah",
  "ip": "192.168.100.246",
  "version": "0.0.1",
  "value": -44
}

```

my point was, parse your response. - so capture a message & put it in an inject & you can inject & test & design until it looks correct / useful.

The buffer parser (or a function node if you want) can help you achieve this - but you will need to interpret the manual to understand the response.

---

<div class="post-metadata">

**Author:** ![vaughan.mcd](https://avatars.discourse-cdn.com/v4/letter/v/258eb7/32.png) [@vaughan.mcd](https://discourse.nodered.org/u/vaughan.mcd)\
**Post date:** [27 June 2021 10:22 UTC](https://discourse.nodered.org/t/mqtt-to-ascii-over-tcp-ip/46438/16 "2021-06-27T10:22:00Z")

</div>

Can you give me an example of how I want set up the buffer parser node, I cant get my head around this.

---

<div class="post-metadata">

**Author:** ![vaughan.mcd](https://avatars.discourse-cdn.com/v4/letter/v/258eb7/32.png) [@vaughan.mcd](https://discourse.nodered.org/u/vaughan.mcd)\
**Post date:** [27 June 2021 20:24 UTC](https://discourse.nodered.org/t/mqtt-to-ascii-over-tcp-ip/46438/17 "2021-06-27T20:24:59Z")

</div>

I had a break through and was able to get things to this point,

Would you recommend this setup for reading values from the device?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/0/f09b4d7f3c910ae42ed359f0b400536b76accc8e.jpeg)

---

<div class="post-metadata">

**Author:** ![tree-frog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tree-frog/32/89303_2.png) [@tree-frog](https://discourse.nodered.org/u/tree-frog)\
**Post date:** [27 June 2021 20:34 UTC](https://discourse.nodered.org/t/mqtt-to-ascii-over-tcp-ip/46438/18 "2021-06-27T20:34:54Z")

</div>

Are you using the fixed settings for the buffer parser? For example, If the buffer length changes, it will truncate your string or give you an error. You may want to consider setting the parameters in a message to the buffer parser. That is covered some in the help documentation in the buffer maker or buffer parser help. You would simply use a function node to modify the configuration in the message, as you send the message containing your payload buffer-parser value.

---

<div class="post-metadata">

**Author:** ![vaughan.mcd](https://avatars.discourse-cdn.com/v4/letter/v/258eb7/32.png) [@vaughan.mcd](https://discourse.nodered.org/u/vaughan.mcd)\
**Post date:** [27 June 2021 20:39 UTC](https://discourse.nodered.org/t/mqtt-to-ascii-over-tcp-ip/46438/19 "2021-06-27T20:39:03Z")

</div>

Yes it was configured as fix setting I will have a read about this.  
Can you give me an example of a function node set to do this?

---

<div class="post-metadata">

**Author:** ![tree-frog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tree-frog/32/89303_2.png) [@tree-frog](https://discourse.nodered.org/u/tree-frog)\
**Post date:** [27 June 2021 20:46 UTC](https://discourse.nodered.org/t/mqtt-to-ascii-over-tcp-ip/46438/20 "2021-06-27T20:46:00Z")

</div>

the best means for this is to read the documentation in the Help.

But first send your buffer to the node and then output the message to a Full Message debug node. Not the default, but change it to show the complete message in there you will find the "specification". you need an object similar to that but in the "spec". That is in the help. Create that information in your spec object and send it to the node.

I hope that gets you started. I can resume the discussion later tonight or tomorrow. Gotta run.

[Next page](https://discourse.nodered.org/t/mqtt-to-ascii-over-tcp-ip/46438.md?page=2)
