parent
e6e784cf58
commit
2ede546fa5
@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
.env
|
||||
data
|
||||
@ -0,0 +1,17 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Launch Program",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"program": "${workspaceFolder}/index.js"
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
FROM node:lts-alpine
|
||||
|
||||
WORKDIR /opt/app
|
||||
|
||||
COPY package.json ./
|
||||
COPY package-lock.json ./
|
||||
|
||||
RUN npm ci
|
||||
|
||||
COPY . .
|
||||
|
||||
CMD [ "node", "index.js" ]
|
||||
@ -0,0 +1,4 @@
|
||||
const pg = require("pg")
|
||||
const client = new pg.Pool();
|
||||
client.connect();
|
||||
module.exports = client
|
||||
@ -0,0 +1,30 @@
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
|
||||
app:
|
||||
restart: always
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
ports:
|
||||
- 8080:8080
|
||||
environment:
|
||||
MQTT: "mqtt://192.168.24.215"
|
||||
DB: "mqtt://192.168.24.215"
|
||||
PGHOST: "database"
|
||||
PGPASSWORD: "6561284a-b277-4668-af57-3226c8ff454c"
|
||||
PGUSER: "postgres"
|
||||
depends_on:
|
||||
- database
|
||||
|
||||
database:
|
||||
image: postgres:alpine
|
||||
restart: always
|
||||
environment:
|
||||
POSTGRES_PASSWORD: 6561284a-b277-4668-af57-3226c8ff454c
|
||||
volumes:
|
||||
- postgres:/var/lib/postgresql/data
|
||||
|
||||
volumes:
|
||||
postgres:
|
||||
@ -0,0 +1,30 @@
|
||||
require("dotenv").config();
|
||||
const mqtt = require("mqtt");
|
||||
const express = require("express");
|
||||
|
||||
// const db = require("./db");
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(require("./routes"))
|
||||
|
||||
app.use(express.static("public"));
|
||||
|
||||
app.listen(process.env.PORT || 8080, () => {
|
||||
console.log(`Listening on port ${process.env.PORT || 8080}`);
|
||||
});
|
||||
|
||||
const mqttClient = mqtt.connect(process.env.MQTT);
|
||||
|
||||
mqttClient.on("connect", (a) => {
|
||||
console.log(`Connected to ${process.env.MQTT}`);
|
||||
});
|
||||
|
||||
mqttClient.subscribe("motion");
|
||||
mqttClient.subscribe("sound");
|
||||
mqttClient.subscribe("temperature");
|
||||
mqttClient.subscribe("light");
|
||||
|
||||
mqttClient.on("message", (topic, message) => {
|
||||
console.log(topic, message.toString());
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,17 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"dotenv": "^16.3.1",
|
||||
"express": "^4.18.2",
|
||||
"mqtt": "^5.0.2",
|
||||
"pg": "^8.11.2"
|
||||
},
|
||||
"name": "alarm-controller",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"description": ""
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
const express = require("express");
|
||||
const Router = express.Router();
|
||||
|
||||
module.exports = Router;
|
||||
Loading…
Reference in New Issue