timeserver fixes

This commit is contained in:
Verkehrsrot 2019-03-10 20:14:10 +01:00
parent c13934be99
commit 71475678cd

View File

@ -48,8 +48,8 @@
"from": "", "from": "",
"to": "", "to": "",
"reg": false, "reg": false,
"x": 540, "x": 220,
"y": 340, "y": 360,
"wires": [ "wires": [
[ [
"84f1cda2.069e7" "84f1cda2.069e7"
@ -64,8 +64,8 @@
"topic": "+/devices/+/up", "topic": "+/devices/+/up",
"qos": "2", "qos": "2",
"broker": "2a15ab6f.ab2244", "broker": "2a15ab6f.ab2244",
"x": 130, "x": 70,
"y": 140, "y": 120,
"wires": [ "wires": [
[ [
"9f4b8dd3.2f0d2" "9f4b8dd3.2f0d2"
@ -81,8 +81,8 @@
"qos": "", "qos": "",
"retain": "", "retain": "",
"broker": "2a15ab6f.ab2244", "broker": "2a15ab6f.ab2244",
"x": 710, "x": 690,
"y": 460, "y": 360,
"wires": [] "wires": []
}, },
{ {
@ -93,8 +93,8 @@
"property": "payload", "property": "payload",
"action": "", "action": "",
"pretty": false, "pretty": false,
"x": 340, "x": 220,
"y": 240, "y": 200,
"wires": [ "wires": [
[ [
"8ed813a9.a9319" "8ed813a9.a9319"
@ -118,8 +118,8 @@
"checkall": "true", "checkall": "true",
"repair": false, "repair": false,
"outputs": 1, "outputs": 1,
"x": 340, "x": 220,
"y": 140, "y": 120,
"wires": [ "wires": [
[ [
"4f97d75.6c87528" "4f97d75.6c87528"
@ -131,11 +131,11 @@
"type": "function", "type": "function",
"z": "449c1517.e25f4c", "z": "449c1517.e25f4c",
"name": "Time_Sync_Ans", "name": "Time_Sync_Ans",
"func": "/* LoRaWAN Timeserver\n\nconstruct 6 byte timesync_answer from gateway timestamp and node's time_sync_req\n\nbyte meaning\n0 sequence number (taken from node's time_sync_req)\n1..4 current second (from epoch time 1970)\n5 1/250ths fractions of current second\n\n*/\n\n let buf = new ArrayBuffer(6);\n let timestamp = (+new Date(msg.payload.metadata.time));\n\n var seconds = Math.floor(timestamp/1000);\n var fractions = timestamp % 250;\n var seqno = msg.payload.payload_raw[0];\n\n new DataView(buf).setUint8(0, seqno);\n new DataView(buf).setUint32(1, seconds);\n new DataView(buf).setUint8(5, fractions);\n\n msg.payload = new Buffer(new Uint8Array(buf));\n \n return msg;", "func": "/* LoRaWAN Timeserver\n\nconstruct 6 byte timesync_answer from gateway timestamp and node's time_sync_req\n\nbyte meaning\n0 sequence number (taken from node's time_sync_req)\n1..4 current second (from epoch time 1970)\n5 1/250ths fractions of current second\n\n*/\n\n let buf = new ArrayBuffer(6);\n let timestamp = (+new Date(msg.payload.metadata.gateways[0].time));\n \n var seconds = Math.floor(timestamp/1000);\n var fractions = timestamp % 250;\n var seqno = msg.payload.payload_raw[0];\n\n new DataView(buf).setUint8(0, seqno);\n new DataView(buf).setUint32(1, seconds);\n new DataView(buf).setUint8(5, fractions);\n\n msg.payload = new Buffer(new Uint8Array(buf));\n \n return msg;",
"outputs": 1, "outputs": 1,
"noerr": 0, "noerr": 0,
"x": 360, "x": 400,
"y": 340, "y": 280,
"wires": [ "wires": [
[ [
"49e3c067.e782e" "49e3c067.e782e"
@ -150,8 +150,8 @@
"property": "payload", "property": "payload",
"action": "", "action": "",
"pretty": false, "pretty": false,
"x": 480, "x": 540,
"y": 460, "y": 360,
"wires": [ "wires": [
[ [
"72d5e7ee.d1eba8" "72d5e7ee.d1eba8"
@ -165,11 +165,11 @@
"name": "Decode", "name": "Decode",
"action": "", "action": "",
"property": "payload.payload_raw", "property": "payload.payload_raw",
"x": 480, "x": 380,
"y": 240, "y": 200,
"wires": [ "wires": [
[ [
"f4c5b6de.f95148" "f868bce2.dde67"
] ]
] ]
}, },
@ -180,14 +180,49 @@
"name": "Encode", "name": "Encode",
"action": "", "action": "",
"property": "payload.payload_raw", "property": "payload.payload_raw",
"x": 340, "x": 380,
"y": 460, "y": 360,
"wires": [ "wires": [
[ [
"dac8aafa.389298" "dac8aafa.389298"
] ]
] ]
}, },
{
"id": "6190967b.01f758",
"type": "comment",
"z": "449c1517.e25f4c",
"name": "LoRaWAN Timeserver",
"info": "PLEASE NOTE: There is a patent filed for the time sync algorithm used in the\ncode of this file. The shown implementation example is covered by the\nrepository's licencse, but you may not be eligible to deploy the applied\nalgorithm in applications without granted license by the patent holder.",
"x": 120,
"y": 40,
"wires": []
},
{
"id": "f868bce2.dde67",
"type": "switch",
"z": "449c1517.e25f4c",
"name": "Timechecker",
"property": "payload.metadata.gateways[0].time",
"propertyType": "msg",
"rules": [
{
"t": "lte",
"v": "payload.metadata.time",
"vt": "msg"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 550,
"y": 200,
"wires": [
[
"f4c5b6de.f95148"
]
]
},
{ {
"id": "2a15ab6f.ab2244", "id": "2a15ab6f.ab2244",
"type": "mqtt-broker", "type": "mqtt-broker",