Energy Monitoring Using Armtronix Wifi LoRa (IA013B) and LG+ 3399

Single Phase Energy Monitoring using Armtronix Wifi RS485 LoRa (IA013 D) and PZEM-016

In this blog we would like to show you Energy monitoring Using LG+ 3399 RS485 energy meter (works for WC4400 also) and Armtronix (IA013 Type – B) device. In this setup we are reading LG+ 3399 measurement values using ESP32 via RS485(modbus) and publishing the data via LoRa (here LoRa is interfacing with ESP32 via SPI) and to the MQTT. Also we are displaying the required parameters in nodeRED dashboard using the TTN MQTT.

Components Required:

2018-09-12T11_34_43.529Z-lora3
IA013_Types-1
NOTE : In this blog we are using IA013-Type B device.

Loading firmware on ESP32

 we have to install the following libraries in arduino ide

you can install the above libraries form Arduino library manager by clicking ctrl+shift+I

So now download the Armtronix IA013 code from github using the below link.

https://github.com/armtronix/IA013_Wifi_RS485_Lora/tree/master/LoRa_Energy_Monitoring_ESP32_and_LoRa_01012021

now open the LoRa_Energy_Monitoring_ESP32_and_LoRa_01012021.ino and you have to add your ttn network keys (Network Session Key, Device Address, Device Address) in the code.

ttn-abp device details.

Now we can upload the code with the following upload setting and proper usb port.

i.e open the code in the Arduino IDE, go to tools and select the settings as follows.

  • Board : “NodeMCU-32S”
  • Upload speed : “115200”
  • Flash Frequency : “40MHz”

So to upload the code on ESP32 of IA013 you need a micro – usb cable (As IA013 has in built USB to UART converter) and Arduino IDE installed . and make sure the programming jumpers are placed properly on header J5

ie Connect Pin1 (TXDE) with Pin2 (TXD) and Pin7 (RXDE) and Pin8 (RXD) as shown in the below fig.

Header
device

once you are done with adding all the libraries and code is compiled, you can upload the code by selecting proper port.

Connection:

Make the connection as per the below wiring diagram shown below.

Reading the Input Registors :

Here in the LG+ 3399 energy meter, we will get 30 input registors. Each registor will take two bytes so to read all 30 parameter we will get 60 bytes payload data, But the Lmic library will take only 51 bytes of data at once. So, because of this here we are reading 24 input registors which are important for us. You can make the modifications in the code to read the parameters whichever important for you. And while modifying the code make sure that the index number of the bytes are serially in order and in ttn network for payload formatting, you are using same bytes which you assigned in the code.

Configurartion of ESP32:

Once you are done with the proper connection turn on the main supply and when the IA013 is turned on for first time you have to configure it using your wifi ssid password. so here IA013 will a host will be hosting as an access point (Eg : Armtronix-94-4f-54 where alphanumeric is mac last six digits of mac address of IA013), once you are connected to the AP enter 192.168.4.1 in your browser, A webpage will be loaded as shown below. there are two IOT options available ie HTTP and MQTT. To operate IA013 on HTTP you have to just fill Ssid and password (if exist) and select http button and click on submit and for mqtt you have to fill all the credentials ie ssid, password(if exist), mqtt broker, mqtt username(if exist), mqtt password(if exist), Subscribe topic, Publish topic and click on submit.

20190706-175001-1

Mqtt topics Example:

If the Device MQTT publish topic is “MP” and subscribe topic is “MS”

Then the following topics you have to subscribe to get the data

  • “MP/Voltage” for voltage
  • “MP/Current” for current
  • “MP/Power” for Power in watts
  • “MP/Wh” for energy in Wh
  • “MP/Frequency” for frequency in Hz
  • “MP/PF” for power factorLoRa_Energy_Monitoring_ESP32_and_LoRa_01012021.ino
  • “MP” you will receive all data in a JSON format.

As per our code, we are are reading the only six parameters individually for example point of view. So, there are only six topics to read the individual parameters. If you wish to read more parameters you can add them in the code and also you can read them in seperate topics.

Now all the setup is done and we are receving date on ttn console and also in mqtt.

Date receiving via IA013, payload formatting code is given below.

