-
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: new sensor data: co2, pm2.5 and pressure. H2S was deprecated
- Loading branch information
1 parent
a0e1c5e
commit 562cb75
Showing
11 changed files
with
163 additions
and
76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `h2s` on the `sensorData` table. All the data in the column will be lost. | ||
- Added the required column `co2` to the `sensorData` table without a default value. This is not possible if the table is not empty. | ||
- Added the required column `pm2_5` to the `sensorData` table without a default value. This is not possible if the table is not empty. | ||
- Added the required column `pressure` to the `sensorData` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "sensorData" DROP COLUMN "h2s", | ||
ADD COLUMN "co2" DOUBLE PRECISION NOT NULL, | ||
ADD COLUMN "pm2_5" DOUBLE PRECISION NOT NULL, | ||
ADD COLUMN "pressure" DOUBLE PRECISION NOT NULL; |
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
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,2 +1 @@ | ||
export * from './fakePub' | ||
export * from './ping' |
This file was deleted.
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
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,4 @@ | ||
export * from './aq' | ||
export * from './date' | ||
export * from './humidity' | ||
export * from './h2s' | ||
export * from './ping' | ||
export * from './temperature' |
This file was deleted.
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import debug from 'debug' | ||
import { MqttClient } from 'mqtt' | ||
|
||
import { socketConnection } from 'network/socket' | ||
// eslint-disable-next-line camelcase | ||
import { updatePm2_5 } from 'database' | ||
import { MAIN_TOPIC } from 'utils' | ||
|
||
const TOPIC = 'pm2.5' | ||
const SUB_TOPIC = `${MAIN_TOPIC}/${TOPIC}` | ||
|
||
const sub = (client: MqttClient) => { | ||
const subDebug = debug(`${MAIN_TOPIC}:Mqtt:${TOPIC}:sub`) | ||
const db = global.__firebase__.database(process.env.FIREBASE_REAL_TIME_DB) | ||
|
||
client.subscribe(SUB_TOPIC, error => { | ||
if (!error) subDebug(`Subscribed to Topic: ${SUB_TOPIC}`) | ||
}) | ||
|
||
client.on('message', (topic, message) => { | ||
if (topic.includes(TOPIC)) { | ||
const [id, moduleId, sensorId, value] = message.toString().split('/') | ||
const floatValue = parseFloat(value) | ||
|
||
if (floatValue === 0) return | ||
|
||
subDebug(`Topic: ${topic} - Message received: ${message.toString()}`) | ||
subDebug( | ||
`Received a ${TOPIC.toUpperCase()} update at: ${new Date().toISOString()}` | ||
) | ||
updatePm2_5({ db, moduleId, id, value: floatValue, sensorId }) | ||
socketConnection(subDebug).connect().emit(`${sensorId}/pm2.5`, floatValue) | ||
} | ||
}) | ||
} | ||
|
||
const pH: Route = { | ||
sub, | ||
SUB_TOPIC | ||
} | ||
|
||
export { pH } |
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 { MqttClient } from 'mqtt' | ||
|
||
import { socketConnection } from 'network/socket' | ||
import { updatePressure } from 'database' | ||
import { MAIN_TOPIC } from 'utils' | ||
|
||
const TOPIC = 'pressure' | ||
const SUB_TOPIC = `${MAIN_TOPIC}/${TOPIC}` | ||
|
||
const sub = (client: MqttClient) => { | ||
const subDebug = debug(`${MAIN_TOPIC}:Mqtt:${TOPIC}:sub`) | ||
const db = global.__firebase__.database(process.env.FIREBASE_REAL_TIME_DB) | ||
|
||
client.subscribe(SUB_TOPIC, error => { | ||
if (!error) subDebug(`Subscribed to Topic: ${SUB_TOPIC}`) | ||
}) | ||
|
||
client.on('message', (topic, message) => { | ||
if (topic.includes(TOPIC)) { | ||
const [id, moduleId, sensorId, value] = message.toString().split('/') | ||
const floatValue = parseFloat(value) | ||
|
||
if (floatValue === 0) return | ||
|
||
subDebug(`Topic: ${topic} - Message received: ${message.toString()}`) | ||
subDebug( | ||
`Received a ${TOPIC.toUpperCase()} update at: ${new Date().toISOString()}` | ||
) | ||
updatePressure({ db, moduleId, id, value: floatValue, sensorId }) | ||
socketConnection(subDebug) | ||
.connect() | ||
.emit(`${sensorId}/pressure`, floatValue) | ||
} | ||
}) | ||
} | ||
|
||
const pH: Route = { | ||
sub, | ||
SUB_TOPIC | ||
} | ||
|
||
export { pH } |