Skip to content

Instantly share code, notes, and snippets.

@amotl
Created January 19, 2020 11:23
Show Gist options
  • Select an option

  • Save amotl/53489f65ea769d5c6118afbd65aa92a3 to your computer and use it in GitHub Desktop.

Select an option

Save amotl/53489f65ea769d5c6118afbd65aa92a3 to your computer and use it in GitHub Desktop.
Node-RED flow to forward OVMS location information to OwnTracks
[
{
"id": "89e9d395.f358",
"type": "mqtt in",
"z": "d605de2e.9f01e",
"name": "",
"topic": "ovms/emonpi/<VEHICLE-ID>/metric/v/p/latitude",
"qos": "0",
"broker": "42d1a439.248b0c",
"x": 200,
"y": 60,
"wires": [
[
"a434b606.26e328"
]
]
},
{
"id": "c9be458f.e2e928",
"type": "mqtt in",
"z": "d605de2e.9f01e",
"name": "",
"topic": "ovms/emonpi/<VEHICLE-ID>/metric/v/p/longitude",
"qos": "0",
"broker": "42d1a439.248b0c",
"x": 200,
"y": 100,
"wires": [
[
"b2f98901.84ec48"
]
]
},
{
"id": "dd774d3a.647f2",
"type": "function",
"z": "d605de2e.9f01e",
"name": "context.global.lat",
"func": "context.global.lat = msg.payload;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 710,
"y": 80,
"wires": [
[
"9656d4f7.b65408"
]
]
},
{
"id": "3087ba49.6ce996",
"type": "function",
"z": "d605de2e.9f01e",
"name": "context.global.lon",
"func": "context.global.lon = msg.payload;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 710,
"y": 120,
"wires": [
[]
]
},
{
"id": "9656d4f7.b65408",
"type": "debug",
"z": "d605de2e.9f01e",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"x": 930,
"y": 80,
"wires": []
},
{
"id": "a434b606.26e328",
"type": "function",
"z": "d605de2e.9f01e",
"name": "ignore 0",
"func": "var value=msg.payload;\n// if (value !==\"\" && value !==\"0\" && value !==0 );{\nif (value){\n return msg;\n}\n",
"outputs": 1,
"noerr": 0,
"x": 480,
"y": 80,
"wires": [
[
"dd774d3a.647f2"
]
]
},
{
"id": "b2f98901.84ec48",
"type": "function",
"z": "d605de2e.9f01e",
"name": "ignore 0",
"func": "var value=msg.payload;\n// if (value !==\"\" && value !==\"0\" && value !==0 );{\nif (value){\n return msg;\n}\n",
"outputs": 1,
"noerr": 0,
"x": 480,
"y": 120,
"wires": [
[
"3087ba49.6ce996"
]
]
},
{
"id": "f4ec6fc4.4dcaa",
"type": "inject",
"z": "d605de2e.9f01e",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "60",
"crontab": "",
"once": false,
"onceDelay": "60",
"x": 90,
"y": 260,
"wires": [
[
"e9f44233.cddf6"
]
]
},
{
"id": "a61cddc0.6c138",
"type": "function",
"z": "d605de2e.9f01e",
"name": "create object",
"func": "var owntracks={_type:\"location\",tst:msg.payload,lat:Number(context.global.lat),lon:Number(context.global.lon)};\nvar newMsg = { payload: JSON.stringify(owntracks) };\nreturn newMsg;",
"outputs": 1,
"noerr": 0,
"x": 450,
"y": 260,
"wires": [
[
"4b6d9633.eead28",
"a5474c90.c79c4",
"55689f77.2efd3"
]
]
},
{
"id": "4b6d9633.eead28",
"type": "debug",
"z": "d605de2e.9f01e",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"x": 930,
"y": 260,
"wires": []
},
{
"id": "a5474c90.c79c4",
"type": "mqtt out",
"z": "d605de2e.9f01e",
"name": "",
"topic": "owntracks/my/car",
"qos": "",
"retain": "",
"broker": "834ac211.8eba8",
"x": 730,
"y": 300,
"wires": []
},
{
"id": "55689f77.2efd3",
"type": "file",
"z": "d605de2e.9f01e",
"name": "",
"filename": "/data/gps-json.csv",
"appendNewline": true,
"createDir": false,
"overwriteFile": "false",
"x": 770,
"y": 200,
"wires": [
[]
]
},
{
"id": "e9f44233.cddf6",
"type": "function",
"z": "d605de2e.9f01e",
"name": "timestamp in s",
"func": "// msg.payload = msg.payload/1000;\nmsg.payload = Math.floor(Date.now() / 1000);\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 260,
"y": 260,
"wires": [
[
"a61cddc0.6c138"
]
]
},
{
"id": "42d1a439.248b0c",
"type": "mqtt-broker",
"z": "",
"name": "emonpi",
"broker": "IP-ADDRESS",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willPayload": ""
},
{
"id": "834ac211.8eba8",
"type": "mqtt-broker",
"z": "",
"name": "MQTT-SERVER",
"broker": "IP-ADDRESS",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willPayload": ""
}
]
@ethan4
Copy link
Copy Markdown

ethan4 commented Sep 24, 2020

Thanks for posting this (and to @glynhudson). Exactly what I was looking for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment