Skip to content

Commit

Permalink
add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Reinstein committed Aug 4, 2019
1 parent 62edf43 commit 2add909
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
height
history
node_modules
package-lock.json
3 changes: 3 additions & 0 deletions desk-machine.js
Expand Up @@ -8,6 +8,8 @@ const gpio = require('rpi-gpio')

const MAX_HEIGHT = 18
const HEIGHT_FILE = __dirname + '/height'
const HISTORY_FILE = __dirname + '/history'

const SPEED = 0.56 // how fast the desk extends/retracts (inches per second)

const gpiop = gpio.promise
Expand All @@ -22,6 +24,7 @@ let currentHeight = 0

function saveHeight (height) {
fs.writeFileSync(HEIGHT_FILE, height, 'utf8')
fs.appendFileSync(HISTORY_FILE, `${Date.now()},${height}\n`)
}


Expand Down
9 changes: 9 additions & 0 deletions index.js
Expand Up @@ -5,6 +5,7 @@
const delay = require('delay')
const deskMachine = require('./desk-machine.js')
const express = require('express')
const fs = require('fs')
const register = require('register-multicast-dns')
const safeHandler = require('async-middleware').wrap
const serveStatic = require('serve-static')
Expand All @@ -24,6 +25,14 @@ app.use(function (req, res, next) {
return next()
})

app.get('/history', function (req, res) {
if (!fs.existsSync(__dirname + '/history'))
return res.send('')

const history = fs.readFileSync(__dirname + '/history', 'utf8')
res.send(history)
})

app.get('/state', safeHandler(async function (req, res) {
req.socket.setTimeout(0);
req.socket.setNoDelay(true);
Expand Down

0 comments on commit 2add909

Please sign in to comment.