Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[issue #914] _P053_PMSx003 Dust Sensor looses sync #976

Merged
merged 3 commits into from
Mar 1, 2018

Conversation

TD-er
Copy link
Member

@TD-er TD-er commented Feb 28, 2018

  • Use peek instead of read, to make sure a complete packet is in the buffer.
  • Flush buffer after processing a packet.
  • Increased software serial buffer to the size of 3 packets.
  • Peek (+ read garbage) 10 times per second to get the buffer in sync to start with start byte of packet.
  • Decent delete + clean up of software serial allocation when changing settings (prevent memory leak)
  • Move log String allocation to inside scope of function, not permanent allocated.
  • Split into separate functions to make it better readable.

- Use peek instead of read, to make sure a complete packet is in the buffer.
- Flush buffer after processing a packet.
- Increased software serial buffer to the size of 3 packets.
- Peek (+ read garbage) 10 times per second to get the buffer in sync to start with start byte of packet.
- Decent delete + clean up of software serial allocation when changing settings (prevent memory leak)
- Move log String allocation to inside scope of function, not permanent allocated.
- Split into separate functions to make it better readable.
@uzi18
Copy link
Contributor

uzi18 commented Feb 28, 2018

It is better to check also if dummy (marker) is exactly 0x424D, if not we don't need to try calculate checksum.

Looks like problem was because always take 2 bytes from buffer and datagram has even bytes so it is impossible to find sync if miss one byte.

@TD-er
Copy link
Member Author

TD-er commented Feb 28, 2018

That's a good suggestion. (it was past 2am)
Will try that later today.

Quickly commit + merge is never a good idea when some visitors arrive...
Fixed now.
@micropet
Copy link

micropet commented Mar 1, 2018

OK, test begins.

@TD-er
Copy link
Member Author

TD-er commented Mar 1, 2018

@micropet OK to merge it?

@micropet
Copy link

micropet commented Mar 1, 2018

Unfortunately, no. There were about 60 minutes of data delivered.
Now nothing is coming out.

@TD-er
Copy link
Member Author

TD-er commented Mar 1, 2018

But it is not worse than before?
When I merge it, then others can also test. Just to get an idea what's going on. (don't have one of those sensors myself, for the next few weeks)

@micropet
Copy link

micropet commented Mar 1, 2018

Yes you are right. This version also runs longer than the old version.

@TD-er TD-er merged commit 5d9137d into letscontrolit:v2.0 Mar 1, 2018
@TD-er TD-er deleted the bugfix/P053_PMSx003DustPlugin branch March 1, 2018 22:07
@micropet
Copy link

micropet commented Mar 1, 2018

serialReadPMValue.zip

I've been running this version on an ESP32 and STMF4 board for many months now.

She has never failed. Maybe it gives you an idea.

#include "serialReadPMValue.h"
uint16_t p01 = 0; //define PM1.0 value of the air detector module
uint16_t p25 = 0; //define PM2.5
uint16_t p10 = 0; //define PM10
#define receiveDatIndex 32
uint8_t receiveDat[receiveDatIndex];

int length = serialRead(Serial1,receiveDat,receiveDatIndex,5); //change the serial port:Serial1,Serial2..
int checkSum=checkValue(receiveDat,receiveDatIndex);

if(length&&checkSum)
{
p01=transmitPM01(receiveDat); // count PM1.0 value of the air detector module
p25=transmitPM2_5(receiveDat); // count PM2.5 value of the air detector module
p10=transmitPM10(receiveDat); // count PM10 value of the air detector module
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants