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

Problems with the _P053_PMSx003 Dust Plugin #914

Closed
micropet opened this issue Feb 21, 2018 · 79 comments
Closed

Problems with the _P053_PMSx003 Dust Plugin #914

micropet opened this issue Feb 21, 2018 · 79 comments
Assignees
Labels
Category: Plugin Related to supported sensors Category: Stabiliy Things that work, but not as long as desired Status: In Progress Is being worked on by the development team Type: Bug Considered a bug
Milestone

Comments

@micropet
Copy link

Hello everybody,
I have some devices with the dust sensor PMS7003 and some with the SDS021.

The devices with the SDS021 run smoothly for weeks.
Those with the PMS7003 only make a few measurements and then hang. The dust levels are no longer updated.

After a reset or disconnection of the voltage, the values are updated only a couple of times, then nothing comes up.

The rest of the measurements, such as BME280 BH1750, continue.

device_4
device_page_1

@TD-er
Copy link
Member

TD-er commented Feb 21, 2018 via email

@micropet
Copy link
Author

The device with the SDS also has a MH-Z19 CO2 sensor.

I think the PMS sends the data by itself.

The connections I would not like to change.

device_4
device_page_1

@TD-er
Copy link
Member

TD-er commented Feb 21, 2018

Have you also tried another power supply and other cable to power the node?
These sensors may peak in current use and it may be just enough to let the voltage drop too much when both the CO2 and the dust sensor peak at the same time.
A lot of USB cables often have quite some resistance, which will result in voltage drop at higher currents.

@micropet
Copy link
Author

micropet commented Feb 21, 2018

Yes, I know that with the cables. There are a lot of high-impedance cables on the market.
I had the power supply and the cable changed this morning.

I have set paralell to the 5V a 2800μF capacitor. This has been enough for all devices so far.

The PMS has then sent his values twice and is frozen again.

But it must be due to the software, with Tasmota it runs perfectly.

@TD-er
Copy link
Member

TD-er commented Feb 25, 2018

I've looked into the source and it looks very likely to give exactly the issues you mention.
I will fix it, although I have not (yet) such a sensor to test myself.

The problem with this implementation is that the reader (ESPboard) can get out of sync with the writer (sensor) and can't get into sync anymore (not within a few hours, perhaps never)
Apart from that, the implementation is made overly complicated to support the hardware serial, which is a great idea, but at the wrong place.

@TD-er TD-er self-assigned this Feb 25, 2018
@TD-er TD-er added Type: Bug Considered a bug Category: Plugin Related to supported sensors labels Feb 25, 2018
@TD-er TD-er added this to the 2.0.0 milestone Feb 25, 2018
@micropet
Copy link
Author

micropet commented Feb 25, 2018

The PMS is already connected via software serial.

What does your answer mean? Cant we do anything?
Then you should remove the plugin.

I will buy a SDS021 that works in other devices.
And for the PMS I will use Tasmota.

@TD-er
Copy link
Member

TD-er commented Feb 25, 2018

What I meant is, I will try to fix it in ESPeasy.
All plugins in the releases should work and if not, we should make them work.
Simple as that.
So thanks for your report, I will have a look at it.

@micropet
Copy link
Author

That is a word!

@uzi18
Copy link
Contributor

uzi18 commented Feb 25, 2018

@TD-er I have got PMS sensor, maybe can help here
Where do You think problem is?

@TD-er
Copy link
Member

TD-er commented Feb 25, 2018

@uzi18
You will get a version to test later this week.

Do you also experience similar issues?

@uzi18
Copy link
Contributor

uzi18 commented Feb 25, 2018

My sensor were never used before but this is a time ;)

@uzi18
Copy link
Contributor

uzi18 commented Feb 25, 2018

It is PMS3003

TD-er added a commit to TD-er/ESPEasy that referenced this issue 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.
@TD-er
Copy link
Member

TD-er commented Feb 28, 2018

