From 71475678cd44636a89de863b58c86a853a6a54fd Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sun, 10 Mar 2019 20:14:10 +0100 Subject: [PATCH] timeserver fixes --- src/TTN/Nodered-Timeserver.json | 75 ++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 20 deletions(-) diff --git a/src/TTN/Nodered-Timeserver.json b/src/TTN/Nodered-Timeserver.json index f5ebdf70..2ad5c54e 100644 --- a/src/TTN/Nodered-Timeserver.json +++ b/src/TTN/Nodered-Timeserver.json @@ -48,8 +48,8 @@ "from": "", "to": "", "reg": false, - "x": 540, - "y": 340, + "x": 220, + "y": 360, "wires": [ [ "84f1cda2.069e7" @@ -64,8 +64,8 @@ "topic": "+/devices/+/up", "qos": "2", "broker": "2a15ab6f.ab2244", - "x": 130, - "y": 140, + "x": 70, + "y": 120, "wires": [ [ "9f4b8dd3.2f0d2" @@ -81,8 +81,8 @@ "qos": "", "retain": "", "broker": "2a15ab6f.ab2244", - "x": 710, - "y": 460, + "x": 690, + "y": 360, "wires": [] }, { @@ -93,8 +93,8 @@ "property": "payload", "action": "", "pretty": false, - "x": 340, - "y": 240, + "x": 220, + "y": 200, "wires": [ [ "8ed813a9.a9319" @@ -118,8 +118,8 @@ "checkall": "true", "repair": false, "outputs": 1, - "x": 340, - "y": 140, + "x": 220, + "y": 120, "wires": [ [ "4f97d75.6c87528" @@ -131,11 +131,11 @@ "type": "function", "z": "449c1517.e25f4c", "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, "noerr": 0, - "x": 360, - "y": 340, + "x": 400, + "y": 280, "wires": [ [ "49e3c067.e782e" @@ -150,8 +150,8 @@ "property": "payload", "action": "", "pretty": false, - "x": 480, - "y": 460, + "x": 540, + "y": 360, "wires": [ [ "72d5e7ee.d1eba8" @@ -165,11 +165,11 @@ "name": "Decode", "action": "", "property": "payload.payload_raw", - "x": 480, - "y": 240, + "x": 380, + "y": 200, "wires": [ [ - "f4c5b6de.f95148" + "f868bce2.dde67" ] ] }, @@ -180,14 +180,49 @@ "name": "Encode", "action": "", "property": "payload.payload_raw", - "x": 340, - "y": 460, + "x": 380, + "y": 360, "wires": [ [ "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", "type": "mqtt-broker",