Commit Graph

28 Commits

Author SHA1 Message Date
Wizznu c79033de91 fix: Add polling mechanism for sensor threshold monitoring
Problem:
- Firebase SDK listener not triggering (SDK timeout)
- No sensor data being checked despite sensor=true
- Log shows no SENSOR CHECK output

Solution:
- Add polling every 30 seconds using REST API (reliable)
- Keep Firebase listener as backup if SDK recovers
- Check kontrolConfig.sensor flag before processing
- Shared checkSensorThresholds() function for both methods

This ensures sensor mode works even when Firebase SDK fails
2026-02-16 19:45:29 +07:00
Wizznu 581ab42fac feat: Add verbose logging for sensor mode threshold monitoring
- Log every sensor check with full sensor data
- Display threshold config for each check
- Show detailed evaluation for each pot
- Log cooldown status and trigger events
- Help debug why mosfet not triggering
2026-02-16 19:30:34 +07:00
Wizznu 91cb3eaaea feat: Dynamic threshold system for sensor-based watering
- Detect all threshold_* nodes from kontrol_1
- Support unlimited threshold configurations
- Each threshold: batas_bawah, batas_atas, smart_mode, pot_aktif[], pompa settings
- Smart mode: water until batas_atas reached
- Fixed mode: water for fixed duration
- Setup script: setup-firebase-threshold.js for auto Firebase initialization
- Improved logging: show threshold ID, mode, and pot info on trigger
2026-02-16 12:31:26 +07:00
Wizznu 6f4b7c25f1 feat: Flexible jadwal system + kontrol_1 path support
- Added FIREBASE_PATHS config for easy path switching
- Support unlimited jadwal (jadwal_1, jadwal_2, ... jadwal_N)
- Each jadwal can select specific pots (pot_aktif array)
- Per-schedule config: duration, pompa_air, pompa_pupuk
- Updated all kontrol refs to use FIREBASE_PATHS.kontrol (kontrol_1)
- Added setup script for auto Firebase initialization
- Added comprehensive documentation (FLEXIBLE_SCHEDULE_GUIDE.md)
- Backward compatible with legacy waktu_1/waktu_2 format

Files added:
- setup-firebase-jadwal.js: Auto setup Firebase jadwal
- FLEXIBLE_SCHEDULE_GUIDE.md: Complete guide for flexible schedules
- firebase-example.json: Example Firebase structure

