Push POE project
This commit is contained in:
17
memory-bank/activeContext.md
Normal file
17
memory-bank/activeContext.md
Normal file
@ -0,0 +1,17 @@
|
||||
# Active Context
|
||||
|
||||
## Current Work Focus
|
||||
- The script is stable and functional, continuously reading temperature and humidity from a Modbus TCP device and publishing the data to an MQTT broker in pretty-printed JSON format.
|
||||
- The main focus is on reliability, error handling, and clear logging.
|
||||
|
||||
## Recent Changes
|
||||
- Improved JSON formatting for MQTT payloads (pretty print with indent).
|
||||
- Refined temperature calibration logic (subtracting 40 from raw value after scaling).
|
||||
- Enhanced logging for all major events and error conditions.
|
||||
- All configuration is now at the top of the script for easier modification.
|
||||
|
||||
## Next Steps
|
||||
- Optional: Parameterize configuration via environment variables or a config file for easier deployment.
|
||||
- Optional: Add support for additional Modbus registers or sensors.
|
||||
- Optional: Implement more advanced error recovery or alerting (e.g., email/SMS on repeated failures).
|
||||
- Optional: Containerize the application for easier deployment in production environments.
|
20
memory-bank/productContext.md
Normal file
20
memory-bank/productContext.md
Normal file
@ -0,0 +1,20 @@
|
||||
# Product Context
|
||||
|
||||
## Why This Project Exists
|
||||
Many industrial and environmental sensors use the Modbus protocol for data communication, while modern IoT and monitoring systems often rely on MQTT for data ingestion and distribution. This project bridges the gap between legacy Modbus devices and MQTT-based platforms, enabling seamless integration and real-time data flow.
|
||||
|
||||
## Problems Solved
|
||||
- Eliminates the need for manual data collection from Modbus sensors.
|
||||
- Automates the process of converting and forwarding sensor data to cloud or local MQTT brokers.
|
||||
- Provides a reliable, scriptable, and extensible solution for integrating Modbus sensors into IoT ecosystems.
|
||||
|
||||
## How It Should Work
|
||||
- The script runs continuously, connecting to a Modbus TCP device to read temperature and humidity data at regular intervals.
|
||||
- Data is processed and formatted as JSON, then published to a specified MQTT topic.
|
||||
- The system handles connection issues gracefully, with logging for troubleshooting.
|
||||
|
||||
## User Experience Goals
|
||||
- Simple configuration via code variables (host, port, credentials, topic, etc.).
|
||||
- Clear, timestamped logging for all major events and errors.
|
||||
- Data is published in a structured, readable JSON format for easy consumption by MQTT subscribers.
|
||||
- Minimal setup required; designed for headless/server environments.
|
23
memory-bank/progress.md
Normal file
23
memory-bank/progress.md
Normal file
@ -0,0 +1,23 @@
|
||||
# Progress
|
||||
|
||||
## What Works
|
||||
- The script successfully connects to both the Modbus TCP device and the MQTT broker.
|
||||
- Temperature and humidity data are read from the correct Modbus registers and calibrated as per device documentation.
|
||||
- Data is published to the MQTT topic in a pretty-printed JSON format.
|
||||
- Logging provides clear feedback on all major events and errors.
|
||||
- The script handles connection failures and retries in the main loop.
|
||||
|
||||
## What's Left to Build
|
||||
- (Optional) Configuration via environment variables or external config file.
|
||||
- (Optional) Support for additional sensors or Modbus registers.
|
||||
- (Optional) Advanced error notification (e.g., email/SMS alerts).
|
||||
- (Optional) Dockerfile or deployment scripts for production use.
|
||||
|
||||
## Current Status
|
||||
- The project is functional and meets its core requirements for a Modbus-to-MQTT bridge.
|
||||
- Ready for deployment in environments matching the current configuration.
|
||||
|
||||
## Known Issues
|
||||
- All configuration is hardcoded; not ideal for dynamic or multi-environment deployments.
|
||||
- No persistent storage or buffering if MQTT broker is temporarily unavailable.
|
||||
- No web UI or REST API for monitoring or control.
|
25
memory-bank/projectbrief.md
Normal file
25
memory-bank/projectbrief.md
Normal file
@ -0,0 +1,25 @@
|
||||
# Project Brief
|
||||
|
||||
## Project Name
|
||||
Modbus-to-MQTT Bridge for Environmental Sensor
|
||||
|
||||
## Overview
|
||||
This project implements a Python-based bridge that reads temperature and humidity data from a Modbus TCP device and publishes the readings to an MQTT broker in JSON format. The system is designed for continuous, automated data acquisition and integration with IoT or monitoring platforms.
|
||||
|
||||
## Core Requirements
|
||||
- Connect to a Modbus TCP device (sensor gateway) to read holding registers for temperature and humidity.
|
||||
- Process and calibrate the raw sensor data as per device documentation.
|
||||
- Publish the processed data to a specified MQTT topic at a configurable interval.
|
||||
- Support MQTT authentication (username/password).
|
||||
- Provide clear logging for connection, data acquisition, and publishing events.
|
||||
|
||||
## Goals
|
||||
- Enable seamless integration of Modbus-based sensors with MQTT-based IoT systems.
|
||||
- Ensure reliable, periodic data transfer with error handling and reconnection logic.
|
||||
- Maintain code clarity and extensibility for future enhancements (e.g., more sensors, additional data fields).
|
||||
|
||||
## Scope
|
||||
- Single Python script (poe.py) as the main application.
|
||||
- No web interface or GUI; headless operation via command line.
|
||||
- Focus on environmental data (temperature, humidity) but extensible for other Modbus registers.
|
||||
- No persistent storage; data is transient and only sent to MQTT.
|
21
memory-bank/systemPatterns.md
Normal file
21
memory-bank/systemPatterns.md
Normal file
@ -0,0 +1,21 @@
|
||||
# System Patterns
|
||||
|
||||
## System Architecture
|
||||
- **Single-process, event-driven script**: The application runs as a single Python process, using a main loop to periodically read from Modbus and publish to MQTT.
|
||||
- **Polling pattern**: Data is acquired from the Modbus device at a fixed interval (configurable via `PUBLISH_INTERVAL`).
|
||||
- **Bridge pattern**: The script acts as a bridge between two protocols (Modbus TCP and MQTT), translating and forwarding data.
|
||||
|
||||
## Key Technical Decisions
|
||||
- **Direct variable configuration**: All connection and operational parameters are set as variables at the top of the script for simplicity.
|
||||
- **Error handling and reconnection**: The script checks and re-establishes connections to both Modbus and MQTT as needed, with logging for all failures.
|
||||
- **JSON formatting**: Data is published in pretty-printed JSON for readability and ease of integration.
|
||||
- **Separation of concerns**: Reading/publishing logic is encapsulated in a dedicated function (`read_and_publish_data`), while the main loop handles orchestration and lifecycle.
|
||||
|
||||
## Design Patterns
|
||||
- **Callback pattern**: Used for MQTT events (on_connect, on_publish).
|
||||
- **Try/except/finally**: Used for robust error handling and resource cleanup.
|
||||
- **Headless operation**: No UI; all feedback is via logs and MQTT messages.
|
||||
|
||||
## Component Relationships
|
||||
- The Modbus client and MQTT client are instantiated and managed independently, but coordinated within the main loop.
|
||||
- Data flows from Modbus -> Python processing -> MQTT publish.
|
21
memory-bank/techContext.md
Normal file
21
memory-bank/techContext.md
Normal file
@ -0,0 +1,21 @@
|
||||
# Technical Context
|
||||
|
||||
## Technologies Used
|
||||
- **Python 3.x**: Main programming language.
|
||||
- **pymodbus**: For Modbus TCP client communication.
|
||||
- **paho-mqtt**: For MQTT client functionality.
|
||||
- **Logging**: Python's built-in logging module for event and error tracking.
|
||||
|
||||
## Dependencies
|
||||
- `pymodbus` (>=2.5, <4.0 recommended for current code)
|
||||
- `paho-mqtt`
|
||||
|
||||
## Development Setup
|
||||
- No external configuration files; all settings are in `poe.py` as variables.
|
||||
- Script is intended to run on any system with Python 3.x and the above dependencies installed.
|
||||
|
||||
## Technical Constraints
|
||||
- Assumes the Modbus device is accessible via TCP/IP and supports reading holding registers for temperature and humidity.
|
||||
- MQTT broker must be reachable from the host running the script.
|
||||
- No persistent storage or database integration; data is transient.
|
||||
- No web UI or REST API; all interaction is via logs and MQTT.
|
Reference in New Issue
Block a user