See Pull Request #976
@micropet and/or @uzi18 Can you test it to see if it is now more stable.
I don't have such a sensor yet, so I cannot test it.

@TD-er TD-er added the Status: Fixed Commit has been made, ready for testing label Feb 28, 2018
@micropet
Copy link
Author

micropet commented Feb 28, 2018

Good morning Gijs,
you are awake early!

The plugin has already failed after two measurements.
Now it has been running for 15 minutes with some Errors in the Logfile.

504669: PMSx003: invalid framelength - 142
506220: MHZ19: Raw PPM: 905 Filtered PPM value: 1043 Temp / S / U values: 23/0 / 0.00
506224: EVENT: MH-Z19 # PPM = 1093.00
506366: ACT: NeoPixelAll, 50,70,0,0
506492: EVENT: MH-Z19 # MHZ19Temp = 22.20
506721: EVENT: MH-Z19 # U = 0.00
515541: WD: Uptime 9 ConnectFailures 0 FreeMem 13104
528697: EVENT: PMS7003 # pm1.0 = 5.00
528971: EVENT: PMS7003 # pm2.5 = 8.00
529217: EVENT: PMS7003 # pm10 = 14.00
....
564627: PMSx003: invalid framelength - 32772
567203: MHZ19: Raw PPM: 917 Filtered PPM value: 1053 Temp / S / U values: 23/0 / 0.00
567207: EVENT: MH-Z19 # PPM = 1103.00
567348: ACT: NeoPixelAll, 50,70,0,0
567444: EVENT: MH-Z19 # MHZ19Temp = 22.20
567672: EVENT: MH-Z19 # U = 0.00
575544: WD: Uptime 10 ConnectFailures 0 FreeMem 13088
589198: EVENT: PMS7003 # pm1.0 = 3.00
589444: EVENT: PMS7003 # pm2.5 = 7.00
589717: EVENT: PMS7003 # pm10 = 8.00
597648: MHZ19: Raw PPM: 920 Filtered PPM value: 1058 Temp / S / U values: 23/0 / 0.00
597652: EVENT: MH-Z19 # PPM = 1108.00
......
742633: EVENT: PMS7003 # pm1.0 = 3.00
742881: EVENT: PMS7003 # pm2.5 = 8.00
743125: EVENT: PMS7003 # pm10 = 10.00
743662: EVENT: Clock # Time = Wed, 06: 04
748652: PMSx003: invalid framelength - 142

edit:
Looks good. Runs for 30 minutes.

@TD-er
Copy link
Member

TD-er commented Feb 28, 2018

Those errors are not that bad, as long as it can keep sync. Or at least regain sync.
And I was nerding late, it is now 8am here.

@micropet
Copy link
Author

micropet commented Feb 28, 2018

If it has just failed, no values are displayed anymore.
It ran for over three hours.

There is no entry from the dust sensor in the logfile.

@uzi18
Copy link
Contributor

uzi18 commented Feb 28, 2018

It is almost perfect now with @TD-er fix.
My idea is to not do anything unnecessary, it is only related to overhead.

@micropet
Copy link
Author

It only runs for a few hours. That's not enough.

@uzi18
Copy link
Contributor

uzi18 commented Feb 28, 2018

Code is better it must be ok.
I think you have got some connection problems sometimes, now it will auto sync.

@micropet
Copy link
Author

I have no connection problems.
The device ran for weeks under Tasmota without failing once.

@TD-er
Copy link
Member

TD-er commented Feb 28, 2018

@micropet Can you show the last output of the sensor (log output)?
And also try to see if that specific ESP module is showing some accurate uptime (disable NTP for this test)
I will add the extra check on the dummy parameter. Maybe you have some valid value in the stream that has the same byte value as the first byte in the sequence and then you'll never get a valid output anymore.
So test the 'dummy' value as suggested and then stop reading if it is not matching the start sequence.

@micropet
Copy link
Author

