-
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.
- Loading branch information
Showing
14 changed files
with
1,156 additions
and
0 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,4 @@ | ||
node_modules | ||
ENV.json | ||
log/* | ||
offlineData |
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,25 @@ | ||
{ | ||
"main": { | ||
"port": "3000", | ||
"logDirectory": "/home/pi/raspberryAPI/log", | ||
"linebotAPI": "", | ||
"firebase": { | ||
"apiKey" : "", | ||
"authDomain" : "", | ||
"databaseURL" : "", | ||
"storageBucket" : "" | ||
} | ||
}, | ||
"rfid": { | ||
|
||
}, | ||
"lock": { | ||
"powerPIN": 0, | ||
"openPIN": 0 | ||
}, | ||
"glass": { | ||
"powerPIN": 0, | ||
"casePIN": 0, | ||
"detectPIN": 0 | ||
} | ||
} |
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,4 @@ | ||
{ | ||
"idNumber": "", | ||
"space": [] | ||
} |
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,26 @@ | ||
{ | ||
"spaceID": "", | ||
"space": "", | ||
"spaceRule": [ | ||
{ | ||
"type": "static", | ||
"method": "", | ||
"period": [ | ||
{ | ||
"from": "", | ||
"to": "" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "schedule", | ||
"method": "", | ||
"period": [ | ||
{ | ||
"from": "", | ||
"to": "" | ||
} | ||
] | ||
} | ||
] | ||
} |
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,8 @@ | ||
{ | ||
"idNumber": "", | ||
"name": "", | ||
"identity": "", | ||
"departmentGrade": "", | ||
"email": "", | ||
"lineUserID": "" | ||
} |
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,24 @@ | ||
const express = require('express'); | ||
const bodyParser = require('body-parser'); | ||
const request = require('request'); | ||
const config = require("./ENV.json"); | ||
const rpio = require('rpio'); | ||
const rfid = require('./modules/rfidReader')(config); | ||
const door = require('./modules/doorControl')(rpio, config); | ||
const logSystem = require('./modules/logControl'); | ||
|
||
var app = express(); | ||
|
||
app.use(bodyParser.urlencoded({ extended: false })); | ||
app.use(bodyParser.json()); | ||
|
||
rpio.init({mapping: 'physical'}); | ||
|
||
setInterval(function(){ | ||
console.log(rfid.read()); | ||
}, 500); | ||
|
||
var server = app.listen(config.main.port || 8080, function() { | ||
var port = server.address().port; | ||
console.log('API Server is running on port: ' + port + '!'); | ||
}); |
Empty file.
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,54 @@ | ||
module.exports = function (rpio, config) { | ||
|
||
var module = {}; | ||
|
||
module.doorInit = function () { | ||
_doorAttach(); | ||
} | ||
|
||
// control functions | ||
|
||
module.doorPowerSwitch = function () { | ||
rpio.read(config.lock.powerPIN) == 0 ? rpio.write(config.lock.powerPIN, rpio.HIGH) : rpio.write(config.lock.powerPIN, rpio.LOW) | ||
|
||
return rpio.read(config.lock.powerPIN); | ||
} | ||
|
||
module.doorOpenSwitch = function () { | ||
rpio.read(config.lock.openPIN) == 0 ? rpio.write(config.lock.openPIN, rpio.HIGH) : rpio.write(config.lock.openPIN, rpio.LOW) | ||
|
||
return rpio.read(config.lock.openPIN); | ||
} | ||
|
||
module.doorPowerState = function () { | ||
return rpio.read(config.lock.powerPIN); | ||
} | ||
|
||
module.doorOpenState = function () { | ||
return rpio.read(config.lock.openPIN); | ||
} | ||
|
||
function _doorAttach() { | ||
// connect relay and default power open and door close | ||
rpio.open(config.lock.powerPIN, rpio.OUTPUT, rpio.HIGH); | ||
rpio.open(config.lock.openPIN, rpio.OUTPUT, rpio.LOW); | ||
} | ||
|
||
function _doorDetach() { | ||
rpio.close(config.lock.powerPIN, rpio.PIN_RESET); | ||
rpio.close(config.lock.openPIN, rpio.PIN_RESET); | ||
} | ||
|
||
// listen event functions | ||
function _doorPowerPush() { | ||
// push Line API | ||
// logging | ||
} | ||
|
||
function _doorStatePush() { | ||
// push Line API | ||
// logging | ||
} | ||
|
||
return module; | ||
}; |
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,32 @@ | ||
module.exports = function(rpio, config){ | ||
|
||
var module = {} | ||
|
||
module.glassInit = function () { | ||
// connect relay and default power open and door close | ||
rpio.open(config.glass.powerPIN, rpio.OUTPUT, rpio.HIGH); | ||
rpio.open(config.glass.casePIN, rpio.INPUT); | ||
rpio.open(config.glass.detectPIN, rpio.INPUT); | ||
} | ||
|
||
// control functions | ||
|
||
module.glassPowerSwitch = function () { | ||
rpio.read(config.glass.powerPIN) == 0 ? rpio.write(config.glass.powerPIN, rpio.HIGH) : rpio.write(config.glass.powerPIN, rpio.LOW) | ||
|
||
return rpio.read(config.glass.powerPIN); | ||
} | ||
|
||
// listen event functions | ||
function glassDetectPush() { | ||
// push Line API | ||
// logging | ||
} | ||
|
||
function glassCasePush() { | ||
// push Line API | ||
// logging | ||
} | ||
|
||
return module; | ||
}(); |
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,28 @@ | ||
"use strict"; | ||
|
||
const winston = require('winston'); | ||
require('winston-daily-rotate-file'); | ||
|
||
module.exports = class logSystem { | ||
constructor(source, type) { | ||
this.source = source; | ||
this.type = type; | ||
this.transport = new (winston.transports.DailyRotateFile)({ | ||
filename: `${type}-%DATE%.log`, | ||
dirname: `${source}/${type}/`, | ||
datePattern: 'YYYY-MMM-DD', | ||
zippedArchive: false, | ||
maxSize: '20m', | ||
maxFiles: '14d' | ||
}); | ||
this.logger = new (winston.Logger)({ | ||
transports: [ | ||
this.transport | ||
] | ||
}); | ||
} | ||
|
||
record(log) { | ||
this.logger.info(log); | ||
} | ||
}; |
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,66 @@ | ||
const rfid = require('mfrc522-rpi'); | ||
|
||
module.exports = rfidReader; | ||
|
||
function rfidReader(config) { | ||
|
||
var module = {}; | ||
|
||
// listen to SPI channel 0 | ||
rfid.initWiringPi(0); | ||
|
||
//* | ||
// @string.padStart(@number, @string) | ||
// padding left | ||
// parameter: @number(total length), @string(padding with which string) | ||
// return @string | ||
//* | ||
|
||
// prototype to add left padding | ||
if (!String.prototype.padStart) { | ||
String.prototype.padStart = function padStart(targetLength,padString) { | ||
targetLength = targetLength>>0; //truncate if number or convert non-number to 0; | ||
padString = String((typeof padString !== 'undefined' ? padString : ' ')); | ||
if (this.length > targetLength) { | ||
return String(this); | ||
} | ||
else { | ||
targetLength = targetLength-this.length; | ||
if (targetLength > padString.length) { | ||
padString += padString.repeat(targetLength/padString.length); //append to original to ensure we are longer than needed | ||
} | ||
return padString.slice(0,targetLength) + String(this); | ||
} | ||
}; | ||
} | ||
|
||
module.verify = function() { | ||
|
||
} | ||
|
||
function read() { | ||
// reset card | ||
rfid.reset(); | ||
|
||
// Scan for cards | ||
var response = rfid.findCard(); | ||
if (!response.status) { | ||
return "No Card"; | ||
} | ||
|
||
// Get the UID of the card | ||
response = rfid.getUid(); | ||
if (!response.status) { | ||
return "UID Scan Error"; | ||
} | ||
|
||
// If we have the UID, continue | ||
const uid = response.data; | ||
|
||
//# Rebuild uid to match card's ID | ||
var cardID = uid[3].toString(16).padStart(2, "0") + uid[2].toString(16).padStart(2, "0") + uid[1].toString(16).padStart(2, "0") + uid[0].toString(16).padStart(2, "0") | ||
return parseInt(cardID, 16); | ||
} | ||
|
||
return module; | ||
}; |
Empty file.
Oops, something went wrong.