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

added wait for transmission of pms commands #23

Closed
wants to merge 1 commit into from

Conversation

lukacsd
Copy link

@lukacsd lukacsd commented Oct 5, 2020

Happy that I've came across this library, nice work!
Although, really struggled to get the active/passive modes working on a ESP32-WROOM-32D, until I realised that we need to wait for the transmit buffer to be emptied. Hope this helps others with the same problem..

@fu-hsi
Copy link
Owner

fu-hsi commented Oct 5, 2020

Hi.
I wrote about this here:
#5
It's only my observations, I don't received any tickets about this.

flush() method blocks main program and it can do unexpected behavior in current applications which use PMS library and I don't wanna risk break them all.
This method we can place (if necessary) in our program after we sending command to PMS.

We don't have to wait for the sensor to receive commands because communication takes place asynchronously (character by character).
If we want to wait for a reply, we can use flush() (if needed?) after request and then readUntil().

More info about using flush() and what problems it can cause:
https://www.baldengineer.com/when-do-you-use-the-arduinos-to-use-serial-flush.html

Summarizing, we don't have to wait until PMS receive our commands.
PMS needs some time to initialize, warming up (fan) and other things and this is async.

Regards.

@lukacsd
Copy link
Author

lukacsd commented Oct 6, 2020

Hey,
Sorry, I haven't given proper explanation on the background of this pull request.

The sensor I was testing with is a fairly recent PMS7003, hooked up with an Espressif ESP32-WROOM-32D, via G7/G135 adapter.

I'll want it to operate in passive mode, so started testing with the "Advanced" example provided in this repository - basically uploaded the code without modifications at first. Although, I was able to get back readings, the sensor did not respond to passive protocol commands. Sending a sleep or wakeUp had no effect, and the fan was just keep spinning.

After a fair bit of trials, got a hunch that it might something to do with synchronization. Eventually, got it working by doing a while (_stream->available()) { _stream->read(); } after each command. Funnily enough, I found the same article you mentioned, only I was searching for a clean way of ensuring a serial transmission has completed :D

So, what I found in the end: the only way to operate the sensor in passive mode correctly, is to make sure the transmission buffer is empty after each command (passiveMode/wakeUp/requestRead/sleep).

I don't know enough to be able to tell the reason for this. Happy to do some debugging if you want more information (and give me some hints on what you need). Otherwise, I totally understand if this is a breaking change, and you decide to decline the pull.

Thanks for your time!

Cheers,
David

@lukacsd
Copy link
Author

lukacsd commented Oct 6, 2020

Hmm, I really have to get into the habit of looking around thoroughly .. just saw #6 which is exactly what I was seeing, and also includes the solution haha
Thanks again!

@lukacsd lukacsd closed this Oct 6, 2020
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.

2 participants