function Decoder(bytes, port) {
   // Decode an uplink message from a buffer
 // Decode bytes to int
   var watts_total = (bytes[0] << 8) | bytes[1];
   var watts_r_phase = (bytes[2]<< 8) | bytes[3];
   var watts_y_phase = (bytes[4]<<8) | bytes[5];
   var watts_b_phase = (bytes[6] << 8) | bytes[7];
   var var_total = (bytes[8] << 8) | bytes[9];
   var var_r_phase = (bytes[10] << 8) | bytes[11];
   var var_y_phase = (bytes[12] << 8) | bytes[13];
   var var_b_phase = (bytes[14] << 8) | bytes[15];
   var pf_average = (bytes[16] << 8) | bytes[17];
   var pf_r_phase = (bytes[18] << 8) | bytes[19];
   //var pf_y_phase = (bytes[20] << 8) | bytes[21];
   //var pf_b_phase = (bytes[22] << 8) | bytes[23];
   var va_total = (bytes[20] << 8) | bytes[21];
   var va_r_phase = (bytes[22] << 8) | bytes[23];
   var va_y_phase = (bytes[24] << 8) | bytes[25];
   var va_b_phase = (bytes[26] << 8) | bytes[27];
   var vll_average = (bytes[28] << 8) | bytes[29];
   var vry_phase = (bytes[30] << 8) | bytes[31];
   var vyb_phase = (bytes[32] << 8) | bytes[33];
   var vbr_phase = (bytes[34] << 8) | bytes[35];
   var vln_average = (bytes[36] << 8) | bytes[37];
   var v_r_phase = (bytes[38] << 8) | bytes[39];
  // var v_y_phase = (bytes[44] << 8) | bytes[45];
  // var v_b_phase = (bytes[46] << 8) | bytes[47];
   var current_total = (bytes[40] << 8) | bytes[41];
   var current_r_phase = (bytes[42] << 8) | bytes[43];
   //var current_y_phase = (bytes[46] << 8) | bytes[47];
   //var current_b_phase = (bytes[46] << 8) | bytes[47];
   var frequency = (bytes[44] << 8) | bytes[45];
   var wh_received = (bytes[46] << 8) | bytes[47];
 return{
     Watts_Total: watts_total/100,
     Watts_R_phase: watts_r_phase/100,
     Watts_Y_phase: watts_y_phase/100,
     Watts_B_phase: watts_b_phase/100,
     VAR_Total: var_total/100,
     VAR_R_phase: var_r_phase/100,
     VAR_Y_phase: var_y_phase/100,
     VAR_B_phase: var_b_phase/100,
     PF_Ave: pf_average/100,
     PF_R_phase: pf_r_phase/100,
     //PF_Y_phase: pf_y_phase/100,
     //PF_B_phase: pf_b_phase/100,
     VA_Total: va_total/100,
     VA_R_phase: va_r_phase/100,
     VA_Y_phase: va_y_phase/100,
     VA_B_phase: va_b_phase/100,
     VLL_avg: vll_average/100,
     Vry_phase: vry_phase/100,
     Vyb_phase: vyb_phase/100,
     Vbr_phase: vbr_phase/100,
     VLN_avg: vln_average/100,
     V_R_phase: v_r_phase/100,
     //V_Y_phase: v_y_phase/100,
     //V_B_phase: v_b_phase/100,
     Current_Total: current_total/100,
     Current_R_phase: current_r_phase/100,
     //Current_Y_phase
     //Current_B_phase
     Freq: frequency/100,
     Wh_Received: wh_received/100
   };
 }

NodeRED Concept:

Here, in this blog further we introduced the NodeRED concept to read the required parameters from the energy meter using the ttn MQTT. The Things Network uses MQTT to publish device activations and messages, but also allows you to publish a message for a specific device in response. So, go through the below link to understand about how to read the values through subscribing to an application’s activations and messages.

https://www.thethingsnetwork.org/docs/applications/mqtt/quick-start.html

and now in this case we are reading the three para meters from subscribing to the mqtt using the nodeRED concept. The nodeRED flow is as shown below.

After completing the flow you have to make the modifications to the function node as shown below.

now press deploy button and we are successfully getting the 3 parameters readings on dashboard as follows.

Leave a Reply