diff --git a/cmd/decoder/main.go b/cmd/decoder/main.go index 2c200fc..80b6cb4 100644 --- a/cmd/decoder/main.go +++ b/cmd/decoder/main.go @@ -146,6 +146,8 @@ func processIncoming(incoming model.Incoming_json, ctx *model.AppContext) { } }() + fmt.Println("message came") + incoming = mqttclient.IncomingBeaconFilter(incoming) id := mqttclient.GetBeaconID(incoming) now := time.Now().Unix() diff --git a/cmd/server/main.go b/cmd/server/main.go index 04f2f17..ada5500 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -50,8 +50,6 @@ func HttpServer(addr string) { http.ListenAndServe(addr, handlers.CORS(originsOk, headersOk, methodsOk)(r)) } -// This looks wrong, should handle error somehow - func sendKafkaMessage(writer *kafka.Writer, value *model.ApiUpdate) bool { valueStr, err := json.Marshal(&value) if err != nil { diff --git a/test/node-red-integration-tests/apitest.json b/test/node-red-integration-tests/apitest.json index c184ade..992c355 100644 --- a/test/node-red-integration-tests/apitest.json +++ b/test/node-red-integration-tests/apitest.json @@ -45,7 +45,7 @@ "50c9899be46f95be" ], "x": 74, - "y": 99, + "y": 39, "w": 892, "h": 482 }, @@ -77,10 +77,34 @@ "29f7ce4208592cc7" ], "x": 74, - "y": 599, + "y": 539, "w": 892, "h": 282 }, + { + "id": "cd2e897dda200635", + "type": "group", + "z": "59310844a3cdc638", + "style": { + "stroke": "#999999", + "stroke-opacity": "1", + "fill": "none", + "fill-opacity": "1", + "label": true, + "label-position": "nw", + "color": "#a4a4a4" + }, + "nodes": [ + "0390244642827293", + "b573b41eeb6a3021", + "f367b6f3d40ee8c4", + "6eee04a8f67e01eb" + ], + "x": 74, + "y": 839, + "w": 712, + "h": 142 + }, { "id": "883490d684612591", "type": "inject", @@ -104,7 +128,7 @@ "payload": "", "payloadType": "date", "x": 180, - "y": 240, + "y": 180, "wires": [ [ "522c9262dc81a34f" @@ -119,7 +143,7 @@ "name": "Server components test | BEACONS LIST", "info": "", "x": 260, - "y": 140, + "y": 80, "wires": [] }, { @@ -136,7 +160,7 @@ "finalize": "", "libs": [], "x": 360, - "y": 240, + "y": 180, "wires": [ [ "2f19e204e95d32b2" @@ -161,7 +185,7 @@ "senderr": false, "headers": [], "x": 550, - "y": 240, + "y": 180, "wires": [ [ "3b832f5f2a705f87" @@ -176,7 +200,7 @@ "name": "GET beacons list", "info": "", "x": 180, - "y": 200, + "y": 140, "wires": [] }, { @@ -202,7 +226,7 @@ "payload": "", "payloadType": "date", "x": 180, - "y": 340, + "y": 280, "wires": [ [ "368acb55a1372809" @@ -223,7 +247,7 @@ "finalize": "", "libs": [], "x": 360, - "y": 340, + "y": 280, "wires": [ [ "06586c5ac291f999" @@ -248,7 +272,7 @@ "senderr": false, "headers": [], "x": 550, - "y": 340, + "y": 280, "wires": [ [ "48eb1b4c5a48a874" @@ -263,7 +287,7 @@ "name": "POST beacons list", "info": "", "x": 190, - "y": 300, + "y": 240, "wires": [] }, { @@ -280,7 +304,7 @@ "statusVal": "", "statusType": "auto", "x": 860, - "y": 240, + "y": 180, "wires": [] }, { @@ -297,7 +321,7 @@ "statusVal": "", "statusType": "auto", "x": 860, - "y": 340, + "y": 280, "wires": [] }, { @@ -310,7 +334,7 @@ "action": "", "pretty": false, "x": 710, - "y": 240, + "y": 180, "wires": [ [ "b03a9a99c8897f49" @@ -340,7 +364,7 @@ "payload": "", "payloadType": "date", "x": 180, - "y": 440, + "y": 380, "wires": [ [ "3b4d5dca9051f727" @@ -361,7 +385,7 @@ "finalize": "", "libs": [], "x": 360, - "y": 440, + "y": 380, "wires": [ [ "213a0de12ca7b387" @@ -386,7 +410,7 @@ "senderr": false, "headers": [], "x": 550, - "y": 440, + "y": 380, "wires": [ [ "668a57a11d34fab9" @@ -401,7 +425,7 @@ "name": "PUT beacons list", "info": "", "x": 180, - "y": 400, + "y": 340, "wires": [] }, { @@ -418,7 +442,7 @@ "statusVal": "", "statusType": "auto", "x": 860, - "y": 440, + "y": 380, "wires": [] }, { @@ -444,7 +468,7 @@ "payload": "", "payloadType": "date", "x": 180, - "y": 540, + "y": 480, "wires": [ [ "c52f0e6e0e08f1ca" @@ -465,7 +489,7 @@ "finalize": "", "libs": [], "x": 370, - "y": 540, + "y": 480, "wires": [ [ "35d94840a12ca741" @@ -490,7 +514,7 @@ "senderr": false, "headers": [], "x": 550, - "y": 540, + "y": 480, "wires": [ [ "50c9899be46f95be" @@ -505,7 +529,7 @@ "name": "DELETE beacons list", "info": "", "x": 200, - "y": 500, + "y": 440, "wires": [] }, { @@ -522,7 +546,7 @@ "statusVal": "", "statusType": "auto", "x": 860, - "y": 540, + "y": 480, "wires": [] }, { @@ -548,7 +572,7 @@ "payload": "", "payloadType": "date", "x": 180, - "y": 740, + "y": 680, "wires": [ [ "d846952c928cabfd" @@ -563,7 +587,7 @@ "name": "Server components test | SETTINGS", "info": "", "x": 240, - "y": 640, + "y": 580, "wires": [] }, { @@ -580,7 +604,7 @@ "finalize": "", "libs": [], "x": 360, - "y": 740, + "y": 680, "wires": [ [ "e8f1a6bb67aa191e" @@ -605,7 +629,7 @@ "senderr": false, "headers": [], "x": 550, - "y": 740, + "y": 680, "wires": [ [ "04d408c7b56c5004" @@ -620,7 +644,7 @@ "name": "POST settings", "info": "", "x": 170, - "y": 700, + "y": 640, "wires": [] }, { @@ -637,7 +661,7 @@ "statusVal": "", "statusType": "auto", "x": 860, - "y": 740, + "y": 680, "wires": [] }, { @@ -663,7 +687,7 @@ "payload": "", "payloadType": "date", "x": 180, - "y": 840, + "y": 780, "wires": [ [ "39131f3755e4535d" @@ -684,7 +708,7 @@ "finalize": "", "libs": [], "x": 350, - "y": 840, + "y": 780, "wires": [ [ "8284044fa3903be9" @@ -709,7 +733,7 @@ "senderr": false, "headers": [], "x": 550, - "y": 840, + "y": 780, "wires": [ [ "29f7ce4208592cc7" @@ -724,7 +748,7 @@ "name": "GET settings", "info": "", "x": 170, - "y": 800, + "y": 740, "wires": [] }, { @@ -741,7 +765,7 @@ "statusVal": "", "statusType": "auto", "x": 860, - "y": 840, + "y": 780, "wires": [] }, { @@ -754,11 +778,123 @@ "action": "", "pretty": false, "x": 710, - "y": 840, + "y": 780, "wires": [ [ "4321534186191e5c" ] ] + }, + { + "id": "0390244642827293", + "type": "inject", + "z": "59310844a3cdc638", + "g": "cd2e897dda200635", + "name": "", + "props": [ + { + "p": "payload" + }, + { + "p": "topic", + "vt": "str" + } + ], + "repeat": "", + "crontab": "", + "once": false, + "onceDelay": 0.1, + "topic": "", + "payload": "", + "payloadType": "date", + "x": 180, + "y": 940, + "wires": [ + [ + "f367b6f3d40ee8c4" + ] + ] + }, + { + "id": "b573b41eeb6a3021", + "type": "comment", + "z": "59310844a3cdc638", + "g": "cd2e897dda200635", + "name": "MQTT test", + "info": "", + "x": 160, + "y": 880, + "wires": [] + }, + { + "id": "f367b6f3d40ee8c4", + "type": "function", + "z": "59310844a3cdc638", + "g": "cd2e897dda200635", + "name": "prepare msg and topic", + "func": "msg.payload = [\n { \"timestamp\": \"2025-07-24T15:00:00.161Z\", \"type\": \"Gateway\", \"mac\": \"AC233FC1DCCB\", \"nums\": 56 },\n { \"timestamp\": \"2025-07-24T15:00:00.141Z\", \"mac\": \"C3000057B9DA\", \"rssi\": -66, \"rawData\": \"0201060303AAFE1116AAFE20000C392500000601EA01192890\" },\n { \"timestamp\": \"2025-07-24T15:00:00.180Z\", \"mac\": \"2EEF56E34CF7\", \"rssi\": -52, \"rawData\": \"1EFF06000109202231FC772C59F6DD39CBE3F46A46C69105FC424C6705B6D4\" },\n { \"timestamp\": \"2025-07-24T15:00:00.200Z\", \"mac\": \"C3000057B9F5\", \"rssi\": -55, \"rawData\": \"0201060303E1FF1216E1FFA103640007FFFE0100F5B9570000C3\" },\n { \"timestamp\": \"2025-07-24T15:00:00.286Z\", \"mac\": \"2EEF56E34CF7\", \"rssi\": -64, \"rawData\": \"1EFF06000109202231FC772C59F6DD39CBE3F46A46C69105FC424C6705B6D4\" },\n { \"timestamp\": \"2025-07-24T15:00:00.293Z\", \"mac\": \"C3000057B9DD\", \"rssi\": -77, \"rawData\": \"0201060303E1FF1216E1FFA1036400050002010ADDB9570000C3\" },\n { \"timestamp\": \"2025-07-24T15:00:00.312Z\", \"mac\": \"C3000057B9DD\", \"rssi\": -77, \"rawData\": \"0201060303AAFE1516AAFE00E800112233445566778899000000000011\" },\n { \"timestamp\": \"2025-07-24T15:00:00.332Z\", \"mac\": \"C3000057B9F6\", \"rssi\": -75, \"rawData\": \"0201060303AAFE0C16AAFE10E8016D696E657700\" },\n { \"timestamp\": \"2025-07-24T15:00:00.333Z\", \"mac\": \"C300003B1E21\", \"rssi\": -72, \"rawData\": \"0201060303E1FF1116E1FFA10848211E3B0000C34D57433031\" },\n { \"timestamp\": \"2025-07-24T15:00:00.337Z\", \"mac\": \"0C063F7162D6\", \"rssi\": -59, \"rawData\": \"1EFF0600010F2022DD24BF3F2AB0BED78AE0CF7151E580A9C3562C5C16425D\" },\n { \"timestamp\": \"2025-07-24T15:00:00.338Z\", \"mac\": \"C3000057B9DC\", \"rssi\": -70, \"rawData\": \"0201060303E1FF1216E1FFA10364000700F80000DCB9570000C3\" },\n { \"timestamp\": \"2025-07-24T15:00:00.361Z\", \"mac\": \"C3000057B9DC\", \"rssi\": -79, \"rawData\": \"0201060303E1FF0E16E1FFA10864DCB9570000C34237\" },\n { \"timestamp\": \"2025-07-24T15:00:00.380Z\", \"mac\": \"D54E908B7972\", \"rssi\": -76, \"rawData\": \"020106020A001216ABFE40000A0BD50001D54E908B7972300B\" },\n { \"timestamp\": \"2025-07-24T15:00:00.387Z\", \"mac\": \"C3000057B9DC\", \"rssi\": -70, \"rawData\": \"0201060303AAFE1516AAFE00E800112233445566778899000000000010\" },\n { \"timestamp\": \"2025-07-24T15:00:00.392Z\", \"mac\": \"2EEF56E34CF7\", \"rssi\": -53, \"rawData\": \"1EFF06000109202231FC772C59F6DD39CBE3F46A46C69105FC424C6705B6D4\" },\n { \"timestamp\": \"2025-07-24T15:00:00.393Z\", \"mac\": \"E017085443A7\", \"rssi\": -68, \"rawData\": \"0201060C16E0FE2001000000000100000A094D4B20427574746F6E\" },\n { \"timestamp\": \"2025-07-24T15:00:00.401Z\", \"mac\": \"C3000057B9F6\", \"rssi\": -71, \"rawData\": \"0201060303E1FF1216E1FFA10364FFEF00F8000AF6B9570000C3\" },\n { \"timestamp\": \"2025-07-24T15:00:00.409Z\", \"mac\": \"C3000057B9DB\", \"rssi\": -66, \"rawData\": \"0201060303AAFE1516AAFE00E800112233445566778899000000000009\" },\n { \"timestamp\": \"2025-07-24T15:00:00.411Z\", \"mac\": \"C3000057B9F4\", \"rssi\": -79, \"rawData\": \"0201060303F1FF1716E2C56DB5DFFB48D2B060D0F5A71096E000000000EC64\" },\n { \"timestamp\": \"2025-07-24T15:00:00.436Z\", \"mac\": \"0C063F7162D6\", \"rssi\": -75, \"rawData\": \"1EFF0600010F2022DD24BF3F2AB0BED78AE0CF7151E580A9C3562C5C16425D\" },\n { \"timestamp\": \"2025-07-24T15:00:00.449Z\", \"mac\": \"C3000057B9D7\", \"rssi\": -69, \"rawData\": \"0201060303AAFE1116AAFE20000C1B1F0000060D6B011929E4\" },\n { \"timestamp\": \"2025-07-24T15:00:00.494Z\", \"mac\": \"2EEF56E34CF7\", \"rssi\": -53, \"rawData\": \"1EFF06000109202231FC772C59F6DD39CBE3F46A46C69105FC424C6705B6D4\" },\n { \"timestamp\": \"2025-07-24T15:00:00.522Z\", \"mac\": \"CD738844D504\", \"rssi\": -63, \"rawData\": \"07FF4C0012020003\" },\n { \"timestamp\": \"2025-07-24T15:00:00.522Z\", \"mac\": \"C3000057B9F9\", \"rssi\": -80, \"rawData\": \"0201060303AAFE0C16AAFE10E8016D696E657700\" },\n { \"timestamp\": \"2025-07-24T15:00:00.545Z\", \"mac\": \"0C063F7162D6\", \"rssi\": -69, \"rawData\": \"1EFF0600010F2022DD24BF3F2AB0BED78AE0CF7151E580A9C3562C5C16425D\" },\n { \"timestamp\": \"2025-07-24T15:00:00.573Z\", \"mac\": \"C3000057B9D3\", \"rssi\": -70, \"rawData\": \"0201060303E1FF1216E1FFA10364FFECFFFEFF06D3B9570000C3\" },\n { \"timestamp\": \"2025-07-24T15:00:00.588Z\", \"mac\": \"C3000057B9E8\", \"rssi\": -73, \"rawData\": \"0201060303AAFE0C16AAFE10E8016D696E657700\" },\n { \"timestamp\": \"2025-07-24T15:00:00.596Z\", \"mac\": \"2EEF56E34CF7\", \"rssi\": -54, \"rawData\": \"1EFF06000109202231FC772C59F6DD39CBE3F46A46C69105FC424C6705B6D4\" },\n { \"timestamp\": \"2025-07-24T15:00:00.645Z\", \"mac\": \"C3000057B9D7\", \"rssi\": -70, \"rawData\": \"0201060303AAFE0C16AAFE10E8016D696E657700\" },\n { \"timestamp\": \"2025-07-24T15:00:00.647Z\", \"mac\": \"0C063F7162D6\", \"rssi\": -58, \"rawData\": \"1EFF0600010F2022DD24BF3F2AB0BED78AE0CF7151E580A9C3562C5C16425D\" },\n { \"timestamp\": \"2025-07-24T15:00:00.704Z\", \"mac\": \"6E9836F89346\", \"rssi\": -68, \"rawData\": \"02011A020A070BFF4C0010063E1E8C2885FC\" },\n { \"timestamp\": \"2025-07-24T15:00:00.705Z\", \"mac\": \"2EEF56E34CF7\", \"rssi\": -52, \"rawData\": \"1EFF06000109202231FC772C59F6DD39CBE3F46A46C69105FC424C6705B6D4\" },\n { \"timestamp\": \"2025-07-24T15:00:00.707Z\", \"mac\": \"C300003947E2\", \"rssi\": -53, \"rawData\": \"0201060303E1FF1216E1FFA10364000700F50000E247390000C3\" },\n { \"timestamp\": \"2025-07-24T15:00:00.713Z\", \"mac\": \"C300003947C4\", \"rssi\": -81, \"rawData\": \"0201060303E1FF1216E1FFA10364001700FAFFFEC447390000C3\" },\n { \"timestamp\": \"2025-07-24T15:00:00.727Z\", \"mac\": \"C3000057B9D7\", \"rssi\": -69, \"rawData\": \"0201060303E1FF1216E1FFA10364000A0105FFFBD7B9570000C3\" }, \n { \"timestamp\": \"2025-07-24T15:00:00.752Z\", \"mac\": \"0C063F7162D6\", \"rssi\": -71, \"rawData\": \"1EFF0600010F2022DD24BF3F2AB0BED78AE0CF7151E580A9C3562C5C16425D\" },\n { \"timestamp\": \"2025-07-24T15:00:00.811Z\", \"mac\": \"2EEF56E34CF7\", \"rssi\": -54, \"rawData\": \"1EFF06000109202231FC772C59F6DD39CBE3F46A46C69105FC424C6705B6D4\" },\n { \"timestamp\": \"2025-07-24T15:00:00.828Z\", \"mac\": \"C3000057B9D4\", \"rssi\": -81, \"rawData\": \"0201060303AAFE1116AAFE20000C1B1B00002C441A01192BB0\" }, \n { \"timestamp\": \"2025-07-24T15:00:00.830Z\", \"mac\": \"C3000057B9DC\", \"rssi\": -70, \"rawData\": \"0201060303AAFE1116AAFE20000C3022000005FBF1011926E2\" }, \n { \"timestamp\": \"2025-07-24T15:00:00.832Z\", \"mac\": \"C3000057B9F4\", \"rssi\": -60, \"rawData\": \"0201060303E1FF1216E1FFA10364000001000005F4B9570000C3\" }, \n { \"timestamp\": \"2025-07-24T15:00:00.847Z\", \"mac\": \"C3000057B9E5\", \"rssi\": -83, \"rawData\": \"0201060303AAFE1116AAFE20000BEB1B000006262A01192084\" }, \n { \"timestamp\": \"2025-07-24T15:00:00.855Z\", \"mac\": \"0C063F7162D6\", \"rssi\": -70, \"rawData\": \"1EFF0600010F2022DD24BF3F2AB0BED78AE0CF7151E580A9C3562C5C16425D\" }, \n { \"timestamp\": \"2025-07-24T15:00:00.882Z\", \"mac\": \"C3000057B9D6\", \"rssi\": -68, \"rawData\": \"0201060303AAFE1516AAFE00E800112233445566778899000000000004\" }, \n { \"timestamp\": \"2025-07-24T15:00:00.906Z\", \"mac\": \"C3000057B9F5\", \"rssi\": -57, \"rawData\": \"0201060303AAFE1516AAFE00E800112233445566778899000000000035\" },\n { \"timestamp\": \"2025-07-24T15:00:00.920Z\", \"mac\": \"2EEF56E34CF7\", \"rssi\": -54, \"rawData\": \"1EFF06000109202231FC772C59F6DD39CBE3F46A46C69105FC424C6705B6D4\" }, \n { \"timestamp\": \"2025-07-24T15:00:00.931Z\", \"mac\": \"C3000057B9F5\", \"rssi\": -67, \"rawData\": \"0201060303AAFE0C16AAFE10E8016D696E657700\" }, \n { \"timestamp\": \"2025-07-24T15:00:00.963Z\", \"mac\": \"0C063F7162D6\", \"rssi\": -58, \"rawData\": \"1EFF0600010F2022DD24BF3F2AB0BED78AE0CF7151E580A9C3562C5C16425D\" }, \n { \"timestamp\": \"2025-07-24T15:00:00.975Z\", \"mac\": \"6E9836F89346\", \"rssi\": -63, \"rawData\": \"02011A020A070BFF4C0010063E1E8C2885FC\" },\n { \"timestamp\": \"2025-07-24T15:00:00.998Z\", \"mac\": \"C300003947E2\", \"rssi\": -71, \"rawData\": \"0201060303AAFE1116AAFE20000BEB1D00009704B20DB7A57C\" },\n { \"timestamp\": \"2025-07-24T15:00:01.027Z\", \"mac\": \"2EEF56E34CF7\", \"rssi\": -52, \"rawData\": \"1EFF06000109202231FC772C59F6DD39CBE3F46A46C69105FC424C6705B6D4\" }, \n { \"timestamp\": \"2025-07-24T15:00:01.055Z\", \"mac\": \"C3000057B9EA\", \"rssi\": -82, \"rawData\": \"0201060303AAFE0C16AAFE10E8016D696E657700\" }, \n { \"timestamp\": \"2025-07-24T15:00:01.056Z\", \"mac\": \"F045AEE31DB4\", \"rssi\": -71, \"rawData\": \"0201060C16E0FE2001000000000100000A094D4B20427574746F6E\" }, \n { \"timestamp\": \"2025-07-24T15:00:01.070Z\", \"mac\": \"C3000057B9D4\", \"rssi\": -82, \"rawData\": \"0201060303E1FF1216E1FFA10364000000F50002D4B9570000C3\" }, \n { \"timestamp\": \"2025-07-24T15:00:01.079Z\", \"mac\": \"C3000057B9E8\", \"rssi\": -70, \"rawData\": \"0201060303E1FF1216E1FFA10364FFFB00FAFFECE8B9570000C3\" }, \n { \"timestamp\": \"2025-07-24T15:00:01.089Z\", \"mac\": \"C3000057B9F4\", \"rssi\": -61, \"rawData\": \"0201060303AAFE1116AAFE20000C181C000005FD3901191896\" }, \n { \"timestamp\": \"2025-07-24T15:00:01.116Z\", \"mac\": \"C3000057B9DB\", \"rssi\": -72, \"rawData\": \"0201060303E1FF1216E1FFA103640002FFF4010ADBB9570000C3\" }, \n { \"timestamp\": \"2025-07-24T15:00:01.136Z\", \"mac\": \"2EEF56E34CF7\", \"rssi\": -54, \"rawData\": \"1EFF06000109202231FC772C59F6DD39CBE3F46A46C69105FC424C6705B6D4\" }\n];\n\nmsg.topic = \"publish_out/ac233fc1dccb\";\n\nreturn msg;", + "outputs": 1, + "timeout": 0, + "noerr": 0, + "initialize": "", + "finalize": "", + "libs": [], + "x": 380, + "y": 940, + "wires": [ + [ + "6eee04a8f67e01eb" + ] + ] + }, + { + "id": "6eee04a8f67e01eb", + "type": "mqtt out", + "z": "59310844a3cdc638", + "g": "cd2e897dda200635", + "name": "", + "topic": "", + "qos": "", + "retain": "", + "respTopic": "", + "contentType": "", + "userProps": "", + "correl": "", + "expiry": "", + "broker": "109b7c239250b941", + "x": 710, + "y": 940, + "wires": [] + }, + { + "id": "109b7c239250b941", + "type": "mqtt-broker", + "name": "", + "broker": "emqx", + "port": 1883, + "clientid": "", + "autoConnect": true, + "usetls": false, + "protocolVersion": 4, + "keepalive": 60, + "cleansession": true, + "autoUnsubscribe": true, + "birthTopic": "", + "birthQos": "0", + "birthRetain": "false", + "birthPayload": "", + "birthMsg": {}, + "closeTopic": "", + "closeQos": "0", + "closeRetain": "false", + "closePayload": "", + "closeMsg": {}, + "willTopic": "", + "willQos": "0", + "willRetain": "false", + "willPayload": "", + "willMsg": {}, + "userProps": "", + "sessionExpiry": "" } ] \ No newline at end of file