# Sending json data via tcp/ip node with start and end delimiters (tcam-mini)

**URL:** <https://discourse.nodered.org/t/sending-json-data-via-tcp-ip-node-with-start-and-end-delimiters-tcam-mini/96184>\
**Category:** General\
**Created:** [23 March 2025 07:30 UTC](https://discourse.nodered.org/t/sending-json-data-via-tcp-ip-node-with-start-and-end-delimiters-tcam-mini/96184 "2025-03-23T07:30:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![letshin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/letshin/32/51665_2.png) [@letshin](https://discourse.nodered.org/u/letshin)\
**Post date:** [23 March 2025 07:30 UTC](https://discourse.nodered.org/t/sending-json-data-via-tcp-ip-node-with-start-and-end-delimiters-tcam-mini/96184/1 "2025-03-23T07:30:58Z")

</div>

Hi, I'm trying to communicate via a tcp/ip node with a thermal camera board. The documentation is here ([tCam/tCam-Mini/firmware at main · danjulio/tCam · GitHub](https://github.com/danjulio/tCam/tree/main/tCam-Mini/firmware)), and it says that a json command with a start delimited (0x02) and an end delimter (0x03) can be used; IE `<0x02><json string><0x03>`.

The example given is

```auto
{"cmd":"get_status"}

```

Which returns

```auto
{
	"status": {
		"Camera":"tCam-Mini-EFB5",
		"Model":262402,
		"Version":"2.0",
		"Time":"17:33:49.0",
		"Date":"2/3/21"
	}
}

```

I have tried variants of `get_status`,`\\2 get_status \\3` as `msg.payload` using the inject node into the tcp request node; and also eg `msg.payload = { "cmd": Buffer.concat([buf1, buf2, buf3]).toString()}` in a function node where `buf1` is `0x02`, `buf2` is the string and `buf3` is `0x03`;  
but am not getting a response. The flow I've used for the latter is below. Can anyone offer advise on how to incorporate the start and end delimiters please? Thanks

```auto
[{"id":"2ba4eeddcd7dbac0","type":"tcp request","z":"0bf00a3cf0d0d07d","name":"","server":"10.20.30.105","port":"5001","out":"time","ret":"string","splitc":"1000","newline":"","trim":false,"tls":"","x":460,"y":220,"wires":[["11f3972e6975e8b7"]]},{"id":"b1c269f80afc8b20","type":"inject","z":"0bf00a3cf0d0d07d","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"cmd\":\"\\\\2 get_status \\\\3\"}","payloadType":"json","x":110,"y":220,"wires":[["2ba4eeddcd7dbac0","2093eef66e9bf6e8"]]},{"id":"11f3972e6975e8b7","type":"debug","z":"0bf00a3cf0d0d07d","name":"debug 20","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":760,"y":220,"wires":[]},{"id":"2093eef66e9bf6e8","type":"debug","z":"0bf00a3cf0d0d07d","name":"debug 21","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":500,"y":320,"wires":[]}]

```

---

<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:** [23 March 2025 09:17 UTC](https://discourse.nodered.org/t/sending-json-data-via-tcp-ip-node-with-start-and-end-delimiters-tcam-mini/96184/2 "2025-03-23T09:17:03Z")

</div>

The numbers 2 and 3 are ASCII STX (start of text) and ETX (end of text) characters and are typically added to the very beginning and end of the data (not inside like you are attempting).

Add this to a function node immediately before the TCP node:

```auto
  const STX = '\x02';
  const ETX = '\x03';

  if (typeof msg.payload === 'object') {
    msg.payload = STX + JSON.stringify(msg.payload) + ETX;
  } else if (typeof msg.payload === 'string') {
    msg.payload = STX + msg.payload + ETX;
  } else {
    msg.payload = STX + String(msg.payload) + ETX;
  }

  return msg;

```

---

<div class="post-metadata">

**Author:** ![letshin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/letshin/32/51665_2.png) [@letshin](https://discourse.nodered.org/u/letshin)\
**Post date:** [23 March 2025 10:13 UTC](https://discourse.nodered.org/t/sending-json-data-via-tcp-ip-node-with-start-and-end-delimiters-tcam-mini/96184/3 "2025-03-23T10:13:46Z")

</div>

Ah, makes sense. Thank you.

---

<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:** [6 April 2025 10:14 UTC](https://discourse.nodered.org/t/sending-json-data-via-tcp-ip-node-with-start-and-end-delimiters-tcam-mini/96184/4 "2025-04-06T10:14:01Z")

</div>

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