Is that correct that the log file is only so short? Or is there a "full" version of it?

@TD-er
Copy link
Member

TD-er commented Feb 28, 2018

You can try to send it to a logserver.
But in one of the releases someone reported issues with that. Still have to look into that.

@micropet
Copy link
Author

OK, then I'm waiting for the version with the extra check on the dummy parameter.

@TD-er
Copy link
Member

TD-er commented Oct 5, 2018

GPIO16 is used to get the ESP8266 out of deep sleep (when connected to GPIO0)
This has nothing to do with the sensor itself.

As far as I know, the sensor has to be told to switch the fan on/off and that is not implemented yet.
As a work-around you could disable power to the sensor and control that via the ESP8266, but that has to be done via external commands and is not yet included in the plugin for this sensor.
It will, but I've been too busy getting stuff stable the last few month, so I've not yet looked into this sensor. :(

@AndrewB82
Copy link

AndrewB82 commented Oct 6, 2018

UPDATE: [SOLVED] - it was a wiring issue with SET pin, now it works like a charm.

Thanks for the answer, but I am confused now - @ShardanX described his way of getting the sensor to sleep few posts above, similar to the one on the plugin website:

I'm using a ESPEasy version from february so i can't, sadly. The System info says "manual reboot" - which is obviously wrong.

I'm using timing rules to put the sensor to sleep - this might be the reason why reading does not stop for me.

on System#Boot do
   gpio,16,0
   timerSet,1,20
endon

On Rules#Timer=1 do
   LongPulse,16,1,5
   timerSet,1,20
endon

GPIO 16 connected to the "SET" pin at the PMS is used to push the sensor into sleep mode.
On system boot the pin is set to 0 (low), sensor sleeps.
Timer 1 is set to run for 20 seconds, then trigger a 5 sec pulse on GPIO 16.
Timer 1 is set again to 20 seconds so it loops the sensor pulse.

It does not work for me, however, just as I wrote before. I connected GPIO16 to SET on PMS. Should it work then?

@TD-er
Copy link
Member

TD-er commented Oct 6, 2018

@AndrewB82 I guess I must be mistaken then, mixing up sensors I guess.

@AndrewB82
Copy link

@TD-er thanks anyway - btw I solved my issue - it was a wiring problem - now the sensor goes to sleep and works like a charm.

@TD-er
Copy link
Member

TD-er commented Oct 6, 2018

Is it also stable in readings?
There is still an issue about these sensors regarding stability of readings. Not the values read, but only occasionally a value is read and others claim to be missed/rejected.

@AndrewB82
Copy link

@TD-er I have set up rules to get readings every 5 minutes and send them to domoticz, but not tested it on longer run. I am planning to put the sensor in some case and then test its working. I will pay attention to this issue.

@red55der
Copy link

I'm testing a PMS7003 sensor to. It was running for hours ok, but then got stuck. Now it's get stuck after one or two readings after boot. Use a Wemos D1 mini, GPIO3/1. Going to test with above mentioned rules.

@AndrewB82
Copy link

AndrewB82 commented Oct 22, 2018

Mine 5003 has worked flawlessly for almost 2 weeks now with readings every 5 minutes, sent to Domoticz and Fibaro. Readings seem accurate and I see correlation with outside sensors, although from time time some outlier readings occur which I cannot explain.

@fzdunek
Copy link

fzdunek commented Nov 6, 2018

Hi
The rules doesn’t work for me. I connected pin set from Pms7003 to gpio16 and fan don’t stop. Any solution ?

@AndrewB82
Copy link

Have you double checked wiring @edwarpan ? For me it was the case. Do you use rules set explicitly in example?

@fzdunek
Copy link

fzdunek commented Nov 6, 2018 via email

@AndrewB82
Copy link

I also have OLED and bme280, but no reset pin, only set on gpio16 and it works.

@fzdunek
Copy link

fzdunek commented Nov 7, 2018

i checked, set pin from pms to d0 (gpio16) and get 5V because earlier i delivered 3.3V from esp. And still nothing. In dust device interval set to 30s.
2
1

I also have OLED and bme280, but no reset pin, only set on gpio16 and it works.

@apszowski
Copy link

apszowski commented Nov 7, 2018

I had similar problems and I was able to fix it.

The LongPulse command doesn't work properly if you don't configure a Switch Input on the GPIO you want to use.

image

Once I configured the Switch Input it started working :

EVENT: Rules#Timer=1
ACT : Longpulse,16,1,30
SW : GPIO 16 Pulse set for 30 sec
ACT : timerSet,1,300
ACT : timerSet,2,28
SW : Switch state 1 Output value 1
EVENT: PMS5003_Enabled#Switch=1.00
Command: timerset
Command: timerset
EVENT: Rules#Timer=2
ACT : Publish /WeatherStation/PMS5003/pm1.0, 5
ACT : Publish /WeatherStation/PMS5003/pm2.5, 10
ACT : Publish /WeatherStation/PMS5003/pm10, 10
Command: publish
Command: publish
Command: publish
SW : Switch state 0 Output value 0
EVENT: PMS5003_Enabled#Switch=0.00

Without the Switch Input, the GPIO pin would switch to 1 when the LongPulse gets executed, but would never switch back. Using the switch allows it to work.

I also use the rules mentioned by @blb4github instead of sending it via the device controller, and it works very stable now, no timing problems.

on System#Boot do
gpio,16,0
timerSet,1,50
endon

On Rules#Timer=1 do
Longpulse,16,1,30
timerSet,1,300
timerSet,2,28
endon

On Rules#Timer=2 do
Publish /%sysname%/PMS5003/pm1.0, [PMS5003#PM1.0]
Publish /%sysname%/PMS5003/pm2.5, [PMS5003#PM2.5]
Publish /%sysname%/PMS5003/pm10, [PMS5003#PM10]
endon

According to the documentation of the PMSx003 the 30 seconds high on the SET pin are required to get a stable output from the sensor anyway... the 5 seconds simply isn't good enough.

Hopefully this will get fixed in the future so this kind of workarounds isn't necessary.

@blb4github
Copy link

I did have problem with Longpulse, sorry I didn't mention before...
I did fix it on another way (without switch);I did use gpio,x,0 and gpio,x,1:

on System#Boot do
gpio,14,0
timerSet,1,20
endon

On Rules#Timer=1 do
gpio,14,1
timerSet,1,300
timerSet,2,28
endon

On Rules#Timer=2 do
Publish %sysname%/PMS7003/pm1.0, [PMS7003#PM1.0]
Publish %sysname%/PMS7003/pm2.5, [PMS7003#PM2.5]
Publish %sysname%/PMS7003/pm10, [PMS7003#PM10]
gpio,14,0
endon

@AndrewB82
Copy link

@edwarpan actually, I forgot to mention - I haven't used longpulse either - my solution is similar to the one by @blb4github

@jawilczek
Copy link

AndrewB82

Can you describe how you connected ESPEASY with FIBARO?

@AndrewB82
Copy link

Here you have code excerpts - I got it through virtual device button which is shceduled to be pressed every 15 minutes - honestly I found some code on Fibaro Forum and fine tuned it to my needs, but do not remember where exactly:

local thisdevice = fibaro:getSelfId() -- make sure youve correctly set the ip adress of the ESPEasy node
local taskId = {"1","3"} -- make sure this matches the task id on your ESPEasy
local conn = Net.FHttp(fibaro:getValue(thisdevice, 'IPAddress'), fibaro:getValue(thisdevice, 'TCPPort'))

local values = {};
local valueCounter = 1;
local err = false;

local PM25global = "PM25IndoorDIY"; -- this is global variable where PM reading is stored
local PM25norm = 25;
local PM10norm = 50;

local varTelegram = "TelegramMessage";
local telegramTimeSTART = 7;
local telegramTimeSTOP = 22;

local icon1 = 1105;
local icon2 = 1106;
local icon3 = 1107;
local icon4 = 1108;
local icon5 = 1109;
local icon6 = 1110;
local icon0 = 1112;

local currentHour = os.date("%H");

for i = 1, #taskId do
if (not err) then
response, status, errorCode = conn:GET('/json?tasknr=' .. taskId[i])

	if errorCode == 0 then
		fibaro:debug("Request "..i.." status: "..status)	
		jsonTable = json.decode(response);
		for j = 1, #jsonTable.TaskValues do
			values[valueCounter] = jsonTable.TaskValues[j].Value
			valueCounter = valueCounter + 1;
		end
	else
		err = true;
		fibaro:debug("Connection Error");
		fibaro:log("Connection Error");
		fibaro:call(thisdevice, "setProperty", "currentIcon", icon0);
		fibaro:call(thisdevice, "setProperty", "ui.lblPM25.value", "Connection Error");
		fibaro:call(thisdevice, "setProperty", "ui.lblPM10.value", "Connection Error");
		fibaro:call(thisdevice, "setProperty", "ui.lblTemperature.value", "Connection Error");
		fibaro:call(thisdevice, "setProperty", "ui.lblHumidity.value", "Connection Error");
		fibaro:call(thisdevice, "setProperty", "ui.lblPressure.value", "Connection Error");
  
  		local counter = 10;  
  	
		fibaro:debug("Telegram buffer: "..fibaro:getGlobalValue(varTelegram));
		while ((fibaro:getGlobalValue(varTelegram) ~= "0") and (counter > 0)) do
			fibaro:debug("Waiting for Telegram buffer - trial no. "..10-counter+1);
    		fibaro:sleep(200);
    		counter = counter - 1;
		end
  		fibaro:sleep(500);
		fibaro:setGlobal(varTelegram,"Uwaga! Problem z połączeniem z domowym czujnikiem pyłu zawieszonego PM2.5.");
	end
end

end

for k = 1, #values do
fibaro:debug(values[k]);
if (not err) then
if (values[k] == "nil") then
err = true;
fibaro:call(thisdevice, "setProperty", "currentIcon", icon0);
fibaro:call(thisdevice, "setProperty", "ui.lblPM25.value", "Value Error");
fibaro:call(thisdevice, "setProperty", "ui.lblPM10.value", "Value Error");
fibaro:call(thisdevice, "setProperty", "ui.lblTemperature.value", "Value Error");
fibaro:call(thisdevice, "setProperty", "ui.lblHumidity.value", "Value Error");
fibaro:call(thisdevice, "setProperty", "ui.lblPressure.value", "Value Error");

  		local counter = 10;  
  	
		fibaro:debug("Telegram buffer: "..fibaro:getGlobalValue(varTelegram));
		while ((fibaro:getGlobalValue(varTelegram) ~= "0") and (counter > 0)) do
			fibaro:debug("Waiting for Telegram buffer - trial no. "..10-counter+1);
    		fibaro:sleep(200);
    		counter = counter - 1;
		end
  		fibaro:sleep(500);
		fibaro:setGlobal(varTelegram,"Uwaga! Domowy czujnik pyłu zawieszonego PM2.5 przesyła błędne dane.");
    end
end

end

if (not err) then

fibaro:setGlobal(PM25global,values[2]);

local PM25Proc = (values[2]/PM25norm)*100;
local PM10Proc = (values[3]/PM10norm)*100;

if (tonumber(values[2]) < 13) then 
	fibaro:call(thisdevice, "setProperty", "currentIcon", icon1);
elseif (tonumber(values[2]) < 37) then
	fibaro:call(thisdevice, "setProperty", "currentIcon", icon2);
elseif (tonumber(values[2]) < 61) then
	fibaro:call(thisdevice, "setProperty", "currentIcon", icon3);
elseif (tonumber(values[2]) < 85) then
	fibaro:call(thisdevice, "setProperty", "currentIcon", icon4);
elseif (tonumber(values[2]) < 121) then
	fibaro:call(thisdevice, "setProperty", "currentIcon", icon5); 
else							
	fibaro:call(thisdevice, "setProperty", "currentIcon", icon6);
end

if ((PM25Proc > 150) and ((tonumber(currentHour) >= telegramTimeSTART) and (tonumber(currentHour) < telegramTimeSTOP))) then

	local counter = 10;  
  	
	fibaro:debug("Telegram buffer: "..fibaro:getGlobalValue(varTelegram));
	while ((fibaro:getGlobalValue(varTelegram) ~= "0") and (counter > 0)) do
		fibaro:debug("Waiting for Telegram buffer - trial no. "..10-counter+1);
    	fibaro:sleep(200);
    	counter = counter - 1;
	end
  	fibaro:sleep(500);
	fibaro:setGlobal(varTelegram,"Uwaga! Poziom pyłu zawieszonego PM2.5 w pomieszczeniu wynosi "..tostring(PM25Proc).."% normy.");
end

fibaro:call(thisdevice, "setProperty", "ui.lblPM25.value", values[2].." µg/m3 ("..PM25Proc.."%)");
fibaro:call(thisdevice, "setProperty", "ui.lblPM10.value", values[3].." µg/m3 ("..PM10Proc.."%)");
fibaro:call(thisdevice, "setProperty", "ui.lblTemperature.value", values[4].." °C");
fibaro:call(thisdevice, "setProperty", "ui.lblHumidity.value", values[5].."%");
fibaro:call(thisdevice, "setProperty", "ui.lblPressure.value", values[6].." hPa");

end

@jawilczek
Copy link

jawilczek commented Feb 15, 2019 via email

@zbx-sadman
Copy link

Hello @ShardanX

Due to datasheet the PMSx003 have a lifetime of around 8000h, so permanently driven it will run for 333 days. The laser diode has a limited lifetime so after this period the values will get unreliable.

Can you post link to the datashet with 8000h lifetime?

Plantower support answer me about PMS-A003 sensor:

Our sensor lifetime in our datasheet is 3years, but actually it can use more than 4.5year with works continuously.
 
Best regards,
Holly Gao(Ms.)

Sales Executive-Marketing Dept.
Beijing Plantower Technology Co., Ltd.
#613,Building 9,Yuxi Road No.9,Houshayu,Shunyi District,Beijing, P.R.China.

I see in the PMS 5003/7003/A003 manuals "MTTF ≥3 Year(Y)"

@mrdc
Copy link

mrdc commented Oct 19, 2019

@blb4github

I did have problem with Longpulse, sorry I didn't mention before...
I did fix it on another way (without switch);I did use gpio,x,0 and gpio,x,1:

on System#Boot do
gpio,14,0
timerSet,1,20
endon

On Rules#Timer=1 do
gpio,14,1
timerSet,1,300

@AndrewB82

actually, I forgot to mention - I haven't used longpulse either - my solution is similar to the one by @blb4github

It shouldn't work when we set GPIO High for PMSx003 SET Pin - sensor won't sleep. We need to cycle sleep/awake:

on System#Boot do
gpio,YOUR_GPIO_FOR_SET_PIN,0
timerSet,1,30
endon

On Rules#Timer=1 do
gpio,YOUR_GPIO_FOR_SET_PIN,1
timerSet,2,30

On Rules#Timer=2 do
gpio,YOUR_GPIO_FOR_SET_PIN,0
timerSet,1,30

@tonhuisman
Copy link
Contributor

This seems to be solved, so can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Plugin Related to supported sensors Category: Stabiliy Things that work, but not as long as desired Status: In Progress Is being worked on by the development team Type: Bug Considered a bug
Projects
Status: Done
Status: Closed
Development

No branches or pull requests