dev to master #3
|
@ -2,7 +2,7 @@ arcId: 1
|
||||||
port: 1234
|
port: 1234
|
||||||
ip: 1.2.3.4
|
ip: 1.2.3.4
|
||||||
env: dev
|
env: dev
|
||||||
interval: 1000
|
interval: 3000
|
||||||
reconnectInterval: 5000
|
reconnectInterval: 5000
|
||||||
counterInterval: 1000
|
counterInterval: 1000
|
||||||
db:
|
db:
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"author": "Verdnatura Levante SL",
|
"author": "Verdnatura Levante SL",
|
||||||
"description": "rfid backend",
|
"description": "rfid backend",
|
||||||
"main": "index.js",
|
"main": "server.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "nodemon ./server.js"
|
"start": "nodemon ./server.js"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import con from '../db/connect.js';
|
import con from '../db/connect.js';
|
||||||
|
|
||||||
export default async(size, arcId) => {
|
export default async(size, arcId) => {
|
||||||
|
console.logger.info(`COUNTER: SIZE:${size} ARC_ID:${arcId}`);
|
||||||
await con.query(`
|
await con.query(`
|
||||||
UPDATE vn.arcRead
|
UPDATE vn.arcRead
|
||||||
SET counter = ?
|
SET counter = ?
|
||||||
|
|
|
@ -5,8 +5,8 @@ export default async(rfids, arcId) => {
|
||||||
console.logger.info('PRINTING...');
|
console.logger.info('PRINTING...');
|
||||||
console.log([Array.from(rfids), arcId, null]);
|
console.log([Array.from(rfids), arcId, null]);
|
||||||
await con.query(`CALL vn.expeditionPallet_build(JSON_ARRAY(?), ?, ?, @palletId);`, [Array.from(rfids), arcId, null]);
|
await con.query(`CALL vn.expeditionPallet_build(JSON_ARRAY(?), ?, ?, @palletId);`, [Array.from(rfids), arcId, null]);
|
||||||
const palletId = await con.query(`SELECT @palletId;`);
|
const [[{palletId}]] = await con.query(`SELECT @palletId as palletId;`);
|
||||||
console.log(palletId);
|
|
||||||
await counter(null, arcId);
|
await counter(null, arcId);
|
||||||
if (!palletId)
|
if (!palletId)
|
||||||
console.logger.error({error: 'ERROR_CREATING_PALLET', expeditions: rfids});
|
console.logger.error({error: 'ERROR_CREATING_PALLET', expeditions: rfids});
|
||||||
|
|
|
@ -5,18 +5,19 @@ import debug from '../util/debugStream.js';
|
||||||
import counter from './counter.js';
|
import counter from './counter.js';
|
||||||
|
|
||||||
let interval;
|
let interval;
|
||||||
|
let counterInterval;
|
||||||
|
|
||||||
export default async(conf, cb) => {
|
export default async(conf, cb) => {
|
||||||
let rfidbuffer = new Set();
|
let rfidbuffer = new Set();
|
||||||
let rfidbufferExtend = [];
|
let rfidbufferExtend = [];
|
||||||
|
|
||||||
const counterInterval = setInterval(counter, conf.counterInterval, rfidbuffer.size, conf.arcId);
|
|
||||||
const stream = got.stream(`http://${conf.ip}/api/v1/data/stream`);
|
const stream = got.stream(`http://${conf.ip}/api/v1/data/stream`);
|
||||||
|
|
||||||
stream
|
stream
|
||||||
.on('data', async value => {
|
.on('data', async value => {
|
||||||
const parsed = await rfidParser(value);
|
const parsed = await rfidParser(value);
|
||||||
console.log(parsed.codes);
|
console.log(parsed.codes);
|
||||||
|
if (!parsed.codes.size) return;
|
||||||
rfidbuffer = new Set([...rfidbuffer, ...parsed.codes]);
|
rfidbuffer = new Set([...rfidbuffer, ...parsed.codes]);
|
||||||
rfidbufferExtend = rfidbufferExtend.concat(parsed.extended);
|
rfidbufferExtend = rfidbufferExtend.concat(parsed.extended);
|
||||||
|
|
||||||
|
@ -26,6 +27,9 @@ export default async(conf, cb) => {
|
||||||
clearTimeout(interval);
|
clearTimeout(interval);
|
||||||
interval = null;
|
interval = null;
|
||||||
interval = setTimeout(createPallet, conf.interval);
|
interval = setTimeout(createPallet, conf.interval);
|
||||||
|
|
||||||
|
if (!counterInterval)
|
||||||
|
counterInterval = setTimeout(counterIntervalManager, conf.counterInterval);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.on('error', e => {
|
.on('error', e => {
|
||||||
|
@ -34,11 +38,15 @@ export default async(conf, cb) => {
|
||||||
|
|
||||||
function createPallet() {
|
function createPallet() {
|
||||||
clearTimeout(interval); // try remove
|
clearTimeout(interval); // try remove
|
||||||
clearInterval(counterInterval); // try remove
|
|
||||||
|
|
||||||
newPallet(rfidbuffer, conf.arcId);
|
newPallet(rfidbuffer, conf.arcId);
|
||||||
|
|
||||||
rfidbuffer = new Set();
|
rfidbuffer = new Set();
|
||||||
rfidbufferExtend = [];
|
rfidbufferExtend = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function counterIntervalManager() {
|
||||||
|
counterInterval = null;
|
||||||
|
counter(rfidbuffer.size, conf.arcId);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,7 +18,7 @@ export default (parsed, conf) => {
|
||||||
// WARNING IF AN ANTENNA READS LESS THAN IT SHOULD
|
// WARNING IF AN ANTENNA READS LESS THAN IT SHOULD
|
||||||
for (const [index, set] of uniqueRead.entries()) {
|
for (const [index, set] of uniqueRead.entries()) {
|
||||||
if (((set.size * 100) / parsed.codes.size) < 25)
|
if (((set.size * 100) / parsed.codes.size) < 25)
|
||||||
console.log('[WARNING_ANTENNA]: ', index + 1, ' ONLY ', set.size);
|
console.logger.warn(`[ANTENNA]: ${index + 1} ONLY ${set.size}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('----------------------------------------------------------------');
|
console.log('----------------------------------------------------------------');
|
||||||
|
|
Loading…
Reference in New Issue