feat(rfid): more rfid topics while monitoring the system run

This commit is contained in:
2025-07-10 20:09:35 -05:00
parent 58711becf2
commit 6a082d9737
10 changed files with 87 additions and 12 deletions

View File

@@ -8,7 +8,22 @@ export const noRead = async (reader: string) => {
createLog(
"error",
"rfid",
"rifd",
"rfid",
`${reader} just had a no read please check for a tag and manually trigger a read.`
);
};
// noReadTimer.js
let timeout: any = null;
export const startNoReadTimer = (onTimeout: any, ms = 10000) => {
clearNoReadTimer(); // Always clear any previous timer
timeout = setTimeout(onTimeout, ms);
};
export const clearNoReadTimer = () => {
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
};

View File

@@ -3,6 +3,8 @@ import { createLog } from "../../logger/logger.js";
import { db } from "../../../../database/dbclient.js";
import { rfidReaders } from "../../../../database/schema/rfidReaders.js";
import { eq } from "drizzle-orm";
import { noRead, startNoReadTimer } from "./noRead.js";
import { badRead } from "./readerControl.js";
const authData = btoa("admin:Zebra123!");
let token: string;
@@ -63,6 +65,11 @@ const startRead = async (reader: string, ip: string) => {
//console.log(res.data);
if (res.status === 200) {
// start the no read timer
startNoReadTimer(() => {
noRead(reader);
badRead(reader);
});
setTimeout(() => {
stopRead(reader, ip);
}, 5 * 1000);

View File

@@ -48,7 +48,11 @@ export const badRead = async (reader: string) => {
try {
const badRead = await db
.update(rfidReaders)
.set({ lastTrigger: sql`NOW()`, lastTriggerGood: false })
.set({
lastTrigger: sql`NOW()`,
lastTriggerGood: false,
lastTagScanned: null,
})
.where(eq(rfidReaders.reader, reader));
createLog(
"info",

View File

@@ -11,12 +11,15 @@ import { sendEmail } from "../../../notifications/controller/sendMail.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { db } from "../../../../../database/dbclient.js";
import { rfidTags } from "../../../../../database/schema/rfidTags.js";
import { eq } from "drizzle-orm";
import { and, eq, gte, ne, sql } from "drizzle-orm";
import { rfidReaders } from "../../../../../database/schema/rfidReaders.js";
import { shouldSkipByCooldown } from "../../utils/rateLimit.js";
export const wrapperStuff = async (tagData: any) => {
console.log("WrapperTag", tagData[0].tag);
if (shouldSkipByCooldown("wrapperDouble Scan", 10)) return;
// update the reader with the last tag read.
const { error } = await tryCatch(
db
.update(rfidReaders)
@@ -53,8 +56,21 @@ export const wrapperStuff = async (tagData: any) => {
monitorChecks();
}
const { data: tagdata, error: tagError } = await tryCatch(
db.select().from(rfidTags).where(eq(rfidTags.tag, tagData[0].tag))
db
.select()
.from(rfidTags)
.where(
and(
eq(rfidTags.tag, tagData[0].tag),
gte(
rfidTags.lastRead,
sql.raw(`NOW() - INTERVAL '6 hours'`)
),
ne(rfidTags.lastareaIn, "wrapper1")
)
)
);
console.log("DB Data:", tagdata);
if (tagError) {
return {
success: false,
@@ -136,10 +152,12 @@ export const wrapperStuff = async (tagData: any) => {
const genlabel = await labelingProcess({
line: lineNum.toString(),
});
console.log(genlabel);
if (genlabel?.success) {
const createPrintData = {
...tagData[0],
runnungNr: parseInt(genlabel.data?.SSCC.slice(10, -1)),
runnungNumber: parseInt(genlabel.data?.SSCC.slice(10, -1)),
};
tagStuff([createPrintData]);

View File

@@ -9,6 +9,7 @@ export type TagData = {
antenna: number;
tagStrength: number;
lastareaIn?: string;
runningNumber?: number;
};
export const tagData = async (data: TagData[]) => {
/**

View File

@@ -26,6 +26,9 @@ export const tagStuff = async (tagData: TagData[]): Promise<any> => {
lastareaIn: tagData[i].reader,
antenna: tagData[i].antenna,
tagStrength: tagData[i].tagStrength,
runningNumber: tagData[i].runningNumber
? tagData[i].runningNumber
: null,
};
try {
// insert the tag with the onConflict update the tag