GPS tracker - TK103/TK10x

This flow is for GPS tracker devices that require a "logon" and "heartbeat" response, these have to be answered upon connection.

Change the TCP port to your liking.

In the Switch Node, decisions are made based on incoming traffic. The GPS tracker usually sends eg.:

Logon request: ##,imei:359586015829802,A;

Flow sends: LOAD

Heartbeat requests: 359586015829802;

Flow sends: ON

Change the switch node to match your imei.

End result is an object with converted longitude/latitude coordinates, speed etc. The format works with node-red-contrib-web-worldmap

Example sql statement is in the function node.

Send an SMS to your tracker: imei<passcode> to determine your imei

[{"id":"2671037d.537ca4","type":"tcp in","z":"619627e3.aaed6","name":"From GPS","server":"server","host":"","port":"5001","datamode":"stream","datatype":"utf8","newline":"","topic":"","base64":false,"x":100,"y":240,"wires":[["d47998cc.3cdfd","105016d3.1c63d1"]]},{"id":"bf4ef4f6.36852","type":"tcp out","z":"619627e3.aaed6","host":"","port":"","beserver":"reply","base64":false,"end":false,"name":"to GPS","x":780,"y":260,"wires":[]},{"id":"d47998cc.3cdfd","type":"switch","z":"619627e3.aaed6","name":"logon/heartbeat/tracker/move","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"##,imei:864180031021079,A;","vt":"str"},{"t":"eq","v":"864180031021079;","vt":"str"},{"t":"cont","v":"tracker","vt":"str"},{"t":"cont","v":"move","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":370,"y":280,"wires":[["971ae96c.693ab"],["e3ccc0b8.39479"],["579e60af.64dfb"],["579e60af.64dfb"]]},{"id":"971ae96c.693ab","type":"change","z":"619627e3.aaed6","name":"LOAD","rules":[{"t":"set","p":"payload","pt":"msg","to":"LOAD","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":240,"wires":[["bf4ef4f6.36852"]]},{"id":"579e60af.64dfb","type":"function","z":"619627e3.aaed6","name":"To object or SQL","func":"\n//   Incoming data\n//   [0] => imei:864180031021079\n//   [1] => tracker,\n//   [2] => 170805122543,\n//   [3] => ,\n//   [4] => F,\n//   [5] => 112540.000,\n//   [6] => A,\n//   [7] => 5208.3026,\n//   [8] => N,\n//   [9] => 00428.1723,\n//   [10] => E,\n//   [11] => 0.00,\n//   [12] => 0; \n\n\nfunction convertlatlon(lat,lon){\n\n    latout = (Math.floor(lat / 100) + (lat - 100 * Math.floor(lat / 100)) / 60).toFixed(5);\n    lonout = (Math.floor(lon / 100) + (lon - 100 * Math.floor(lon / 100)) / 60).toFixed(5);\n\n    return [latout,lonout];\n }\n\nflow.set(\"session\",msg._session)\n\nvar today = new Date();\nvar date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();\nvar time = today.getHours() + \":\" + today.getMinutes() + \":\" + today.getSeconds();\n\nm = msg.payload\nt = m.split(\",\")\nlatitude = t[7]\nlongitude = t[9]\nlatlon = convertlatlon(latitude,longitude)\n\n\nimei = t[0];\nstatus = t[1];\ntrackerdate = t[2]\n\nsatelliteDerivedTime = t[5];\nsatelliteFixStatus = t[6];\ntimestamp = t[2];\nlatitudeDecimalDegrees = latlon[0];\nlatitudeHemisphere = t[8];\nlongitudeDecimalDegrees = latlon[1];\nlongitudeHemisphere = t[10];\nbearing = ''\nutcDate = ''\nspeed = t[11]\ngpsSignalIndicator = t[4]\ncurrdate = date+' '+time;\nother = t[12]\nchecksum = ''\n\n// For SQL usage:\n// sql = \"INSERT INTO gprmc (locationdate, imei, phone, trackerdate, satelliteDerivedTime, satelliteFixStatus, latitudeDecimalDegrees, latitudeHemisphere, longitudeDecimalDegrees, longitudeHemisphere, speed, Bearing, utcDate, Checksum, gpsSignalIndicator, other) VALUES ('\"+currdate+\"', '\"+imei+\"', '\"+phone+\"', '\"+trackerdate+\"', '\"+satelliteDerivedTime+\"', '\"+satelliteFixStatus+\"', '\"+latitudeDecimalDegrees+\"', '\"+latitudeHemisphere+\"', '\"+longitudeDecimalDegrees+\"', '\"+longitudeHemisphere+\"', '\"+speed+\"', '\"+bearing+\"', '\"+utcDate+\"', '\"+checksum+\"', '\"+gpsSignalIndicator+\"', '\"+other+\"')\"\n// return {topic:sql}\n\nreturn {payload:{\n\tlocationdate:currdate,\n\timei:imei,\n\tstatus:status,\n\ttrackerdate:trackerdate,\n\tsatelliteDerivedTime:satelliteDerivedTime,\n\tsatelliteFixStatus:satelliteFixStatus,\n\tlatitudeDecimalDegrees:latitudeDecimalDegrees,\n\tlatitudeHemisphere:latitudeHemisphere,\n\tlongitudeDecimalDegrees:longitudeDecimalDegrees,\n\tlongitudeHemisphere:longitudeHemisphere,\n\tspeed:speed,\n\tbearing:bearing,\n\tutcDate:utcDate,\n\tchecksum:checksum,\n\tgpsSignalIndicator:gpsSignalIndicator\t\n\n}}\n\n\n","outputs":1,"noerr":0,"x":650,"y":320,"wires":[["f27c551d.6089b"]]},{"id":"e3ccc0b8.39479","type":"change","z":"619627e3.aaed6","name":"ON","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":280,"wires":[["bf4ef4f6.36852"]]},{"id":"f27c551d.6089b","type":"debug","z":"619627e3.aaed6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":810,"y":320,"wires":[]},{"id":"105016d3.1c63d1","type":"debug","z":"619627e3.aaed6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":290,"y":220,"wires":[]},{"id":"f485b01e.782728","type":"inject","z":"619627e3.aaed6","name":"Test input","topic":"","payload":"imei:864180031021079,tracker,190310160322,,F,170317.000,A,5208.3287,N,00428.1048,E,0.00,0;","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":280,"wires":[["d47998cc.3cdfd","105016d3.1c63d1"]]},{"id":"e6d551b3.db315","type":"comment","z":"619627e3.aaed6","name":"TK102B based GPS tracker - see info","info":"This flow is for GPS tracker devices that require a \"logon\" and \"heartbeat\" response, these have to be answered upon connection.\n\nChange the TCP port to your liking.\n\nIn the Switch Node, decisions are made based on incoming traffic. \nThe GPS tracker usually sends eg.:\n\nLogon request: ```##,imei:359586015829802,A;``` \n\nFlow sends: ```LOAD``` \n\n\nHeartbeat requests: ```359586015829802;``` \n\nFlow sends: ```ON```\n\nChange the switch node to match your imei.\n\nEnd result is an object with converted longitude/latitude coordinates, speed etc.\nThe format works with [node-red-contrib-web-worldmap](https://flows.nodered.org/node/node-red-contrib-web-worldmap)\n\nExample sql statement is in the function node.\n\n\nSend an SMS to your tracker: ```imei<passcode>``` to determine your imei\n","x":190,"y":160,"wires":[]}]

Flow Info

Created 6 years, 10 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • change (x2)
  • comment (x1)
  • debug (x2)
  • function (x1)
  • inject (x1)
  • switch (x1)
  • tcp in (x1)
  • tcp out (x1)

Tags

  • gps
  • tracker
  • map
  • tk103
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option