Need help with posting data EMONCMS

Hi All,
Is there a way to integrate blynk with Emoncms?
currently I am using Pzem004t energy monitor with blynk app but i want the same data to be posted to
Thanks in advance

Try the Webhook widget and populate it as based on the input options of EMONCMS

Ok as i am not an expert, i will need your help to manage this, below is code iam using on ESP8266 with PZEM-004t

#define USE_BLYNK_WM      0       //

#include <ArduinoOTA.h>

#include <BlynkSimpleEsp8266_WM.h>
#include <BlynkSimpleEsp8266.h>

//#include <SimpleTimer.h>
#include <ModbusMaster.h>
#include <ESP8266WiFi.h>
#include "settingsPZEM.h"

#include <DHT.h>

#include <SoftwareSerial.h>  //  ( NODEMCU ESP8266 )
SoftwareSerial pzem(D5,D6);  // (RX,TX) connect to TX,RX of PZEM for NodeMCU
//SoftwareSerial pzem(D7,D8);  // (RX,TX) connect to TX,RX of PZEM
#include <ModbusMaster.h>
ModbusMaster node;

BlynkTimer timer;

//WiFi data
char ssid[]   = "****";           //WiFi Credential
char pass[]   = "****";           //WiFi Password
char server[] = "****";           //Blynk local server IP address
int port      = 8080;             //Blynk local port

char auth[]   = "****";           //PZEM-004v3 Auth code for Blynk Local Server

double U_PR, I_PR,  P_PR,  PPR, PR_F, PR_PF, PR_alarm;
uint8_t result;  uint16_t data[6];

#define UPDATE_INTERVAL_MS      5000

// Use 0 or 1 when you don't need to debug with many messages
#define DEBUG_LOOP              2

#define MODBUS_ID               1

#define DHTTYPE     DHT11     // DHT 11
//#define DHTTYPE     DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE     DHT21   // DHT 21, AM2301

#define DHTPIN        D2        // Using pin D2 for DHTxx


// Change according to your Blynk App design 
#define vPIN_VOLTAGE              V0
#define vPIN_CURRENT_USAGE        V1
#define vPIN_ACTIVE_POWER         V2
#define vPIN_ACTIVE_ENERGY        V3
#define vPIN_FREQUENCY            V4
#define vPIN_POWER_FACTOR         V5
#define vPIN_OVER_POWER_ALARM     V6

#define DHT_TEMP                  V7
#define DHT_HUMIDITY              V8 

float humidDHT;
float tempDHT;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void readSensor()
  float h  = dht.readHumidity();
  float t  = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
  if (isnan(h) || isnan(t)) 
    Serial.println("Failed to read from DHT sensor!");

  humidDHT  = h;
  tempDHT   = t;

void updateBlynk() 

  Blynk.virtualWrite(vPIN_VOLTAGE,               U_PR);
  Blynk.virtualWrite(vPIN_CURRENT_USAGE,         I_PR);
  Blynk.virtualWrite(vPIN_ACTIVE_POWER,          P_PR);
  Blynk.virtualWrite(vPIN_ACTIVE_ENERGY,         PPR);
  Blynk.virtualWrite(vPIN_FREQUENCY,             PR_F);
  Blynk.virtualWrite(vPIN_POWER_FACTOR,          PR_PF);
  Blynk.virtualWrite(vPIN_OVER_POWER_ALARM,      PR_alarm);

  Blynk.virtualWrite(DHT_TEMP, tempDHT);
  Blynk.virtualWrite(DHT_HUMIDITY, humidDHT);

uint8_t getPZEM()
  result = node.readInputRegisters(0x0000, 10);
  if (result == node.ku8MBSuccess)  
    U_PR      = (node.getResponseBuffer(0x00)/10.0f);
    I_PR      = (node.getResponseBuffer(0x01)/1000.000f);
    P_PR      = (node.getResponseBuffer(0x03)/10.0f);
    PPR       = (node.getResponseBuffer(0x05)/1000.0f);
    PR_F      = (node.getResponseBuffer(0x07)/10.0f);
    PR_PF     = (node.getResponseBuffer(0x08)/100.0f);
    PR_alarm  = (node.getResponseBuffer(0x09));

    #if (DEBUG_LOOP > 0)
    Serial.print("U_PR:     "); Serial.println(U_PR);   // V
    Serial.print("I_PR:     "); Serial.println(I_PR,3); //  A
    Serial.print("P_PR:     "); Serial.println(P_PR);   //  W 
    Serial.print("PPR:      "); Serial.println(PPR,3);  // kWh
    Serial.print("PR_F:     "); Serial.println(PR_F);   // Hz
    Serial.print("PR_PF:    "); Serial.println(PR_PF);  
    Serial.print("PR_alarm: "); Serial.println(PR_alarm,0);
  #if (DEBUG_LOOP > 0)
    Serial.println("PZEM: can't get data");
  return result;

