Codec JSON by TCP

I’m reading the JSON received by TCP but when I try to send a command, like setdigout 1?0 , don’t do nothing!
Here is a example code:

socket.write(Buffer.from(({ "CMD": "setdigout 1?0" }).toString('hex'), "hex"));
socket.on('data', (data) => {
		data = Buffer.from(data, "hex").toString('utf8').trim();
		if(data.length <= 15) {
			console.log(data.length);
			console.log(data);
		} else {
			data = JSON.parse(JSON.stringify(data));
			console.log(data);
		}
		
});

Hi,
Are you using which platform azure or AWS?

Best Regards
Maynard C

I’m creating my own server in NodeJS.

I’m afraid that the writing json string into raw socket won’t work.
Communication must comply with the MQTT protocol.
In a node environment, try the mqtt.js package.

1 Like

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