-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: simulation time is now dynamic
- Loading branch information
Showing
17 changed files
with
474 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* eslint-disable no-var */ | ||
declare global { | ||
// eslint-disable-next-line no-var | ||
var __io__: import('socket.io').Server | ||
var __SIMULATION_TIME__: number | ||
} | ||
|
||
export {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
interface Route { | ||
sub: (client: import('mqtt').MqttClient) => void | ||
type: 'mqtt' | 'http' | ||
sub?: (client: import('mqtt').MqttClient) => void | ||
init?: (app: FastifyInstance) => void | ||
SUB_TOPIC: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ const sub = (client: MqttClient) => { | |
} | ||
|
||
const aq: Route = { | ||
type: 'mqtt', | ||
sub, | ||
SUB_TOPIC | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ const sub = (client: MqttClient) => { | |
} | ||
|
||
const co2: Route = { | ||
type: 'mqtt', | ||
sub, | ||
SUB_TOPIC | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ const sub = (client: MqttClient) => { | |
} | ||
|
||
const date: Route = { | ||
type: 'mqtt', | ||
sub, | ||
SUB_TOPIC | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ const sub = (client: MqttClient) => { | |
} | ||
|
||
const humidity: Route = { | ||
type: 'mqtt', | ||
sub, | ||
SUB_TOPIC | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ const sub = (client: MqttClient) => { | |
} | ||
|
||
const pressure: Route = { | ||
type: 'mqtt', | ||
sub, | ||
SUB_TOPIC | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import debug from 'debug' | ||
import { FastifyInstance } from 'fastify' | ||
import { MAIN_TOPIC } from 'utils' | ||
|
||
const TOPIC = 'simulationTIme' | ||
const SUB_TOPIC = `${MAIN_TOPIC}/${TOPIC}` | ||
|
||
const updateSimulationTime = (app: FastifyInstance) => { | ||
const simDebug = debug('simulation:time:update') | ||
|
||
app.post<{ Params: { time: number } }>( | ||
'/simulationTime/:time', | ||
async (req, reply) => { | ||
const { | ||
headers: { authorization }, | ||
params: { time } | ||
} = req | ||
|
||
if (authorization !== process.env.API_KEY) | ||
return reply.status(401).send({ message: 'Unauthorized' }) | ||
|
||
if (isNaN(Number(time))) | ||
return reply.status(400).send({ message: 'Time is not a number' }) | ||
|
||
global.__SIMULATION_TIME__ = time * 1000 | ||
simDebug( | ||
`Updated simulation time: ${new Date( | ||
global.__SIMULATION_TIME__ | ||
).toISOString()}` | ||
) | ||
|
||
return { message: 'Simulation time updated', newTime: `${time}s` } | ||
} | ||
) | ||
} | ||
|
||
const simulationTime: Route = { | ||
type: 'http', | ||
init: updateSimulationTime, | ||
SUB_TOPIC | ||
} | ||
|
||
export { simulationTime } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ const sub = (client: MqttClient) => { | |
} | ||
|
||
const temperature: Route = { | ||
type: 'mqtt', | ||
sub, | ||
SUB_TOPIC | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters