Smart Energy Meter with AWS cloud
Vertical: Industry 4.0
Step 1: Connect the A & B of energy meter to A & B pin in RuggedBoard RS485 port respectively.
For demonstration purpose I have used Elmeasure LG+ 1119 meter. If you are having any other meter then you have to read the datasheet of the meter vendor and provide proper parameters.
Step 2: Download the modpoll ARM execulatble binary and save it into your work directory. To download the file click below.
modpoll.bin
644KB
Binary
modpoll.bin
Step 3: Save the following code in .sh format on your working directory and name is as mbpoll.sh
./modpoll.bin -m rtu -a 1 -t 4:float -r 159 -b 9600 -s 1 -p none /dev/ttyS2
The above script has the following components:
- m : communication mode
- a : Slave address
- t : data types of the slave holding register
- r : Start Reference
- b : Baudrate
- s : Stopbits
- p : Parity Bit
- SERIALPORT : Serial port node of the RS485
Step 4: Run the above code to test ModBus communication
sh mbpoll.sh
If everything is correct your code will run without any error. and you can proceed to next stage.
Step 1: Connect the energy meter and the board as shown in the Stage 1.
Step 2: write the following code and save it as read_energymeter.py
#Python code to read data from Energy Meter:
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
from pymodbus.payload import BinaryPayloadDecoder
from pymodbus.payload import BinaryPayloadBuilder
from pymodbus.constants import Endian
import time
client = ModbusClient(method='rtu', port='/dev/ttyS2', stopbits=1, bytesize=8, baudrate=9600, parity='N')
connection = client.connect()
counter = 1
while True:
print("==========================================================")
print("Iteration {}" .format(counter))
print("----------------------------------------------------------")
WattHour = client.read_holding_registers(0x009E, 2, unit=1)
decoder = BinaryPayloadDecoder.fromRegisters(WattHour.registers, Endian.Big, wordorder=Endian.Little)
print("Watt Hour Reading:", float(decoder.decode_32bit_float()))
counter += 1
print("==========================================================")
time.sleep(2)