Hi,
I was able to get data from a mavlink stream and a serial input.
I implement a delay to limit the output rate to 1 second for all data.
Somehow the data output can be mixup and I get gas data first followed by mavlink or the other way around. I tried to implement a "sorts" node but it does'nt work. I need your help:)
In the functions nodes, I add a topic, key and parts number to the msg of each data. My idea was to sort the output base on this. It dont work. I feel this come from the fact that mavlink is an object while serial in is float.
The serial stream is this exact formatted string --> D, 1111.1,1111.11,1111.1\r where the 1111 change and are in fact float value. They are parsed and tag when they get in.
this is my flow.
[
{
"id": "055aa8fd1f8a8f4e",
"type": "tab",
"label": "Flow 2",
"disabled": false,
"info": "",
"env": []
},
{
"id": "7c6626e8bf2da44f",
"type": "websocket in",
"z": "055aa8fd1f8a8f4e",
"name": "heartbeat",
"server": "397172b08ff52a59",
"client": "",
"x": 140,
"y": 80,
"wires": [
[
"4e1e4d987636f511"
]
]
},
{
"id": "4e1e4d987636f511",
"type": "json",
"z": "055aa8fd1f8a8f4e",
"name": "messages",
"property": "payload",
"action": "obj",
"pretty": false,
"x": 310,
"y": 80,
"wires": [
[
"cf22c4ccac44da55",
"f43b7be2f74a58b8"
]
]
},
{
"id": "cf22c4ccac44da55",
"type": "switch",
"z": "055aa8fd1f8a8f4e",
"name": "MAvLink_split",
"property": "payload.message.type",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "BATTERY_STATUS",
"vt": "str"
},
{
"t": "eq",
"v": "GPS_RAW_INT",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 520,
"y": 80,
"wires": [
[
"fb1a25da9fe782ba"
],
[
"e3de8131253b36cf"
]
]
},
{
"id": "fb1a25da9fe782ba",
"type": "function",
"z": "055aa8fd1f8a8f4e",
"name": "vBatt",
"func": "msg.payload = msg.payload.message.voltages[0] / 1000.00\nmsg.topic = \"Voltage\"\nmsg.key = 1\nmsg.parts = 1\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 750,
"y": 60,
"wires": [
[
"5c91fb558c0c86a9"
]
]
},
{
"id": "e3de8131253b36cf",
"type": "function",
"z": "055aa8fd1f8a8f4e",
"name": "lat",
"func": "msg.payload = msg.payload.message.lat\nmsg.topic = \"latitude\"\nmsg.key = 2\nmsg.parts = 2\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 750,
"y": 120,
"wires": [
[
"5c91fb558c0c86a9"
]
]
},
{
"id": "5c91fb558c0c86a9",
"type": "delay",
"z": "055aa8fd1f8a8f4e",
"name": "",
"pauseType": "timed",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": true,
"allowrate": false,
"outputs": 1,
"x": 1070,
"y": 220,
"wires": [
[
"c456570e893e8283"
]
]
},
{
"id": "c456570e893e8283",
"type": "debug",
"z": "055aa8fd1f8a8f4e",
"name": "Output",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"statusVal": "payload",
"statusType": "auto",
"x": 1280,
"y": 40,
"wires": []
},
{
"id": "98e33ae787dd77cd",
"type": "serial in",
"z": "055aa8fd1f8a8f4e",
"name": "Sensor_port",
"serial": "1a0db8d82e42aefd",
"x": 130,
"y": 300,
"wires": [
[
"3c6a2469bd653496"
]
]
},
{
"id": "3c6a2469bd653496",
"type": "function",
"z": "055aa8fd1f8a8f4e",
"name": "function 2",
"func": "var elements = msg.payload.split(\",\");\nmsg.payload = {\n A: parseFloat(elements[1]),\n B: parseFloat(elements[2]),\n C: parseFloat(elements[3]), \n}\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 320,
"y": 300,
"wires": [
[
"ee9650c9b9db9cad",
"0b43e1183e307ee9",
"e41997e8a632ad3c"
]
]
},
{
"id": "ee9650c9b9db9cad",
"type": "function",
"z": "055aa8fd1f8a8f4e",
"name": "Gas_A_data",
"func": "msg.payload = msg.payload.A\nmsg.topic = \"gas_A\"\nmsg.key = 3\nmsg.parts = 3\nreturn msg",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 750,
"y": 300,
"wires": [
[
"5c91fb558c0c86a9"
]
]
},
{
"id": "0b43e1183e307ee9",
"type": "function",
"z": "055aa8fd1f8a8f4e",
"name": "Gas_B_data",
"func": "msg.payload = msg.payload.B\nmsg.topic = \"gas_B\"\nmsg.key = 4\nmsg.parts = 4\nreturn msg",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 750,
"y": 380,
"wires": [
[
"5c91fb558c0c86a9"
]
]
},
{
"id": "e41997e8a632ad3c",
"type": "function",
"z": "055aa8fd1f8a8f4e",
"name": "mBar_data",
"func": "msg.payload = msg.payload.C\nmsg.topic = \"mBar\"\nmsg.key = 5\nmsg.parts = 5\nreturn msg",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 750,
"y": 460,
"wires": [
[
"5c91fb558c0c86a9"
]
]
},
{
"id": "f43b7be2f74a58b8",
"type": "debug",
"z": "055aa8fd1f8a8f4e",
"name": "debug 27",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"statusVal": "payload",
"statusType": "auto",
"x": 470,
"y": 180,
"wires": []
},
{
"id": "397172b08ff52a59",
"type": "websocket-listener",
"path": "ws://192.168.2.2/mavlink2rest/ws/mavlink",
"wholemsg": "false"
},
{
"id": "1a0db8d82e42aefd",
"type": "serial-port",
"name": "Serial_In",
"serialport": "/dev/ttyAMA2",
"serialbaud": "115200",
"databits": "8",
"parity": "none",
"stopbits": "1",
"waitfor": "D",
"dtr": "none",
"rts": "none",
"cts": "none",
"dsr": "none",
"newline": "\\r",
"bin": "false",
"out": "char",
"addchar": "",
"responsetimeout": "1000"
}
]