Hex String to IP device in Muse Automator
Question:
How can I send a Hex string to an IP device using Muse Automator.
Answer:
You can use a function node to create the Hex string and return that string in msg.payload.
An example of the code for the function node would be as follows.
var Arr1 = Buffer.from([0x02, 0x88, 0x30, 0x0B, 0x1B, 0x83, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB0, 0x03]);
msg.payload = Arr1;
return msg;
The following is an example flow, that can be imported into Muse Automator, that uses this function node. When the inject node is activated that will trigger the function node to send a hex string to a TCP request node. The debug node at the end of the flow would receive any responses from the connected device.
[
{
"id": "cb5ab37eea3e95f9",
"type": "tab",
"label": "Hex String Function Example",
"disabled": false,
"info": "",
"env": []
},
{
"id": "596d23da778d3345",
"type": "function",
"z": "cb5ab37eea3e95f9",
"name": "Hex String Function",
"func": "var Arr1 = Buffer.from([0x02, 0x88, 0x30, 0x0B, 0x1B, 0x83, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB0, 0x03]);\nmsg.payload = Arr1;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 390,
"y": 280,
"wires": [
[
"9a4790cd86a90b11"
]
]
},
{
"id": "3372f9ee7f51defb",
"type": "inject",
"z": "cb5ab37eea3e95f9",
"name": "Inject",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 190,
"y": 280,
"wires": [
[
"596d23da778d3345"
]
]
},
{
"id": "9a4790cd86a90b11",
"type": "tcp request",
"z": "cb5ab37eea3e95f9",
"name": "",
"server": "192.168.1.100",
"port": "23",
"out": "sit",
"ret": "buffer",
"splitc": " ",
"newline": "",
"trim": false,
"tls": "",
"x": 730,
"y": 280,
"wires": [
[
"8500d4b027a3c7be"
]
]
},
{
"id": "8500d4b027a3c7be",
"type": "debug",
"z": "cb5ab37eea3e95f9",
"name": "debug 31",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 920,
"y": 280,
"wires": []
}
]