Skip to content

Commit

Permalink
Merge pull request #11 from sacconazzo:develop
Browse files Browse the repository at this point in the history
GET /data
  • Loading branch information
sacconazzo authored Aug 26, 2024
2 parents b28b0aa + 3d84a0d commit 5cd2f70
Show file tree
Hide file tree
Showing 4 changed files with 413 additions and 17 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"dependencies": {
"axios": "^1.6.7",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"knex": "0.15.2",
"mysql": "^2.18.1",
"node-cron": "^3.0.3",
Expand Down
10 changes: 7 additions & 3 deletions src/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const winston = require("winston");
const cron = require("node-cron");
const Gpio = require("pigpio").Gpio;
const http = require("http");
const app = require("express")();
const { Server } = require("socket.io");
const { exec, execSync } = require("child_process");
const db = require("./db");
Expand Down Expand Up @@ -52,14 +53,15 @@ const buttonShutDown = new Gpio(pinShutDown, {
});

// SHARE
const server = http.createServer();
const server = http.createServer(app);
const io = new Server(server);
server.listen(3000, () => {});
server.listen(3000);

const share = async () => {
pwmShare.hardwarePwmWrite(frequency, 20000);

try {
let data;
const system = {
uptime: execSync("uptime").toString(),
temp: Number(
Expand Down Expand Up @@ -118,7 +120,7 @@ const share = async () => {
// LIMIT 500;
);

const data = {
data = {
system,
dayWeek,
realtime,
Expand Down Expand Up @@ -149,6 +151,8 @@ const share = async () => {
cron.schedule(shareInterval, share);
share();

app.get("/data", (req, res) => res.json(data));

// BUTTONS
if (process.env.ENABLE_BUTTONS === "true") {
let waitReboot;
Expand Down
2 changes: 1 addition & 1 deletion tests/socket.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const io = require("socket.io-client");

const socket = io("http://localhost:3000");
const socket = io("http://10.8.0.5:3000");

socket.on("connect", () => {
console.log("connected!");
Expand Down
Loading

0 comments on commit 5cd2f70

Please sign in to comment.