No known key found for this signature in database
GPG Key ID: 86A4D290ED03FAB4
7 changed files with
14 additions and
21 deletions
-
client/src/class/ClientService.ts
-
client/src/class/ClientSocket.ts
-
server/src/AppRouter.ts
-
server/src/class/Service.ts
-
server/src/index.ts
-
server/src/routes/Routes.ts
-
web/.eslintrc.json
|
|
@ -4,7 +4,7 @@ import { Sensor } from './Sensor'; |
|
|
|
export class ClientService { |
|
|
|
private clientSocket: ClientSocket = new ClientSocket( |
|
|
|
process.env.SERVER_URL!, |
|
|
|
'temp' |
|
|
|
'measurement' |
|
|
|
); |
|
|
|
private sensor: Sensor = new Sensor(); |
|
|
|
|
|
|
@ -12,13 +12,13 @@ export class ClientService { |
|
|
|
|
|
|
|
tempService(): void { |
|
|
|
setInterval(() => { |
|
|
|
this.clientSocket.sendTemp(this.sensor.takeMeasure, 'temperature'); |
|
|
|
this.clientSocket.sendMeasure(this.sensor.takeMeasure, 'temperature'); |
|
|
|
}, 5 * 60000); |
|
|
|
} |
|
|
|
|
|
|
|
tempTestService(): void { |
|
|
|
setInterval(() => { |
|
|
|
this.clientSocket.sendTemp(this.sensor.takeTestMeasure, 'temperature'); |
|
|
|
this.clientSocket.sendMeasure(this.sensor.takeTestMeasure, 'temperature'); |
|
|
|
}, 5 * 60000); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
@ -1,5 +1,5 @@ |
|
|
|
import chalk from 'chalk'; |
|
|
|
import { exit } from 'process'; |
|
|
|
import chalk from 'chalk'; |
|
|
|
import io from 'socket.io-client'; |
|
|
|
|
|
|
|
export class ClientSocket { |
|
|
@ -31,7 +31,7 @@ export class ClientSocket { |
|
|
|
if (reason === 'io server disconnect') this.socket.connect(); |
|
|
|
|
|
|
|
if (reason === 'io client disconnect') { |
|
|
|
console.log(chalk.red('Server kicked you out!')); |
|
|
|
console.log(chalk.red('Server kicked you!')); |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
|
|
|
@ -48,7 +48,7 @@ export class ClientSocket { |
|
|
|
this.socket.disconnect(); |
|
|
|
} |
|
|
|
|
|
|
|
sendTemp(measurement: number, pointName: string): void { |
|
|
|
sendMeasure(measurement: number, pointName: string): void { |
|
|
|
this.socket.emit(this.eventName, { measurement, pointName }); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
@ -1,11 +0,0 @@ |
|
|
|
import express from 'express'; |
|
|
|
|
|
|
|
export class AppRouter { |
|
|
|
private static instance: express.Router; |
|
|
|
|
|
|
|
static getInstance(): express.Router { |
|
|
|
if (!AppRouter.instance) AppRouter.instance = express.Router(); |
|
|
|
|
|
|
|
return AppRouter.instance; |
|
|
|
} |
|
|
|
} |
|
|
@ -16,6 +16,6 @@ export class Service { |
|
|
|
} |
|
|
|
|
|
|
|
private initSocket() { |
|
|
|
this.socket = new Socket<Server>('temp', this.http, this.database); |
|
|
|
this.socket = new Socket<Server>('measurement', this.http, this.database); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
@ -3,7 +3,7 @@ import express from 'express'; |
|
|
|
import chalk from 'chalk'; |
|
|
|
var cors = require('cors'); |
|
|
|
import { Service } from './class/Service'; |
|
|
|
import { AppRouter } from './AppRouter'; |
|
|
|
// import { AppRouter } from './AppRouter';
|
|
|
|
import { Routes } from './routes/Routes'; |
|
|
|
|
|
|
|
console.log(chalk.cyan('Started Anchiale Server...')); |
|
|
@ -13,7 +13,6 @@ const http = require('http').Server(app); |
|
|
|
const service = new Service(http); |
|
|
|
|
|
|
|
app.use(cors()); |
|
|
|
app.use(AppRouter.getInstance()); |
|
|
|
|
|
|
|
const route = new Routes(app, service); |
|
|
|
route.routes(); |
|
|
|
|
|
@ -38,7 +38,7 @@ export class Routes { |
|
|
|
|
|
|
|
private measurements(): void { |
|
|
|
this.app.get('/measurements', async (req, res) => { |
|
|
|
const points = await this.service.database.query('temperature', '1h'); |
|
|
|
const points = await this.service.database.query('temperature', '1h'); // make temperature to something more abstract
|
|
|
|
|
|
|
|
res.header('Content-Type', 'application/json'); |
|
|
|
if (points) { |
|
|
|
|
|
@ -0,0 +1,5 @@ |
|
|
|
{ |
|
|
|
"rules": { |
|
|
|
"quotes": ["error", "single"] |
|
|
|
} |
|
|
|
} |