2017-08-22 01:11:07 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const ble = require('./lib/blootstrap')
|
2017-08-22 01:23:48 +00:00
|
|
|
const restify = require('restify')
|
|
|
|
const logger = require('winston')
|
2017-08-22 01:11:07 +00:00
|
|
|
const gpio = require('gpio')
|
2017-08-22 02:59:44 +00:00
|
|
|
const fs = require('fs')
|
2017-08-22 01:23:48 +00:00
|
|
|
const pin = {}
|
|
|
|
|
2017-08-22 02:59:44 +00:00
|
|
|
const PACKAGE = require('./package.json')
|
2017-08-22 01:11:07 +00:00
|
|
|
const PORT = process.env.PORT || 6699
|
2017-08-22 02:59:44 +00:00
|
|
|
const APPNAME = PACKAGE.name
|
|
|
|
const INDEX = fs.readFileSync('./app/www/index.html', 'utf8')
|
2017-08-22 01:23:48 +00:00
|
|
|
|
|
|
|
let app = restify.createServer({
|
|
|
|
name: APPNAME,
|
2017-08-22 02:59:44 +00:00
|
|
|
version: '0.0.1'
|
2017-08-22 01:23:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
function createPins () {
|
|
|
|
pin.four = gpio.export(4, {
|
|
|
|
direction: 'out',
|
|
|
|
interval: 100,
|
|
|
|
ready : () => {
|
2017-08-22 02:59:44 +00:00
|
|
|
logger.info(`Set pin 4 to OUTPUT`)
|
2017-08-22 01:23:48 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-08-22 02:59:44 +00:00
|
|
|
function createServer () {
|
|
|
|
app.get('/', index)
|
|
|
|
//app.all('/frame', rFrame)
|
|
|
|
app.get('/status', status)
|
|
|
|
app.listen(PORT, () => {
|
|
|
|
console.log(`${APPNAME} listening on port ${PORT}!`)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function rFrame (req, res, next) {
|
|
|
|
res.send({})
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
|
|
|
|
function frame (dir = true, length = 0, delay = 0) {
|
2017-08-22 01:23:48 +00:00
|
|
|
|
2017-08-22 01:11:07 +00:00
|
|
|
}
|
|
|
|
|
2017-08-22 02:59:44 +00:00
|
|
|
function rStatus (req, res, next) {
|
|
|
|
const obj = status()
|
|
|
|
res.send(obj)
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
|
|
|
|
function status () {
|
|
|
|
const obj = {}
|
|
|
|
return obj
|
|
|
|
}
|
|
|
|
|
2017-08-22 01:11:07 +00:00
|
|
|
function index (req, res, next) {
|
2017-08-22 02:59:44 +00:00
|
|
|
res.end(INDEX)
|
|
|
|
return next()
|
2017-08-22 01:11:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-22 02:59:44 +00:00
|
|
|
function init () {
|
|
|
|
createPins()
|
|
|
|
createServer()
|
|
|
|
|
|
|
|
ble.on('data', (str) => {
|
|
|
|
console.log(str)
|
|
|
|
})
|
|
|
|
}
|
2017-08-22 01:11:07 +00:00
|
|
|
|
2017-08-22 02:59:44 +00:00
|
|
|
init()
|