CRC issue when reading multiple meters
jayvdw13 opened this issue · 3 comments
whenever i connect multiple meters i get a timeout or a CRC error and a timeout error.
here is my code
`#include <Arduino.h>
#include <SDM.h>
float voltage1L1;
float voltage1L2;
float voltage1L3;
float current1L1;
float current1L2;
float current1L3;
float power1L1;
float power1L2;
float power1L3;
float kwh1L1;
float kwh1L2;
float kwh1L3;
float kwh1;
float voltage2L1;
float voltage2L2;
float voltage2L3;
float current2L1;
float current2L2;
float current2L3;
float power2L1;
float power2L2;
float power2L3;
float kwh2L1;
float kwh2L2;
float kwh2L3;
float kwh2;
float voltage3L1;
float voltage3L2;
float voltage3L3;
float current3L1;
float current3L2;
float current3L3;
float power3L1;
float power3L2;
float power3L3;
float kwh3L1;
float kwh3L2;
float kwh3L3;
float kwh3;
#if defined ( USE_HARDWARESERIAL ) //for HWSERIAL
#if defined ( ESP8266 ) //for ESP8266
SDM sdm(Serial1, 2400, 22, SERIAL_8N1); //config SDM
#elif defined ( ESP32 ) //for ESP32
SDM sdm(Serial1, 2400, 22, SERIAL_8N1, SDM_RX_PIN, SDM_TX_PIN); //config SDM
#else //for AVR
SDM sdm(Serial1, 2400, 22); //config SDM on Serial1 (if available!)
#endif
#else //for SWSERIAL
#include <SoftwareSerial.h> //import SoftwareSerial library
#if defined ( ESP8266 ) || defined ( ESP32 ) //for ESP
SoftwareSerial swSerSDM; //config SoftwareSerial
SDM sdm(swSerSDM, 2400, 22, SWSERIAL_8N1, SDM_RX_PIN, SDM_TX_PIN); //config SDM
#else //for AVR
SoftwareSerial swSerSDM(SDM_RX_PIN, SDM_TX_PIN); //config SoftwareSerial
SDM sdm(swSerSDM, 2400, 22); //config SDM
#endif
#endif
//!
//!
void setup(){ //!
Serial.begin(115200);
SPIFFS.begin(true);
sdm.begin();
}
//--------------------------------------------------------------------
void loop()
{
char bufout[10];
sprintf(bufout, "%c[1;0H", 27);
Serial.print(bufout);
//meter1
float voltage1l1 = sdm.readVal(SDM_PHASE_1_VOLTAGE, 0x01);
Serial.print("Last ERROR: ");
Serial.println(sdm.getErrCode(true));
delay(100);
float voltage1l2 = sdm.readVal(SDM_PHASE_2_VOLTAGE, 0x01);
Serial.print("Last ERROR: ");
Serial.println(sdm.getErrCode(true));
delay(100);
float voltage1l3 = sdm.readVal(SDM_PHASE_3_VOLTAGE, 0x01);
delay(100);
voltage1L1 = voltage1l1;
voltage1L2 = voltage1l2;
voltage1L3 = voltage1l3;
Serial.println(voltage1L1);
Serial.println(voltage1L2);
Serial.println(voltage1L3);
float current1l1 = sdm.readVal(SDM_PHASE_1_CURRENT, 0x01);
Serial.print("Last ERROR: ");
Serial.println(sdm.getErrCode(true));
delay(100);
float current1l2 = sdm.readVal(SDM_PHASE_2_CURRENT, 0x01);
Serial.print("Last ERROR: ");
Serial.println(sdm.getErrCode(true));
delay(100);
float current1l3 = sdm.readVal(SDM_PHASE_3_CURRENT, 0x01);
delay(100);
current1L1 = current1l1;
current1L2 = current1l2;
current1L3 = current1l3;
Serial.println(current1L1);
Serial.println(current1L2);
Serial.println(current1L3);
float power1l1 = sdm.readVal(SDM_PHASE_1_POWER, 0x01);
Serial.print("Last ERROR: ");
Serial.println(sdm.getErrCode(true));
delay(100);
float power1l2 = sdm.readVal(SDM_PHASE_2_POWER, 0x01);
Serial.print("Last ERROR: ");
Serial.println(sdm.getErrCode(true));
delay(100);
float power1l3 = sdm.readVal(SDM_PHASE_3_POWER, 0x01);
delay(100);
power1L1 = power1l1;
power1L2 = power1l2;
power1L3 = power1l3;
Serial.println(power1L1);
Serial.println(power1L2);
Serial.println(power1L3);
float kwh01 = sdm.readVal(SDM_TOTAL_ACTIVE_ENERGY, 0x01);
delay(100);
float kwh1l1 = sdm.readVal(SDM_L1_IMPORT_ACTIVE_ENERGY, 0x01);
delay(100);
float kwh1l2 = sdm.readVal(SDM_L2_IMPORT_ACTIVE_ENERGY, 0x01);
delay(100);
float kwh1l3 = sdm.readVal(SDM_L3_IMPORT_ACTIVE_ENERGY, 0x01);
delay(100);
kwh1 = kwh01;
kwh1L1 = kwh1l1;
kwh1L2 = kwh1l2;
kwh1L3 = kwh1l3;
Serial.println(kwh1);
Serial.println(kwh1l1);
Serial.println(kwh1l2);
Serial.println(kwh1l3);
//meter2
float voltage2l1 = sdm.readVal(SDM_PHASE_1_VOLTAGE, 0x02);
delay(100);
float voltage2l2 = sdm.readVal(SDM_PHASE_2_VOLTAGE, 0x02);
delay(100);
float voltage2l3 = sdm.readVal(SDM_PHASE_3_VOLTAGE, 0x02);
delay(100);
voltage1L1 = voltage2l1;
voltage1L2 = voltage2l2;
voltage1L3 = voltage2l3;
Serial.println(voltage2L1);
float current2l1 = sdm.readVal(SDM_PHASE_1_CURRENT, 0x02);
delay(100);
float current2l2 = sdm.readVal(SDM_PHASE_2_CURRENT, 0x02);
delay(100);
float current2l3 = sdm.readVal(SDM_PHASE_3_CURRENT, 0x02);
delay(100);
current2L1 = current2l1;
current2L2 = current2l2;
current2L3 = current2l3;
Serial.println(current2L1);
float power2l1 = sdm.readVal(SDM_PHASE_1_POWER, 0x02);
delay(100);
float power2l2 = sdm.readVal(SDM_PHASE_2_POWER, 0x02);
delay(100);
float power2l3 = sdm.readVal(SDM_PHASE_3_POWER, 0x02);
delay(100);
power2L1 = power2l1;
power2L2 = power2l2;
power2L3 = power2l3;
Serial.println(power2L1);
float kwh02 = sdm.readVal(SDM_TOTAL_ACTIVE_ENERGY, 0x02);
delay(100);
float kwh2l1 = sdm.readVal(SDM_L1_IMPORT_ACTIVE_ENERGY, 0x02);
delay(100);
float kwh2l2 = sdm.readVal(SDM_L2_IMPORT_ACTIVE_ENERGY, 0x02);
delay(100);
float kwh2l3 = sdm.readVal(SDM_L3_IMPORT_ACTIVE_ENERGY, 0x02);
delay(100);
kwh2 = kwh02;
kwh2L1 = kwh2l1;
kwh2L2 = kwh2l2;
kwh2L3 = kwh2l3;
Serial.println(kwh2L1);
//meter3
float voltage3l1 = sdm.readVal(SDM_PHASE_1_VOLTAGE, 0x03);
float voltage3l2 = sdm.readVal(SDM_PHASE_2_VOLTAGE, 0x03);
float voltage3l3 = sdm.readVal(SDM_PHASE_3_VOLTAGE, 0x03);
voltage3L1 = voltage3l1;
voltage3L2 = voltage3l2;
voltage3L3 = voltage3l3;
Serial.println(voltage3L1);
float current3l1 = sdm.readVal(SDM_PHASE_1_CURRENT, 0x03);
float current3l2 = sdm.readVal(SDM_PHASE_2_CURRENT, 0x03);
float current3l3 = sdm.readVal(SDM_PHASE_3_CURRENT, 0x03);
current3L1 = current3l1;
current3L2 = current3l2;
current3L3 = current3l3;
Serial.println(current3L1);
float power3l1 = sdm.readVal(SDM_PHASE_1_POWER, 0x03);
float power3l2 = sdm.readVal(SDM_PHASE_2_POWER, 0x03);
float power3l3 = sdm.readVal(SDM_PHASE_3_POWER, 0x03);
power3L1 = power3l1;
power3L2 = power3l2;
power3L3 = power3l3;
Serial.println(power3L1);
float kwh03 = sdm.readVal(SDM_TOTAL_ACTIVE_ENERGY, 0x03);
float kwh3l1 = sdm.readVal(SDM_L1_IMPORT_ACTIVE_ENERGY, 0x03);
float kwh3l2 = sdm.readVal(SDM_L2_IMPORT_ACTIVE_ENERGY, 0x03);
float kwh3l3 = sdm.readVal(SDM_L3_IMPORT_ACTIVE_ENERGY, 0x03);
kwh3 = kwh03;
kwh3L1 = kwh3l1;
kwh3L2 = kwh3l2;
kwh3L3 = kwh3l3;
Serial.println(kwh3L1);
}`
`
//define user baudrate
#define SDM_UART_BAUD 2400
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#define USE_HARDWARESERIAL
//------------------------------------------------------------------------------
#if defined ( ESP8266 ) || defined ( ESP32 )
#define SDM_RX_PIN 13
#define SDM_TX_PIN 15
#endif
//------------------------------------------------------------------------------
#define DERE_PIN 22
//------------------------------------------------------------------------------
#define SDM_UART_CONFIG SERIAL_8N1
//#define SDM_UART_CONFIG SWSERIAL_8N1
//------------------------------------------------------------------------------
#define WAITING_TURNAROUND_DELAY 800
//------------------------------------------------------------------------------
#define RESPONSE_TIMEOUT 600
//------------------------------------------------------------------------------
`
no changes where made to SDM.h or SDM.cpp
01 04 00 0E 00 02 10 08
01 04 00 7F F8 84
here is an example of a request and answer from the meter
03 04 00 0C 00 02 B0 2A
03 04 04 41 1C 96 E9 A3 90
another example
01 04 00 04 00 02 30 0A
01 04 04 00 00 00 00 FB 84
i noticed i had two meters with the same id this is a request and answer after i fixed it