-->
Page 1 of 1

Running to the software serial limit ?

PostPosted: Sun Jan 26, 2020 6:05 pm
by bdepauw
Hello All,

Im using an LoLIn ESP8266 nodemcu to read out my digital (electricity and gas) meter via
#define SERIAL_RX D7 // pin for SoftwareSerial RX
SoftwareSerial mySerial(SERIAL_RX, -1, true, MAXLINELENGTH); // (RX, TX. inverted, buffer)

But most of the readings ( 1 per second and software serial speed is 115200 ) always contain one or some mis readings. I only have 1 correct reading in about 10 to 30 readings ( luckly there is a CRC)

See example below :
0-1:24.1.0(0p3)
should have been
0-1:24.1.0(003)
( in human language : current consumptions is 003 amperes )

One compleet reading looks like this (I removed or modified some lines as these are id's ) :

1-0:1.8.1(000155.825*kWh)
1-0:1.8.2(000115.526*kWh)
1-0:2.8.1(000029.778*kWh)
1-0:2.8.2(000013.810*kWh)
0-0:96.14.0(0001)
1-0:1.7.0(00.562*kW)
1-0:2.7.0(00.000*kW)
1-0:32.7.0(228.0*V)
1-0:31.7.0(002*A)
0-0:96.3.10(1)
0-0:17.0.0(999.9*kW)
1-0:31.4.0(999*A)
0-0:96.13.0()
0-1:24.1.0(0p3)
0-1:96.1.1(123456789)
0-1:24.4.0(1)
0-1:24.2.3(123456789)(00161.732*m3)
!4249
===INVALID CRC FOUND!===

I know software serial isn't ideal for such high speeds, but as far as I untherstood I don't have an alternative here as the uart is used/connected by/to the USB chip ( and swapping to the uart data control lines didn't work for me)

Do you thing I'm running here to the limit of the software serial capacity ?
Or should there still be somewhere a solutions ?
Seems to me that timing isn't just correct or a bit off ?

PS : my sketch is a deriviate from
https://github.com/jantenhove/P1-Meter-ESP8266/blob/master/P1Meter.ino
( Thanks Jan ! Bedankt Jan Ten Hove voor dit mooi stukje programeerwerk !)

Already thanks for all reactions and replys !

Re: Running to the software serial limit ?

PostPosted: Thu Feb 13, 2020 10:49 pm
by StanJ
You're probably experiencing a difference in baud rate between the two devices. Serial must have the two data rates within ~5% of each other or it can't sync reliably.

I haven't investigated the serial port yet, but try knobbing the baud rate up or down in 1% increments until you see stable data. If it's worse a bit higher, then start heading lower. You should find a range that they'll reliably talk at, so set the baud rate to the middle of that range. That's the best you can do without an oscilloscope (preferred) or decent logic analyzer to see what's going on there.

The problem could be either the power meter -or- the cheap crystal on the ESP8266 module. You can't change the power meter, so start with the bits you CAN change. It's been a SERIOUSLY long time since I've seen two serial devices that wouldn't communicate, but then again all of my designs used crystals from prime manufacturers with *real* specs, not from some unknown garage-operation in Shenzen.

Additionally, at 115K you'll have to keep the wire length below two meters, I'd have to guess. Don't even think about trying to push 115K down 10 meters of wire: it won't get there. If your wire is wonky or high capacitance, that'll mess up the data as well.

Re: Running to the software serial limit ?

PostPosted: Fri Oct 07, 2022 9:50 am
by Wim7
Hi, I hadn't read this thread yet but I found it when I also had problems reading P1 data with the ESP8266 SoftwareSerial. Even with minimum coding, I could only receive a few lines; missing some 34 lines.
Code: Select all
#include <SoftwareSerial.h>
#define MYPORT_RX (14)
#define MYPORT_TX (false)
#define BAUD_RATE 115200

SoftwareSerial P1serial;

void setup() {
  Serial.begin(115200);
  delay(1000);
  P1serial.begin(BAUD_RATE, SWSERIAL_8N1, MYPORT_RX, MYPORT_TX, true);  // last var is invert
  if (!P1serial) {
    Serial.println("Invalid SoftwareSerial pin configuration, check config");
    while (1) {
      delay(1000);
    }
  }
  Serial.println("P1serial initialized.");
  Serial.println("System configured. Start loop");   
}

void loop()
{
  while (P1serial.available() > 0) {
    Serial.write(P1serial.read());
    yield();
  }
  while (Serial.available() > 0) {
    P1serial.write(Serial.read());
    yield();
  }
}


the data I received was only
Code: Select all/Ene5\T210-D ESMR5.0

1-3:0.2.8(50)
0-0:1.0.0(221007155346S)
0/Ene5\T210-D ESMR5.0

1-3:0.2.8(50)
0-0:1.0.0(221007155347S)
/Ene5\T210-D ESMR5.0

1-3:0.2.8(50)
0-0:1.0.0(221007155348S)


I read 115200 was possible but is it?
Did you solve this problem? Hope you're stil active since feb 2020...