MarkJB / python-pms7003

Python script to test a Plantower PMS7003 serial laser particulate sensor
MIT License
8 stars 10 forks source link

Error while execution #1

Closed ronakdedhia18 closed 5 years ago

ronakdedhia18 commented 5 years ago

Hi, When i print data it gives data= b'\x00\x1c\x00,\x00I\x00M\x00\x1f\x002\x00> \x1c\t:\x01\xca\x00&\x00\x06\x00\x02\x97\x00\x04\x0b'

frameLength = ord(data[1]) + (ord(data[0])<<8)

the above line gives this error TypeError: ord() expected a character, but string of length 2 found

MarkJB commented 5 years ago

That looks like the data from the serial port is not as expected. It should be 30 bytes long by the time you have something in 'data'.

Are you using the same device (PMS7003) or has the data format output by the device changed?

Also, is the '>' character in the data string correct? I wouldn't expect to see that.

ronakdedhia18 commented 5 years ago

Hi Mark, I am using PMS7003 and have integrated it with Raspberry Pi and getting more than 30 bytes as initial input so the error. Please let me know. Thank you.

Regards, Ronak Dedhia

On Sat 29 Dec, 2018, 9:36 PM Mark Benson <notifications@github.com wrote:

That looks like the data from the serial port is not as expected. It should be 30 bytes long by the time you have something in 'data'.

Are you using the same device (PMS7003) or has the data format output by the device changed?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/MarkJB/python-pms7003/issues/1#issuecomment-450502695, or mute the thread https://github.com/notifications/unsubscribe-auth/ANldUc2w3nloF0V5b9tz_w9C_fSmBMeEks5u95MCgaJpZM4ZkfIc .

MarkJB commented 5 years ago

What version of Python are you running?

And can you post the full error/stack trace.

ronakdedhia18 commented 5 years ago

Hi Mark, Sorry I am travelling so can't post he stack.Using python version 3.6 I'll post the stack tomorrow as soon as I can. Thank you. Regards, Ronak Dedhia

On Sun 30 Dec, 2018, 6:35 PM Mark Benson <notifications@github.com wrote:

What version of Python are you running?

And can you post the full error/stack trace.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/MarkJB/python-pms7003/issues/1#issuecomment-450559477, or mute the thread https://github.com/notifications/unsubscribe-auth/ANldUc3GINSiiBhihSZ8CnZ5XYSHgf2Cks5u-LoCgaJpZM4ZkfIc .

ronakdedhia18 commented 5 years ago

Hi Mark, This is the stack i am posting here. cv) pi@raspberrypi:~/live $ python New_PMS_code.py b'\x00\x1c\x00o\x00\xac\x00\xb4\x00I\x00r\x00wI\xef\x15\xb1\x04\x06\x00L\x00\x0e\x00\x04\x97\x00\x06\xa9' Traceback (most recent call last): File "New_PMS_code.py", line 20, in frameLength = ord(data[1]) + (ord(data[0])<<8) TypeError: ord() expected string of length 1, but int found

If i just print data[1] i am getting value as 28 and data[0] as 0.

Please let me know what can be the issue.

Thank you.

MarkJB commented 5 years ago

Is this my script or have you modified it? (line 20 is in the docstring in my code).

If so, does my script run unmodified?

ronakdedhia18 commented 5 years ago

No i havent changed anything fromm your code and can you please update the code if you have changed it?

MarkJB commented 5 years ago

I haven't changed it.

ronakdedhia18 commented 5 years ago

Hi Mark, Then can you please check with the readings i am getting. Please let me know.

Thank you.

MarkJB commented 5 years ago

Looks like this is due to a difference between Python 2 & 3. Indexing a byte string returns integers in 3 and bytes in 2. So if you are using Python 3, remove the ord().

I've tried this with Python 3 and it appears to work, but I'd need to check the byte addition is still correct before committing a fix.

ronakdedhia18 commented 5 years ago

Hi Mark, I already removed ord and then posted the image of output i am getting. Can you please commit a fix and help me ? Thank you.

MarkJB commented 5 years ago

I've pushed the changes with the removed ord() and that is working for me. PM2.5 & PM10 values reading ~20ug/m3.

Let me know if that works for you...

ronakdedhia18 commented 5 years ago

Hi Mark, I am getting below output. How to verify if its correct. And say if i want to test it in an closed environment with a burning wood which values should i consider? Atmospheric or normal PM1.0 values. Please let me know. And a big Thank you for all your co-ordination,quick replies and support.

PMS7003 Sensor Data: PM1.0 = 104 ug/m3 PM2.5 = 163 ug/m3 PM10 = 176 ug/m3 PM1 Atmospheric concentration = 69 ug/m3 PM2.5 Atmospheric concentration = 108 ug/m3 PM10 Atmospheric concentration = 117 ug/m3 Count: 0.3um = 18084 per 0.1l Count: 0.5um = 5227 per 0.1l Count: 1.0um = 1020 per 0.1l Count: 2.5um = 90 per 0.1l Count: 5.0um = 20 per 0.1l Count: 10um = 6 per 0.1l Version = 151 Error Code = 0 Frame length = 28

MarkJB commented 5 years ago

To verify those values are correct you'd need a calibrated air quality meter. I don't know which values you should be looking at for burning wood.

From looking at the data from my pms7003, the standard and atmospheric values are more or less the same and I don't really understand the difference so I go by the atmospheric values.