jantenhove / P1-Meter-ESP8266

Software for the ESP8266 that sends P1 smart meter data to Domoticz (with CRC checking)
GNU General Public License v3.0
79 stars 38 forks source link

New srm5.0 meter sends out telegrams without delay. #15

Open macron0 opened 3 years ago

macron0 commented 3 years ago

Hi,

I have been trying this project with and esp01 and my slimemeter iskra smr 5.0 am550-ED1 Where every one says the p1 spits out a telegram every 10 seconds my seems to spit it out non stop. This seems to make my esp01 crash in about 10 minutes (overheating?) and I have trouble reading the results. I tried adding an opto coupler and driving it by pulling gpio0 low to set RTS high via 3.3v -> 220K -> pc817 -> gpio0 This sort or works. When RTS is high P1 starts spitting out stuff but it looks incomplete? But I don't know when to set high and low? Is a telegram online one line? Or if a telegram one set of lines? Should I put RTS Low directly after seting it high or wait for the readtelegram loop to finish? But I had situation it just kept running for a minute and then go low. and sometimes I missed the fasctI set it high.

Here is my version of readTelegram:

`void readTelegram() {
  // DTR is gpio0 and should be pulled low to set RTS high. 
  unsigned long now=millis();  
  if ((unsigned long)(now - lasttelegram) >= 5000) {lasttelegram=now;} else {return;} // only run once every 5 seconds.     
  TIMES1++;  // count the times set RTS was set high.
  digitalWrite(DTR,LOW); // Trigger a telegram (RTS)
  delay(20); // Do we even need a delay?
  if (mySerial.available()) {
    memset(telegram, 0, sizeof(telegram));
    while (mySerial.available()) {
      // digitalWrite(DTR,HIGH); //Should I set RTS Off again> 
      int len = mySerial.readBytesUntil('\n', telegram, MAXLINELENGTH);
      telegram[len] = '\n';
      telegram[len+1] = 0;
      yield();
      if(decodeTelegram(len+1))
      {
         UpdateElectricity();
         //UpdateGas(); // I have no gas. 
      }
    }     
  }
  TIMES2++; // Count the number of times RTS was set LOW. 
  digitalWrite(DTR,HIGH);
}`

At the start of decodeTelegram I log the received data via a post request to my local webserver. I cannot get Serial and Software Serial to work together so I have no other way to log. Maybe this takes to much time and makes the readTelegram to miss data?

bool decodeTelegram(int len) {
  koffiepost(telegram);
  etc...

void koffiepost(char* message)
  {
  String postData="LOW "+String(TIMES1)+"HIGH "+String(TIMES2)+"log="+String(message);
  String address = "http://192.168.0.1/dmation/esplog.html"; 
  HTTPClient http; 
  http.begin(address); 
  http.addHeader("Content-Type", "application/x-www-form-urlencoded"); 
  auto httpCode = http.POST(postData); 
  String payload = http.getString(); 
  http.end();    
  }

Some of the output I got. (it seems to only do 3 ort 4 lines and than restarts)

1-3:0.2.8(50) 0-0:1.0.0(200814002323S) 0-/ISK5\2M550E-1013

1-3:0.2.8(50) 0-0:1.0.0(200814002328S) 0-0:96.1.1(4530303533æ /ISK5\2M550E-1013

1-3:0.2.8(50) 0-0:1.0.0(200814002333S) 0-/ISK5\2M550E-1013

1-3:0.2.8(50) 0-0:1.0.0(200814002338S) 0-0:96.1.1(4530303533þ

Any suggestion in what I could try to get my iskra smr 5.0 am550-ED1 to work with the esp01 and domoticz?

macron0 commented 3 years ago

To whom it might concern.

I added a serial inverter using an 2n222a transistor. 2 times 2.2k and one 1k resistor like the level shifter/inverter from this picture: https://willem.aandewiel.nl/wp-content/uploads/2018/08/Schema_V20.png (I did not have the bc547) and i removed the softwareSerial code/lib. The softwareSerial should have replaced the inverter circuit which would have been super cool but apparently 115200 baud is way to fast for it? Anyway I get data now. Now I need to change the parser to match the iskra smr 5.0 am550-ED1 output.

One more thing. I thought that the iskra was sending data non stop but it turns out it is sending data every second instead of every 10 seconds in the older versions. If I set RST high and keep it HIGH I see short data bursts on my (very simpel) DSO150 every second. Since serial is only listening it seems it just pushes all date in one burt (telegram?)

I am sure we can still read P1 slimmemeter with an ESP01.

Since I only have ld phone j11 plugs which have r pins wired instead of 6 I am using an external usb charger topower the esp. I added a buck/boost x to 3.3 converter. But once aliexpress delivers my j11 6p plugs I will to to power from the p1 port.

Sample of my log:

LOW 43HIGH 43log=status=alive LOW 44HIGH 43log=2.7.0(00.000kW)M LOW 44HIGH 43log=0-0:96.7.21(00007)M LOW 44HIGH 43log=0-0:96.7.9(00003)M LOW 44HIGH 43log=1-0:99.97.0(1)(0-0:96.7.19)(191204090823W)(0000000234s)M LOW 44HIGH 43log=1-0:32.32.0(00004)M LOW 44HIGH 43log=1-0:32.36.0(00001)M LOW 44HIGH 43log=0-0:96.13.0()M LOW 44HIGH 43log=1-0:32.7.0(232.2V)M LOW 44HIGH 43log=1-0:31.7.0(001A)M LOW 44HIGH 43log=1-0:21.7.0(00.328kW)M LOW 44HIGH 43log=1-0:22.7.0(00.000kW)M LOW 44HIGH 43log=!8715M LOW 44HIGH 44log=status=alive

Ps,

As far as I could find out the esp8266 IS 5 volt tollerant on most IO ports. So level shifting should not be needed.

martijnvwezel commented 1 year ago

You are correct I experience the same issue, because there is no delay a the softserial is having difficulties, with sscanf I get some descend results, but it misses some the gas part.

mspoorendonk commented 1 year ago

I noticed the same. Softserial has a hard time keeping up with 100k baud. This caused the hardware watchdog timer to reset my wemos D1 mini. I switched to using hardware serial and then everything worked flawlessly.

This is the line I constructed for setting up the inverted serial port. (Such that I don't need an external hardware invertor in the serial line) Serial.begin(115200, SERIAL_8N1, SERIAL_RX_ONLY, -1, true); // This connects to the RX pin on the wemos D1 mini. We cannot choose a different one.