Skip to content

Instantly share code, notes, and snippets.

@eschava
Created March 26, 2018 10:10
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 eschava/59d1529d5cc479995dd5799fd4ea188d to your computer and use it in GitHub Desktop.
Save eschava/59d1529d5cc479995dd5799fd4ea188d to your computer and use it in GitHub Desktop.
GPS watch

Creates a TCP server for GPS Watches (usually Chinese, like Smart Baby Watch) and analyzes received data. Also has ability to send simple commands to watches (show message, request location, etc)

[
{
"id": "4f34fe7a.28ec2",
"type": "tcp in",
"z": "bfdbbee.bfabd4",
"name": "",
"server": "server",
"host": "",
"port": "8002",
"datamode": "stream",
"datatype": "utf8",
"newline": "]",
"topic": "",
"base64": false,
"x": 220,
"y": 150,
"wires": [
[
"33e678d5.e9fdf8",
"b342b5ec.58c288"
]
]
},
{
"id": "33e678d5.e9fdf8",
"type": "debug",
"z": "bfdbbee.bfabd4",
"name": "watch receive",
"active": true,
"tosidebar": true,
"console": true,
"tostatus": true,
"complete": "payload",
"x": 430,
"y": 100,
"wires": []
},
{
"id": "35182fa.fe493d",
"type": "tcp out",
"z": "bfdbbee.bfabd4",
"host": "",
"port": "",
"beserver": "reply",
"base64": false,
"end": false,
"name": "",
"x": 1000,
"y": 420,
"wires": []
},
{
"id": "4ecd1fc3.8bf75",
"type": "change",
"z": "bfdbbee.bfabd4",
"name": "LK",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "LK",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 510,
"y": 310,
"wires": [
[
"bd068d2b.51a4"
]
]
},
{
"id": "99c36ea0.d14a9",
"type": "inject",
"z": "bfdbbee.bfabd4",
"name": "1❤",
"topic": "",
"payload": "1",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 210,
"y": 260,
"wires": [
[
"fef33a6a.aba838"
]
]
},
{
"id": "58bd9c65.dea714",
"type": "inject",
"z": "bfdbbee.bfabd4",
"name": "2❤",
"topic": "",
"payload": "2",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 210,
"y": 300,
"wires": [
[
"fef33a6a.aba838"
]
]
},
{
"id": "532b4d7.6594bb4",
"type": "template",
"z": "bfdbbee.bfabd4",
"name": "format",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "{{id}}*{{length}}*{{payload}}{{param}}]",
"output": "str",
"x": 760,
"y": 420,
"wires": [
[
"35182fa.fe493d",
"9444bf88.b7f64"
]
]
},
{
"id": "f2af699a.c38fd8",
"type": "change",
"z": "bfdbbee.bfabd4",
"name": "save session",
"rules": [
{
"t": "set",
"p": "sesion",
"pt": "flow",
"to": "_session",
"tot": "msg"
},
{
"t": "set",
"p": "id",
"pt": "flow",
"to": "parts[0] & '*' & parts[1]",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 840,
"y": 130,
"wires": [
[]
]
},
{
"id": "3a7bcf60.91782",
"type": "change",
"z": "bfdbbee.bfabd4",
"name": "load session",
"rules": [
{
"t": "set",
"p": "_sesion",
"pt": "msg",
"to": "session",
"tot": "flow"
},
{
"t": "set",
"p": "id",
"pt": "msg",
"to": "id",
"tot": "flow"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 780,
"y": 370,
"wires": [
[
"532b4d7.6594bb4"
]
]
},
{
"id": "c3ef72fd.56d72",
"type": "switch",
"z": "bfdbbee.bfabd4",
"name": "command",
"property": "parts[3]",
"propertyType": "msg",
"rules": [
{
"t": "regex",
"v": "^LK",
"vt": "str",
"case": false
},
{
"t": "regex",
"v": "^UD",
"vt": "str",
"case": false
},
{
"t": "regex",
"v": "^UD2",
"vt": "str",
"case": false
}
],
"checkall": "false",
"repair": false,
"outputs": 3,
"x": 580,
"y": 190,
"wires": [
[
"4ecd1fc3.8bf75",
"f2af699a.c38fd8",
"af4eb8c4.a11aa8"
],
[
"d55df99a.879808"
],
[
"d55df99a.879808"
]
],
"outputLabels": [
"LK",
"UD",
"UD2"
]
},
{
"id": "725f7c10.07e2a4",
"type": "inject",
"z": "bfdbbee.bfabd4",
"name": "",
"topic": "",
"payload": "привет",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 210,
"y": 370,
"wires": [
[
"1a206769.2e69b9"
]
]
},
{
"id": "9444bf88.b7f64",
"type": "debug",
"z": "bfdbbee.bfabd4",
"name": "watch send",
"active": true,
"tosidebar": false,
"console": false,
"tostatus": true,
"complete": "payload",
"x": 1020,
"y": 470,
"wires": []
},
{
"id": "f5c92b1a.df0158",
"type": "inject",
"z": "bfdbbee.bfabd4",
"name": "",
"topic": "",
"payload": "hello",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 210,
"y": 410,
"wires": [
[
"1a206769.2e69b9"
]
]
},
{
"id": "1a206769.2e69b9",
"type": "function",
"z": "bfdbbee.bfabd4",
"name": "hex",
"func": "var buf = Buffer.from(msg.payload, 'utf16le');\nbuf.swap16();\nmsg.payload = buf.toString('hex');\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 360,
"y": 390,
"wires": [
[
"b6c13ed3.812be"
]
]
},
{
"id": "bd068d2b.51a4",
"type": "function",
"z": "bfdbbee.bfabd4",
"name": "hex(length)",
"func": "var len = msg.payload.length\nif (msg.param)\n len += msg.param.toString().length\nmsg.length = (len+0x10000).toString(16).substr(-4)\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 770,
"y": 310,
"wires": [
[
"3a7bcf60.91782"
]
]
},
{
"id": "345ea465.ff95ac",
"type": "inject",
"z": "bfdbbee.bfabd4",
"name": "TZ+2",
"topic": "",
"payload": "+2",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 210,
"y": 470,
"wires": [
[
"a597a9d9.f1a028"
]
]
},
{
"id": "a3affbe7.33bf08",
"type": "inject",
"z": "bfdbbee.bfabd4",
"name": "TZ+3",
"topic": "",
"payload": "+3",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 210,
"y": 510,
"wires": [
[
"a597a9d9.f1a028"
]
]
},
{
"id": "9a3ae2a.780a62",
"type": "inject",
"z": "bfdbbee.bfabd4",
"name": "",
"topic": "",
"payload": "12345678",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 220,
"y": 560,
"wires": [
[
"d03de180.21695"
]
]
},
{
"id": "b342b5ec.58c288",
"type": "function",
"z": "bfdbbee.bfabd4",
"name": "split(*)",
"func": "msg.parts = msg.payload.split(\"*\")\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 400,
"y": 150,
"wires": [
[
"c3ef72fd.56d72"
]
]
},
{
"id": "b6c13ed3.812be",
"type": "change",
"z": "bfdbbee.bfabd4",
"name": "MESSAGE,",
"rules": [
{
"t": "set",
"p": "param",
"pt": "msg",
"to": "payload",
"tot": "msg"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "MESSAGE,",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 530,
"y": 390,
"wires": [
[
"bd068d2b.51a4"
]
]
},
{
"id": "fef33a6a.aba838",
"type": "change",
"z": "bfdbbee.bfabd4",
"name": "FLOWER,",
"rules": [
{
"t": "set",
"p": "param",
"pt": "msg",
"to": "payload",
"tot": "msg"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "FLOWER,",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 530,
"y": 350,
"wires": [
[
"bd068d2b.51a4"
]
]
},
{
"id": "d03de180.21695",
"type": "change",
"z": "bfdbbee.bfabd4",
"name": "MONITOR,",
"rules": [
{
"t": "set",
"p": "param",
"pt": "msg",
"to": "payload",
"tot": "msg"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "MONITOR,",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 530,
"y": 470,
"wires": [
[
"bd068d2b.51a4"
]
]
},
{
"id": "a597a9d9.f1a028",
"type": "change",
"z": "bfdbbee.bfabd4",
"name": "LZ,9,",
"rules": [
{
"t": "set",
"p": "param",
"pt": "msg",
"to": "payload",
"tot": "msg"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "LZ,9,",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 510,
"y": 430,
"wires": [
[
"bd068d2b.51a4"
]
]
},
{
"id": "2a599e7a.dacf02",
"type": "inject",
"z": "bfdbbee.bfabd4",
"name": "",
"topic": "",
"payload": "87654321",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 220,
"y": 600,
"wires": [
[
"d03de180.21695"
]
]
},
{
"id": "c8a70c7f.bc2cb",
"type": "change",
"z": "bfdbbee.bfabd4",
"name": "CR",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "CR",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 510,
"y": 510,
"wires": [
[
"bd068d2b.51a4"
]
]
},
{
"id": "a8a4dbb5.069cd8",
"type": "inject",
"z": "bfdbbee.bfabd4",
"name": "location",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 210,
"y": 650,
"wires": [
[
"c8a70c7f.bc2cb"
]
]
},
{
"id": "af4eb8c4.a11aa8",
"type": "function",
"z": "bfdbbee.bfabd4",
"name": "split(,)",
"func": "msg.parts = msg.parts[3].split(\",\")\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 820,
"y": 170,
"wires": [
[
"397aa990.f8a4b6"
]
]
},
{
"id": "d55df99a.879808",
"type": "function",
"z": "bfdbbee.bfabd4",
"name": "split(,)",
"func": "msg.parts = msg.parts[3].split(\",\")\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 820,
"y": 230,
"wires": [
[
"fbbcaef4.ea668"
]
]
},
{
"id": "397aa990.f8a4b6",
"type": "change",
"z": "bfdbbee.bfabd4",
"name": "pedometer/battery",
"rules": [
{
"t": "set",
"p": "pedometer",
"pt": "msg",
"to": "parts[1]",
"tot": "msg"
},
{
"t": "set",
"p": "battery",
"pt": "msg",
"to": "parts[3]",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1020,
"y": 170,
"wires": [
[
"b13536f6.68ad88",
"bf21d195.9785a"
]
]
},
{
"id": "fbbcaef4.ea668",
"type": "change",
"z": "bfdbbee.bfabd4",
"name": "pedometer/battery/location",
"rules": [
{
"t": "set",
"p": "pedometer",
"pt": "msg",
"to": "parts[14]",
"tot": "msg"
},
{
"t": "set",
"p": "battery",
"pt": "msg",
"to": "parts[13]",
"tot": "msg"
},
{
"t": "set",
"p": "location",
"pt": "msg",
"to": "[parts[4], parts[6]]",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1050,
"y": 230,
"wires": [
[
"b13536f6.68ad88",
"bf21d195.9785a",
"dd8879aa.6f6bc8",
"504022cf.77a41c"
]
]
},
{
"id": "b13536f6.68ad88",
"type": "debug",
"z": "bfdbbee.bfabd4",
"name": "Pedometer",
"active": true,
"tosidebar": false,
"console": false,
"tostatus": true,
"complete": "pedometer",
"x": 1330,
"y": 170,
"wires": []
},
{
"id": "bf21d195.9785a",
"type": "debug",
"z": "bfdbbee.bfabd4",
"name": "Battery",
"active": true,
"tosidebar": false,
"console": false,
"tostatus": true,
"complete": "battery",
"x": 1320,
"y": 230,
"wires": []
},
{
"id": "dd8879aa.6f6bc8",
"type": "debug",
"z": "bfdbbee.bfabd4",
"name": "Location",
"active": true,
"tosidebar": false,
"console": false,
"tostatus": true,
"complete": "location",
"x": 1320,
"y": 290,
"wires": []
},
{
"id": "2002e444.7b90cc",
"type": "worldmap",
"z": "bfdbbee.bfabd4",
"name": "GPS watch",
"lat": "",
"lon": "",
"zoom": "10",
"layer": "OSM grey",
"cluster": "",
"maxage": "",
"usermenu": "show",
"layers": "show",
"panit": "false",
"x": 1530,
"y": 360,
"wires": []
},
{
"id": "504022cf.77a41c",
"type": "change",
"z": "bfdbbee.bfabd4",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "{\"name\": \"GPS watch\", \"lat\" : location[0], \"lon\": location[1]}",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1340,
"y": 360,
"wires": [
[
"2002e444.7b90cc"
]
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment