44 lines
1.0 KiB
Python
44 lines
1.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Modbus to MQTT Bridge Service
|
|
|
|
This service reads temperature and humidity data from a Modbus TCP server
|
|
and publishes the data to an MQTT broker.
|
|
|
|
Usage:
|
|
python main.py
|
|
|
|
Author: POE Project
|
|
"""
|
|
|
|
import time
|
|
import logging
|
|
import sys
|
|
import os
|
|
|
|
if __name__ == "__main__":
|
|
# Setup logging first
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format='%(asctime)s - %(levelname)s - %(message)s',
|
|
handlers=[logging.StreamHandler(sys.stdout)]
|
|
)
|
|
|
|
logging.info("POE Sensor Bridge starting up...")
|
|
|
|
try:
|
|
# Import after logging is setup to avoid circular import issues
|
|
from sensor_bridge import main_loop
|
|
|
|
# Give the system a moment to initialize
|
|
time.sleep(2)
|
|
|
|
logging.info("Starting main sensor loop...")
|
|
main_loop()
|
|
|
|
except ImportError as e:
|
|
logging.error(f"Import error: {e}")
|
|
sys.exit(1)
|
|
except Exception as e:
|
|
logging.error(f"Fatal error: {e}", exc_info=True)
|
|
sys.exit(1) |