Pages

Monday 17 June 2019

Modbus Energy Meter Reading using GPRS MQTT Protocol - Indino 4.0


Energy meters with an integrated Serial RS485 Modbus interface allow direct reading of all relevant data, such as energy , current and voltage , frequency and form factor for every phase and active and reactive power for every phase and for the three phases


step 1- Select the required parameter and register address of the modbus energy Meter as shown in the below given image .


Step 2- Copy the code and change the required parameter 

Step 3 - Execute the code 

Step 4 Watch the expected result at cloud MQQT Server








Test Setup

/*
* The example file shows making a phone call
*  
* Pin Connection :  
*  
*/
#include <IndinoDI.h>  
String data1;
/*    Cloud initialisation         */
char* host = "m16.cloudmqtt.com";
//char* host = "52.3.184.147";
char* port = "16997";
char* username = "eoszmzsz";
char* password = "at1yeUD1pERj";
char* topic = "meter";
char *APN = "INTERNET"; //Vodafone
uint8_t funCode = 0x04; //Read holding register
uint8_t slave_id = 1;
uint16_t start_addr = 3854; //Address to read frequency=3854
uint16_t start_addr1 = 3850; //Line to Neutral Voltage=3850
uint16_t start_addr2 = 3846; //Avg PF=3846
uint16_t len = 2; //Datatype is 32-bit Float for MFR 2810
uint16_t data[2] = {0};
uint8_t freq_hex_bytes[4] = {0};
float frequency = 0;
float voltage = 0;
float power = 0;
uint32_t VALUE;
char data2[80];
void setup()
{
Serial.begin(9600);
Serial3.begin(9600);
Indino_Modbus_Master_Init();
delay(2000);
pinMode(41, OUTPUT);
delay(2000);
Serial.println("Start..");
power_on(APN);
delay(1000);
}
void loop()
{
Indino_Modbus_Master_Read_Raw(funCode, slave_id, start_addr, len, data);
/*     place register values in byte array, lsb in position 0      */
freq_hex_bytes[3] = (data[1] & 0xFF00) >> 8;  
freq_hex_bytes[2] = (data[1] & 0x00FF);
freq_hex_bytes[1] = (data[0] & 0xFF00) >> 8;  
freq_hex_bytes[0] = (data[0] & 0x00FF);
/*    Convert to Float         */
memcpy(&frequency, freq_hex_bytes , 4);
Serial.print("Frequency =");
Serial.print(frequency,2);
Serial.println(" Hz");
delay(300);
Indino_Modbus_Master_Read_Raw(funCode, slave_id, start_addr1, len, data);
/*    place register values in byte array, lsb in position 0        */
freq_hex_bytes[3] = (data[1] & 0xFF00) >> 8;  
freq_hex_bytes[2] = (data[1] & 0x00FF);
freq_hex_bytes[1] = (data[0] & 0xFF00) >> 8;  
freq_hex_bytes[0] = (data[0] & 0x00FF);
/*      Convert to Float          */
memcpy(&voltage, freq_hex_bytes , 4);
Serial.print("Line to Neutral Voltage =");
Serial.print(voltage,2);
Serial.println(" volts");
delay(300);
Indino_Modbus_Master_Read_Raw(funCode, slave_id, start_addr2, len, data);
/*     place register values in byte array, lsb in position 0      */
freq_hex_bytes[3] = (data[1] & 0xFF00) >> 8;  
freq_hex_bytes[2] = (data[1] & 0x00FF);
freq_hex_bytes[1] = (data[0] & 0xFF00) >> 8;  
freq_hex_bytes[0] = (data[0] & 0x00FF);
/*     Convert to Float         */
memcpy(&power, freq_hex_bytes , 4);
Serial.print("Power factor =");
Serial.print(power,2);
Serial.println(" PF");
data1 ="Frequency=";
data1 +=frequency;
data1 +=",Voltage=";
data1 +=voltage;
data1 +=",Powerfactor=";
data1 +=power;
for(int i=0;i<data1.length();i++)
data2[i]=data1[i];
Serial.println(data2);
Indino_GPRS_Upload_MQTT(data2, APN, host, port, username, password, topic);
delay(3000);
}

For more details visit www.rdltech.in

No comments:

Post a Comment