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

Enhancement: Nova Fitness SDS011 Dust sensor implement working period command #3724

Closed
edelstahlratte opened this issue Sep 7, 2018 · 21 comments
Labels
awaiting feedback Action - Waiting for response or more information enhancement Type - Enhancement that will be worked on

Comments

@edelstahlratte
Copy link
Contributor

Because the sensor has a limited lifespan of abt. 8000 hours ist would be nice to have the 'working period' command implemented.

Working period means that in a given timeframe the sensor is only active for 30 seconds and goes to sleep after that.

I'm not a C++ programmer, so it is very hard for me to do it on my own :(

The SDS Control Protocol Specification states the following:

image

So it looks that you only have to send these 19 bytes to set the feature on the SDS011.

Maybe someone can evaluate if it's possible to use that feature in tasmota.

Thank you.

@mike2nl
Copy link
Contributor

mike2nl commented Sep 7, 2018

@edelstahlratte
Copy link
Contributor Author

@mike2nl

Yes, I read it and the sensor is working fine, but the 'working period' command would give the sensor a longer lifespan...

@edelstahlratte
Copy link
Contributor Author

@mike2nl

Maybe you can help:

I added some code to tasmota but I'm flying blind here...

e.g. in the xns_20_novasds.ino:

uint8_t novasds_workperiod[19] = {
	0xAA,	// head
	0xB4,	// command id
	0x08,	// data byte 1
	0x01,	// data byte 2 set
	0x05,	// data byte 3 work period 5 minutes: measure for 30 seconds + sleep the rest
	0x00,	// data byte 4
	0x00,	// data byte 5
	0x00,	// data byte 6
	0x00,	// data byte 7
	0x00,	// data byte 8
	0x00,	// data byte 9
	0x00,	// data byte 10
	0x00,	// data byte 11
	0x00,	// data byte 12
	0x00,	// data byte 13
	0xFF,	// data byte 14 (device id byte 1)
	0xFF,	// data byte 15 (device id byte 2)
	0x07,	// checksum (low 8 bit of sum of data bytes)
	0xAB	// tail
};

void NovaSdsSetWorkPeriod()
{
  //maybe there is some data
  while (NovaSdsSerial->available() > 0) {
      NovaSdsSerial->read();
  }

 NovaSdsSerial->flush();
 
 NovaSdsSerial->write(novasds_workperiod, sizeof(novasds_workperiod));
 
 // read the answer and ignore
 while (NovaSdsSerial->available() > 0) {
     NovaSdsSerial->read();
 }
}

I call the function in NovaSdsInit();

But it does not have any effect... Maybe the CRC wrong? Is the send command right? Don't know... How to get some output to the webconsole?

Thank you.

@ascillato2 ascillato2 added enhancement Type - Enhancement that will be worked on awaiting feedback Action - Waiting for response or more information labels Sep 7, 2018
@edelstahlratte
Copy link
Contributor Author

I'm making progress:

The checksum was wrong:

0x0C, // checksum (low 8 bit of sum of data bytes)
This is right...

The sensor will be active for 30 seconds every 5 Minutes...

But I have to understand Tasmota better to really integrate it... Digging further...

@Frogmore42
Copy link
Contributor

You might want to check out this PR
#2841
I believe the enhancement you seek is already available.

@edelstahlratte
Copy link
Contributor Author

edelstahlratte commented Sep 7, 2018

@Frogmore42

You are totally right! But the changes are not merged into the development tree... That's why I didn't find them in the code...

My approach was a litttle different but it achieves the same thing...
#2841 sleeps and wakes the sensor manually... I make use of the 'working period' command...

At least I have learnt more about tasmota and C++ in general :)

@edelstahlratte
Copy link
Contributor Author

@ascillato2

Will the changes from #2841 be merged into development?

@ascillato
Copy link
Contributor

Please, ask Theo. @arendst

@arendst
Copy link
Owner

arendst commented Sep 7, 2018

Have to look at it. The way it is done currently will upset people as their GPIOs will change....

@edelstahlratte
Copy link
Contributor Author

@arendst

Could you please specify further? You mean bécause of the new GPIO_SDS0X1_TX and the renamed GPIO_SDS0X1?

@arendst
Copy link
Owner

arendst commented Sep 7, 2018

The additional GPIO define will shift all GPIOs below one position down resulting in changed GPIO definitions.

@edelstahlratte
Copy link
Contributor Author

@arendst

Thank you, that clarifies a lot...

@edelstahlratte
Copy link
Contributor Author

@arendst

Would it be a solution for the GPIO Problem to hardcode the GPIO_TXD as serial transmit?

@arendst
Copy link
Owner

arendst commented Sep 8, 2018

Yeah, also a good idea.

I'll focus on a solution like I use for the modules. I'll investigate a sorted list. Once done will pick this up.

arendst added a commit that referenced this issue Sep 8, 2018
Add sleep to Nova Fitness SDS01X sensor (#2841, #3724)
@edelstahlratte
Copy link
Contributor Author

@arendst

you integrated the changes from #2841. Thank you!

Should I send a pull request for my solution as well?
#2841 relies on Tasmota for the sleep and wakeup and check for valid data. My solution using the already mentioned 'working period' command of the SDS011 promotes that work to the sensor, it wakes and sleeps by itself. So tasmota just asks for the data and the sensor automatically sends the last valid measurement...

@arendst
Copy link
Owner

arendst commented Sep 10, 2018

If your solution presents last valid data when asked then I'm not sure if it will work out. The rule implementation queries all sensor within 2 seconds for their latest information. For some sensors I use a local storage location which is then being updated by the sensor driver in 1 minute or 5 minutes or even every 10 seconds depending on it's expected change. The driver then provides the data in the storage to the rule handler.

I forsee in that case that the SDS011 will never go to sleep.

On the other hand if the current implementation relies on the sleep command then that's not good either. I never use sleep so in my case the sensor would not go to sleep.

I propose a solution where the sensor goes to sleep on it's own timer (preferable initiated by an amount of FUNC_EVERY_SECOND) and just stores it's values in a local storage for every software user to query at will.

@edelstahlratte
Copy link
Contributor Author

@arendst

The last measurement is saved in the SDS011. So when queried it presents the saved data without waking up...

It only wakes up to the specified 'working period' interval and saves the new measuremet internal... I have it running since 2 days without problems...

@arendst
Copy link
Owner

arendst commented Sep 10, 2018

That's very useful!

Well if you can make a working PR and try to support this specific solution I will replace the current driver with yours.

@edelstahlratte
Copy link
Contributor Author

It's only a quite small change in the novasds.ino, because all the GPIO_SDS0X1_TX stuff is now already implemented... First I have to figure out how to make a proper pull request ;)

@edelstahlratte
Copy link
Contributor Author

@arendst

I just created pull request #3749... Hope that it fits the bill... My first one :)

@arendst
Copy link
Owner

arendst commented Sep 10, 2018

It's released just now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting feedback Action - Waiting for response or more information enhancement Type - Enhancement that will be worked on
Projects
None yet
Development

No branches or pull requests

6 participants