BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       👉 SKETCH BUILDER

Why can't I send information Powermeter (modbus) (use RS485) to Blynk?

I use the BlynkTimer timer; To send the information according to the code I have put but it only works BLYNK data of PowerMeter not send data and not connected to the power meter

My normal code can be used for the information Power meter.

#################################################

#include <SoftwareSerial.h> 
#define MAX485_DE      D6
#define MAX485_RE_NEG  D6

#define RO_RX D2
#define DI_TX D3

float voltage1,voltage2, current, power, energy, frequency, pf;


SoftwareSerial mySerial(RO_RX, DI_TX);
ModbusMaster node;
float C1,C2,C3;
float V1,V2,V3;
float KWh;
float KW;
float HZ;
float PF1,PF2,PF3;

int lock = 0;

void preTransmission()
{
  digitalWrite(MAX485_RE_NEG, 1);
  digitalWrite(MAX485_DE, 1);
}
void postTransmission()
{
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);
}

void setup()
{
  
  Serial.begin(19200);    
  mySerial.begin(19200); 
  
  
  pinMode(MAX485_RE_NEG, OUTPUT);
  pinMode(MAX485_DE, OUTPUT);
  
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);

 // Serial2.begin(9600, SERIAL_8N1, 16, 17);

  node.begin(1,mySerial);

  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);
  Serial.println("Test Cirduit Breaker Start");
}
void loop()
{  
    
    uint8_t result1,result2,result3,result4;
    uint16_t data1[0],data2[0],data3[0],data4[0];
    
    result1 = node.readInputRegisters(0000,2);
    if (result1 == node.ku8MBSuccess)
    {
      data1[0] = node.getResponseBuffer(1);
      voltage1 = data1[0]/100;
      Serial.print("v1 : ");      
      Serial.println(voltage1);       
    }  
    delay(1000); 
    
    
    result2 = node.readInputRegisters(0006,2);
    if (result2 == node.ku8MBSuccess)
    {
      data2[0] = node.getResponseBuffer(1);
      voltage2 = data2[0]/100;
      Serial.print("v2 : ");      
      Serial.println(voltage2); 
    }  
    delay(1000); 
}```
#################################################

***and this code The code I added BLYNK and I can't see the data Power meter.***

```#include <ModbusMaster.h>
#include <SoftwareSerial.h> 
#define MAX485_DE      D6
#define MAX485_RE_NEG  D6

#define RO_RX D2
#define DI_TX D3

// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "TMPLi-uUIJ26"
#define BLYNK_DEVICE_NAME "new"

#define BLYNK_FIRMWARE_VERSION        "0.1.0"

#define BLYNK_PRINT Serial


#define APP_DEBUG
float voltage1,voltage2, current, power, energy, frequency, pf;
uint8_t result1,result2,result3,result4;
uint16_t data1[0],data2[0],data3[0],data4[0];
int lock = 0;

SoftwareSerial mySerial(RO_RX, DI_TX);
ModbusMaster node;


// Uncomment your board, or configure a custom board in Settings.h
//#define USE_SPARKFUN_BLYNK_BOARD
#define USE_NODE_MCU_BOARD
//#define USE_WITTY_CLOUD_BOARD
//#define USE_WEMOS_D1_MINI

#include "BlynkEdgent.h"
BlynkTimer timer;


void preTransmission()
{
  digitalWrite(MAX485_RE_NEG, 1);
  digitalWrite(MAX485_DE, 1);
}
void postTransmission()
{
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);
}
void myTimerEvent1()
{
    float voltage1;
    result1 = node.readInputRegisters(0000,2);
    if (result1 == node.ku8MBSuccess)
    {
      data1[0] = node.getResponseBuffer(1);
      voltage1 = data1[0]/100;
      Serial.print("v1 : ");      
      Serial.println(voltage1);
      Blynk.virtualWrite(V1, voltage1);     
   }    
}

void myTimerEvent2()
{
    float voltage2;
    result2 = node.readInputRegisters(0006,2);
    if (result2 == node.ku8MBSuccess)
    {
      data2[0] = node.getResponseBuffer(1);
      voltage2 = data2[0]/100;
      Serial.print("v2 : ");      
      Serial.println(voltage2);
      Blynk.virtualWrite(V2, voltage2);     
   }    
}

void setup()
{
  Serial.begin(19200);  
  mySerial.begin(19200); 
  
  
  pinMode(MAX485_RE_NEG, OUTPUT);
  pinMode(MAX485_DE, OUTPUT);
  
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);

  node.begin(1,mySerial);

  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);
  Serial.println("Test Cirduit Breaker Start");
  timer.setInterval(2000L, myTimerEvent1);
  timer.setInterval(2000L, myTimerEvent2);
  BlynkEdgent.begin();
  
}

void loop() 
{
 BlynkEdgent.run();
 timer.run();
}```

@111173 Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Copy and paste these if you can’t find the correct symbol on your keyboard.

Pete.

I finished editing. can you help me with my problem.

The triple backticks need to be on a separate line. The way you’ve placed them at the moment your two pieces of code run into eachother.

You’ve rather butchered the Edgent example sketch, adding your own code in all the wrong places.
These two lines…

need to be the very first lines of your sketch, and I’d recommend adding your own #include and variable declarations and object declarations after the #include "BlynkEdgent.h" line of code.

You’ve also created a conflict with the Edgent sketch with this line of code…

Pin D3 (GPIO0) is used as the button pin to clear the stored credentials that you’ve provisioned via the app. Read this for more info…

Pete.