void setup()
  Serial.println("\nStart serial"); 
  Serial.println("Start PZEM serial");
  node.begin(MODBUS_ID, pzem);  
  Serial.println("Start PZEM"); // 1 = ID MODBUS

  Serial.println("Started DHT");
    WiFi.begin(ssid, pass);
      Blynk.config(auth, server, BLYNK_HARDWARE_PORT);
    if ( Blynk.connected())
      Serial.println("Connected to Blynk");   
  timer.setInterval(UPDATE_INTERVAL_MS, updateBlynk);

void loop()

On my blynk side I have Webhook output as V10,
URL i put in blynk is

Method is post and blynk body is empty.
Please let me know what changes should I make to main sketch I given above so I can get all value in EMONCMS, Also let me know about other changes needs to be made.



any body please…

1 Like

It’s actually very difficult for other people to help, as they dont have your API key to try things for themselves, so they would have to create their own EmonCMS account and guess at your file schema.

This syntax bears absolutely no resemblance to anything on the EmonCMS API documentation pages.
As far as I can see, all API calls are https calls rather than http
update does not appear to be a valid keyword
api_key does not appear to be a valid keyword, but apikey does

As a general; rule, pasting your API URL into the browser address field is a good way to test a URL, but that method of testing is not going to work when you are passing parameters from Blynk into the webhook’s URL
In that situation you probably need to use tools like Postman.


Hi Pete,
After following the below EMONCMS input option and entered the url in my webhook widget, I managed to get inputs on EMONCMS site.

But the inputs in my EMONCMS are not updating with change in value of temperature etc as below:

The url i am pasting in my webhook is{"temp1":100,"voltage2":200,"power3":300}&apikey=a1045fc18d0ea128cd0f3307fa5a829c

I will thankful if further guided.


Your screenshot appears to show the values updated to 100, 200 and 300 as specified in your API URL.


These are the values i put in the URL manually, but aren’t they suppose to update as per actual data which is read by my ESP8266 from the PZEM-004 meter?

So now it’s time to re-read the the documentation for the Blynk webhook and incorporate pin values into your API call.


Ok, i have read that a few times and will give it another try but can you tell me if I have to make any changes to my sketch? it is mentioned in the start of the post.

You’ll need a way of triggering the webhook, which will presumably be done from your code.
As the documentation says:

Any write operation from hardware side will trigger Webhook Widget.

And add this code on hardware side:

Blynk.virtualWrite(V0, value);

where V0 is pin assigned to the Webhook widget.


Hi Pete,
Tried to add the code to my main sketch, but it seems i dont know the exact place where to put it, and hence the code is not compiling. Can you please tell me where to put it for all the values to get on EMONCMS, by all value I mean voltage, current power temperature humidity etc.


I’ve never used the webhook widget before, but I guess it would be something like this:

Blynk.virtualWrite(V10, tempDHT, U_PR, P_PR, );
added to the end of your updateBlynk function, with a Webhook weidegt on V10 with a URK something like:{“temp1”:/pin[0]/,“voltage2”:/pin[1]/,“power3”:/pin[3]/}&apikey=a1045fc18d0ea128cd0f3307fa5a829c


If I have guessed correctly and put it in the right spot, but strangely i am getting the below error,

Sorry, the comma after P_PR shouldn’t be there.


Thanks the sketch is composed successfully, I have posted URL in my webhook as{“temp1”:/pin[0]/,“voltage2”:/pin[1]/,“power3”:/pin[3]/}&apikey=a1045fc18d0ea128cd0f3307fa5a829c
output pin on my webhook is now V10, method is GET and body is empty but when i paste the URL in browser it reply the following message, also the variables not showing in EMONCMS input this time.

As I said earlier, pasting this into a web browser won’t work when you are using variables passed from Blynk.