Stage 1 : Testing ModDus Communication (RS485) using modpoll
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.
Step 3: Save the following code in .sh format on your working directory and name is as mbpoll.sh
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.
Stage 2: Reading the Energy Meter values using Python 3 Script.
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 ModbusClientfrom pymodbus.payload import BinaryPayloadDecoderfrom pymodbus.payload import BinaryPayloadBuilderfrom pymodbus.constants import Endianimport timeclient =ModbusClient(method='rtu', port='/dev/ttyS2', stopbits=1, bytesize=8, baudrate=9600, parity='N')connection = client.connect()counter =1whileTrue: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 +=1print("==========================================================") time.sleep(2)
Step 3: Run the above code to read data from Energy Meter
python read_energymeter.py
If everything is correct your code will run without any error and you can proceed to next stage to send the data to a AWS cloud and view it on a dashboard.
Stage 3: Reading the Energy meter values using Python 3 Script
I this stage you will be able to send command from cloud server (AWS) and start replying to the request from cloud. In this example we will send a command from cloud to start sending Energy Meter data and stop sending when the timer is out.
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 lg1119.py