Skip to content

Instantly share code, notes, and snippets.

@xyrox2

xyrox2/README.md Secret

Created June 29, 2017 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xyrox2/73e1776e5696d218109add612646c6a3 to your computer and use it in GitHub Desktop.
Save xyrox2/73e1776e5696d218109add612646c6a3 to your computer and use it in GitHub Desktop.
Test IoT
[{
"id": "5a67cd69.af4de4",
"type": "function",
"z": "34c702a4.cb38fe",
"name": "setArgs2",
"func": "if(msg.payload.length > 0 && msg.payload[0] && msg.payload[0].link_id){\n // MapMatch result becomes list and the first one is nearest link_id\n msg.link_id = msg.payload[0].link_id;\n // msg.trip_id\n msg.matched_heading = msg.payload[0].matched_heading;\n msg.matched_longitude = msg.payload[0].matched_longitude;\n msg.matched_latitude = msg.payload[0].matched_latitude;\n // msg.mo_id\n \n msg.payload = null;\n \n return [msg, null];\n}else{\n msg.link_id = '';\n msg.matched_heading = msg.rawData.heading;\n msg.matched_longitude = msg.rawData.longitude;\n msg.matched_latitude = msg.rawData.latitude;\n return [null, msg];\n}\n",
"outputs": "2",
"noerr": 0,
"x": 602,
"y": 298.28570556640625,
"wires": [["add978b6.091ae8",
"12662b88.b8d154"],
["6fda7a1e.da3064"]]
},{
"id": "22d0375f.359f38",
"type": "ibmiot in",
"z": "34c702a4.cb38fe",
"authentication": "boundService",
"apiKey": "",
"inputType": "evt",
"deviceId": "",
"applicationId": "",
"deviceType": "+",
"eventType": "+",
"commandType": "",
"format": "json",
"name": "IBM IoT",
"service": "registered",
"allDevices": true,
"allApplications": "",
"allDeviceTypes": true,
"allEvents": true,
"allCommands": "",
"allFormats": "",
"x": 144.625,
"y": 130.35714721679688,
"wires": [["5d1140dc.1ce48",
"5793edd9.9635a4"]]
},{
"id": "8f34f0d7.030e3",
"type": "http request",
"z": "34c702a4.cb38fe",
"name": "carProbe",
"method": "POST",
"ret": "obj",
"url": "https://{{driverHostname}}/driverinsights/datastore/carProbe?tenant_id={{driverTenantId}}",
"x": 375.375,
"y": 505.0357074737549,
"wires": [["698d4f42.3e8e9"]]
},{
"id": "9c57021f.6a623",
"type": "function",
"z": "34c702a4.cb38fe",
"name": "setArgs1",
"func": "\nmsg.rawData = msg.payload.d;\n\n// '+' must be URL encoded\n//msg.timestamp = encodeURIComponent(msg.payload.timestamp);\nmsg.timestamp = msg.rawData.timestamp;\nmsg.heading = msg.rawData.heading;\nmsg.mo_id = msg.deviceId;\nmsg.trip_id = msg.rawData.trip_id;\nmsg.longitude = msg.rawData.longitude;\nmsg.latitude = msg.rawData.latitude;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 174.625,
"y": 293.7856750488281,
"wires": [["82743408.064ba8",
"fda52541.63d528"]]
},{
"id": "698d4f42.3e8e9",
"type": "debug",
"z": "34c702a4.cb38fe",
"name": "",
"active": true,
"console": "false",
"complete": "true",
"x": 516.875,
"y": 506.03570556640625,
"wires": []
},{
"id": "82743408.064ba8",
"type": "debug",
"z": "34c702a4.cb38fe",
"name": "",
"active": false,
"console": "false",
"complete": "true",
"x": 230.625,
"y": 354.7856903076172,
"wires": []
},{
"id": "fda52541.63d528",
"type": "http request",
"z": "34c702a4.cb38fe",
"name": "mapMatching",
"method": "GET",
"ret": "obj",
"url": "https://{{mapHostname}}/mapinsights/mapservice/map/matching?tenant_id={{mapTenantId}}&heading={{heading}}&mo_id={{mo_id}}&trip_id={{trip_id}}&longitude={{longitude}}&latitude={{latitude}}",
"x": 367.75,
"y": 293.2856903076172,
"wires": [["5a67cd69.af4de4",
"f588b73.c04f548"]]
},{
"id": "6fda7a1e.da3064",
"type": "function",
"z": "34c702a4.cb38fe",
"name": "setArgs3",
"func": "var type = null;\nif(msg.payload.links && msg.payload.links[0] && msg.payload.links[0].properties && msg.payload.links[0].properties.type){\n type = msg.payload.links[0].properties.type;\n}else {\n type = '5';\n}\n\n\nmsg.payload = {};\n\nmsg.payload.road_type = type;\nmsg.payload.trip_id = msg.trip_id;\nmsg.payload.timestamp = msg.rawData.timestamp;\nmsg.payload.matched_heading = msg.matched_heading;\nmsg.payload.speed = msg.rawData.speed;\nmsg.payload.matched_longitude = msg.matched_longitude;\nmsg.payload.mo_id = msg.deviceId;\nmsg.payload.matched_latitude = msg.matched_latitude;\nmsg.payload.matched_link_id = msg.link_id;\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 174.75,
"y": 502.03570556640625,
"wires": [["8f34f0d7.030e3",
"1afc4826.0d2a38"]]
},{
"id": "f588b73.c04f548",
"type": "debug",
"z": "34c702a4.cb38fe",
"name": "",
"active": true,
"console": "false",
"complete": "true",
"x": 506.5,
"y": 214.28570556640625,
"wires": []
},{
"id": "add978b6.091ae8",
"type": "http request",
"z": "34c702a4.cb38fe",
"name": " getLinkInformation",
"method": "GET",
"ret": "obj",
"url": "https://{{mapHostname}}/mapinsights/mapservice/link?tenant_id={{mapTenantId}}&link_id={{link_id}}",
"x": 857.25,
"y": 301.03570556640625,
"wires": [["6fda7a1e.da3064",
"5d32bca7.d7b174"]]
},{
"id": "5d32bca7.d7b174",
"type": "debug",
"z": "34c702a4.cb38fe",
"name": "",
"active": false,
"console": "false",
"complete": "true",
"x": 1009.25,
"y": 255.28570556640625,
"wires": []
},{
"id": "12662b88.b8d154",
"type": "debug",
"z": "34c702a4.cb38fe",
"name": "",
"active": false,
"console": "false",
"complete": "true",
"x": 757.25,
"y": 163.53570556640625,
"wires": []
},{
"id": "1afc4826.0d2a38",
"type": "debug",
"z": "34c702a4.cb38fe",
"name": "",
"active": false,
"console": "false",
"complete": "true",
"x": 264.75,
"y": 557.5357055664062,
"wires": []
},{
"id": "5d1140dc.1ce48",
"type": "debug",
"z": "34c702a4.cb38fe",
"name": "",
"active": false,
"console": "false",
"complete": "true",
"x": 293.3035583496094,
"y": 85,
"wires": []
},{
"id": "5793edd9.9635a4",
"type": "function",
"z": "34c702a4.cb38fe",
"name": "Common Config",
"func": "msg.mapTenantId = \"FIX-ME\";\nmsg.driverTenantId = \"FIX-ME\";\nmsg.mapHostname =\"automotive.internetofthings.ibmcloud.com\";\nmsg.driverHostname = \"automotive.internetofthings.ibmcloud.com\";\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 428.125,
"y": 130.78570556640625,
"wires": [["9c57021f.6a623"]]
}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment