This repository contains a Python-based script to interface with PZEM energy monitoring devices using Modbus TCP. The script automates data recording, handles connection management, and logs data into CSV files.
- Connects to PZEM devices via Modbus TCP.
- Automatically generates and manages CSV files for daily logs.
- Periodically records voltage, current, and temperature.
- Handles errors such as device disconnection or communication failure.
- Python 3.6+
- Required Python packages:
pymodbus
datetime
threading
os
sys
- A PZEM device accessible via Modbus TCP.
-
Clone the repository:
git clone https://github.com/icecube/solar_panel_project.git
-
Navigate to the repository:
cd solar_panel_project
-
Install dependencies (different in case there of no internet):
pip install pymodbus
- Update the
ser = ModbusTcpClient
section in the script with your device's IP address and port. - Modify the
CONST_DEVICE_ID
if you are using a device ID other than0
.
-
Run the script:
python PZEMReader(Device0).py
-
The script will automatically:
- Attempt to connect to the specified PZEM device.
- Generate a new CSV file for daily logs in the
Documents/Icecube
folder. - Record voltage, current, and temperature periodically.
-
To stop the script, press
CTRL+C
. The current session will be saved.
- Files are stored in the
Documents/Icecube
directory under a folder named by the current year and month (e.g.,24_12
for December 2024). - Filenames are structured as follows:
Example:
<POLE><YY>_<DAY_OF_YEAR>_device_<DEVICE_ID>.csv
spo24_345_device_0.csv
- The script handles errors such as:
- File not found
- Permission issues
- Sensor disconnection or communication failure
- Logs
NO RESPONSE
for failed data reads.
For further information or questions, please contact:
- Manish Khanal ([email protected])
- Hayden Soelberg ([email protected])