diff --git a/README.md b/README.md index ac7b06b..f422097 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,10 @@ $ sudo npm install -g pino-pretty Launch application in developer environment. ``` $ npm run start + +or + +$ npm run start | pino-pretty ``` For test. diff --git a/db/querys/getArcs.js b/db/querys/getArcs.js new file mode 100644 index 0000000..0934372 --- /dev/null +++ b/db/querys/getArcs.js @@ -0,0 +1,6 @@ +import con from '../connect.js'; + +export default async() => { + const [arcs] = await con.query(`SELECT id as arcId, printerFk, ip, minimum FROM vn.arcRead;`); + return arcs; +}; diff --git a/server.js b/server.js index 49210a5..1f9c039 100644 --- a/server.js +++ b/server.js @@ -1,15 +1,21 @@ import stream from './src/stream.js'; import getConfig from './util/getConfig.js'; import logger from 'pino'; +import getArcs from './db/querys/getArcs.js'; + console.logger = logger(); -function main() { +async function main(arcId) { const conf = getConfig(); - stream(conf, e => { - console.logger.error(e); - setTimeout(main, conf.reconnectInterval); - }); + for (let arc of await getArcs()) { + const config = Object.assign({}, conf, arc); + if (arcId && arcId != arc.arcId) continue; + stream(config, e => { + console.logger.error(e); + setTimeout(main, config.reconnectInterval, config.arcId); + }); + } } main(); diff --git a/src/stream.js b/src/stream.js index f8dd802..71eab03 100644 --- a/src/stream.js +++ b/src/stream.js @@ -39,7 +39,8 @@ export default async(conf, cb) => { function createPallet() { clearTimeout(interval); - newPallet(rfidbuffer, conf.arcId); + if (!conf.minimum || rfidbuffer.size > conf.minimum) + newPallet(rfidbuffer, conf.arcId); rfidbuffer = new Set(); rfidbufferExtend = [];