diff --git a/server/Repos.SQLite/ReadingRepo.mjs b/server/Repos.SQLite/ReadingRepo.mjs index b1f6d5f..a8b83fc 100644 --- a/server/Repos.SQLite/ReadingRepo.mjs +++ b/server/Repos.SQLite/ReadingRepo.mjs @@ -11,12 +11,12 @@ class ReadingRepo { this.query_insert = this.db.prepare(`INSERT INTO readings ( id, lat, long, - data_rate_id, code_rate, bit_rate + data_rate, code_rate ) VALUES ( :id, :latitude, :longitude, - :data_rate_id, :code_rate, :bit_rate + :data_rate, :code_rate )`); this.insert_query.run(reading); diff --git a/server/db_template.sql b/server/db_template.sql index 150679c..583800e 100644 --- a/server/db_template.sql +++ b/server/db_template.sql @@ -5,7 +5,7 @@ CREATE TABLE readings IF NOT EXISTS ( long FLOAT NOT NULL, -- Longitude component of GPS co-ordinates of reading, data_rate TEXT NOT NULL, -- The id of the data rate code in the data_rates table that describes the data rate at which the message was transmitted code_rate TEXT, -- The coding rate at which the message was transmitted. FUTURE: This may need to be an INTEGER field - not sure - bit_rate INTEGER, -- The bit rate at which the message was transmitted + -- bit_rate INTEGER, -- The bit rate at which the message was transmitted -- We didn't actually recieve this - disparity between API docs & actual message ); CREATE TABLE rssis IF NOT EXISTS ( id INTEGER PRIMARY KEY, -- Random unique int diff --git a/server/ttn-app-server/MessageHandler.mjs b/server/ttn-app-server/MessageHandler.mjs index 6181e61..4d062ca 100644 --- a/server/ttn-app-server/MessageHandler.mjs +++ b/server/ttn-app-server/MessageHandler.mjs @@ -3,8 +3,10 @@ import { decode_payload } from './DecodePayload.mjs'; class MessageHandler { - constructor() { - + constructor({ ReadingRepo, RSSIRepo, GatewayRepo }) { + this.repo_reading = ReadingRepo; + this.repo_rssi = RSSIRepo; + this.repo_gateway = GatewayRepo; } async handle(message) { @@ -12,6 +14,15 @@ class MessageHandler { let decoded_payload = decode_payload(message.payload_raw); console.log(decoded_payload); + + this.repo_reading.add({ + id: decoded_payload.id, + latitude: decoded_payload.latitude, + longitude: decoded_payload.longitude, + + data_rate: message.metadata.data_rate, + code_rate: message.metadata.coding_rate + }); } }