Changes:
- worker.js: Dynamic schedule detection, kontrol_1 path support
2026-02-16 11:05:22 +07:00
Wizznu 561881e18e fix: Optimize Firebase connection with smart fallback system - SDK timeout 10s->5s - Smart fallback after 3 consecutive failures - API statistics tracking (SDK vs REST) - Auto-recovery every 50 minutes 2026-02-16 09:58:17 +07:00
Wizznu 5e85ad61e2 HOTFIX: Fix incomplete replacement causing syntax errors in setFirebaseViaREST and readFirebaseSmart 2026-02-11 12:32:48 +07:00
Wizznu 935e1059f6 CRITICAL: Fix fetch() timeout not working in Node.js + add job-level timeout + extensive debug logging 2026-02-11 12:23:10 +07:00
Wizznu 1fc1d7ecbc HOTFIX: Fix syntax error in healthCheck function (line 878) 2026-02-11 12:01:16 +07:00
Wizznu 895ce4c1fe CRITICAL FIX: Add timeout+REST fallback for ALL Firebase operations (set, read, delete) 2026-02-11 11:57:25 +07:00
Wizznu 68ce136317 Fix Firebase update timeout: add REST API fallback for write operations 2026-02-11 11:39:09 +07:00
Wizznu 5c8c93c104 Fix BullMQ job ID: replace colon with underscore 2026-02-11 11:25:43 +07:00
Wizznu 4d9add606e Add Firebase REST API fallback and smart fetch mechanism 2026-02-11 11:12:03 +07:00
Wizznu 6ce4affe6b Critical fix: Add timeout handler for Firebase fetch to prevent hanging 2026-02-11 11:03:19 +07:00
Wizznu 6e4f73928f Add extensive debug logging to trace checkScheduledWatering execution 2026-02-11 10:49:56 +07:00
Wizznu 556199a28d Fix: Add error handling and timing fix for scheduler checks 2026-02-11 10:38:33 +07:00
Wizznu 6cf05184f5 Add urgent fix summary and action steps 2026-02-11 10:30:51 +07:00
Wizznu 025c39a4f0 Add comprehensive debugging guide for scheduler and aktuator issues 2026-02-11 10:29:15 +07:00
Wizznu 76bb751962 Fix: Add verbose logging for debugging scheduler and aktuator issues 2026-02-11 10:27:13 +07:00
Wizznu 8b8ad29c4d Add debugging: time sync monitoring, manual test functions, aktuator validation 2026-02-11 10:06:49 +07:00
Wizznu 4434a05db1 Completely suppress Firebase SDK warnings 2026-02-11 07:58:50 +07:00
Wizznu acefe143b4 Add crash prevention and keep-alive mechanisms 2026-02-11 07:55:08 +07:00
Wizznu 2f59a363da Optimize worker: reduce Firebase warnings and verbose logging 2026-02-11 07:49:29 +07:00
Wizznu 9b64706b4d Merge and update Railway Worker with fixes 2026-02-11 07:42:09 +07:00
Wizznu 8da7b66494 Initial commit: Railway Worker for ApsGo IoT System 2026-02-11 07:40:33 +07:00
Wizznu 59dc0b45d9 fix: Remove BOM from railway.json
Fixed Railway deployment error:
'invalid character ï looking for beginning of value'

Cause: UTF-8 BOM (Byte Order Mark) at file start
Solution: Recreated file with UTF-8 without BOM
Railway JSON parser now reads correctly
2026-02-10 11:37:34 +07:00
Wizznu 94499d02d5 feat: Add Dockerfile for Railway deployment
Added production-ready Dockerfile:
- Node.js 18 Alpine (lightweight)
- Multi-stage dependency installation
- Health check monitoring
- Non-root user for security
- Production optimizations

Added .dockerignore:
- Exclude node_modules (reinstalled in Docker)
- Exclude .env files (Railway injects env vars)
- Reduce image size
- Faster build times

Railway will now detect project type via Dockerfile instead of guessing from package.json.
This ensures proper build configuration for BullMQ worker.
2026-02-10 11:29:49 +07:00
Wizznu a9d894b2fd feat: ApsGo Railway Worker - 24/7 Background Automation
Complete Node.js worker for IoT automation:

Features:
- Waktu Mode: Time-based scheduling with cron
- Sensor Mode: Threshold-based automation
- BullMQ + Redis: Queue management (prevent race conditions)
- Firebase Admin: Realtime Database integration
- Auto History Logging: Every 10 minutes
- Health Monitoring: Auto-restart on failure
- Graceful Shutdown: Clean resource cleanup

Architecture:
- NO HTTP server (background worker only)
- Listen to Firebase Realtime DB changes
- Process jobs from Redis queue
- Execute scheduled tasks via cron

Tech Stack:
- Node.js 18+
- Firebase Admin SDK
- BullMQ (job queue)
- Redis (in-memory DB)
- IoRedis client

Files:
- worker.js: Main worker implementation (500+ lines)
- package.json: Dependencies and scripts
- railway.json: Railway deployment config (NO healthcheck - worker not HTTP)
- .env.example: Environment variables template
- README.md: Complete documentation
- .gitignore: Node modules, env files, logs

Ready for Railway deployment!
Connect to Redis and set Firebase environment variables.
2026-02-10 10:52:29 +07:00
awisnuu 8df97e29ec
Initial commit 2026-02-10 10:49:24 +07:00