From b7ae41caa4ebbdf7c9c58b1f83f26eae8b22e1e9 Mon Sep 17 00:00:00 2001 From: cheetah Date: Fri, 2 Apr 2021 16:16:47 +0000 Subject: [PATCH] added manual READ/RECV ack to API Test --- html_main/index.html | 16 +++++++++++----- index.js | 5 +++-- types/devices/BirdySlim.js | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/html_main/index.html b/html_main/index.html index 5f42cc9..1a07b38 100644 --- a/html_main/index.html +++ b/html_main/index.html @@ -69,10 +69,9 @@ Last LoRaWAN Packet: @@ -123,8 +122,10 @@ Message ID: {{ item.id }} } }, created() { - //this.refreshDevices() + this.refreshDevices() setInterval(this.refreshDevices, 1e3) + + this.refreshMessages() setInterval(this.refreshMessages, 1e3) }, methods: { @@ -163,6 +164,11 @@ Message ID: {{ item.id }} }, response => { }) }, + apiACKMessage(id, ackType) { + this.$http.get( + '/api/message/ack/'+[ackType, id].join('/') + ).then(x=>{}) + } } }) diff --git a/index.js b/index.js index 681bf63..c7ae0aa 100644 --- a/index.js +++ b/index.js @@ -47,6 +47,7 @@ app.post('/api/message/advanced', async (req, res) => { app.get('/api/message/status/:id', async (req, res) => { //TODO: make this fancy return res.json(types.MessageManager.messages[ req.params.id ]) }) + app.get('/api/message/recent', async (req, res) => { let msgs = Object.values(types.MessageManager.messages) .sort((a,b) => b.date-a.date) @@ -55,7 +56,7 @@ app.get('/api/message/recent', async (req, res) => { app.get('/api/message/ack/recv/:id', async (req, res) => { types.ConnectorRegistry.reportDelivered({ id: req.params.id }, 'http') - require('../MessageManager').attachMetadata(req.params.id, { + types.MessageManager.attachMetadata(req.params.id, { ack: 'recv', rssi: 0x00, date: new Date(), @@ -65,7 +66,7 @@ app.get('/api/message/ack/recv/:id', async (req, res) => { }) app.get('/api/message/ack/read/:id', async (req, res) => { types.MessageManager.markMessageRead(req.params.id) - require('../MessageManager').attachMetadata(req.params.id, { + types.MessageManager.attachMetadata(req.params.id, { ack: 'read', date: new Date(), metadata: { http: true }, diff --git a/types/devices/BirdySlim.js b/types/devices/BirdySlim.js index 142d988..ecc206c 100644 --- a/types/devices/BirdySlim.js +++ b/types/devices/BirdySlim.js @@ -50,7 +50,7 @@ class BirdySlim extends PagerDevice { break; case 'operational': require('../MessageManager').respondToMessage(data.msgid, data.operationalData) - break; + break; } // If we have had a Ack. Event, we should store some Metadata about it too require('../MessageManager').attachMetadata(data.msgid, {