SDS011 w nowej bibliotece

Awatar użytkownika
shimano73
Posty: 1974
Rejestracja: ndz lut 28, 2016 12:27 pm
Lokalizacja: Orzesze
Kontakt:

Koledzy , znajdując chwilę czasu , chciałem zrobić sobie obsługę czujnika smogu sds011 w kanale czujnika temperatury i wilgotności.
Niestety brak wiedzy zmusza do zwrócenia sie do was z pomocą. Wywołanie miało by wyglądać tak

Kod: Zaznacz cały

  new Supla::Sensor::SDS011(1,3, 10);
gdzie 1- software rx, 3 -softwere rx, 10 - częstotliwość pomiarów

Plik sds011.h

Kod: Zaznacz cały


/*

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#ifndef _sds011_h
#define _sds011_h

#include <DHT.h>
#include "SdsDustSensor.h"

#include "therm_hygro_meter.h"

namespace Supla {
namespace Sensor {
class SDS011: public ThermHygroMeter {
  public:
    SDS011(int rxPin, int txPin, int Period ); 
      

    double getTemp();
    double getHumi();   
    void iterateAlways();
    void onInit();	
    
    


    protected:
 	  int _rxPin;
	  int _txPin;
	  int _Period;
	  int _pm25;
	  int _pm10;
      double lastValidTemp;
      double lastValidHumi;
      int8_t retryCountTemp;
      int8_t retryCountHumi;

};

};  // namespace Sensor
};  // namespace Supla

#endif


plik SDS011.cpp

Kod: Zaznacz cały

/*
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#include "Arduino.h"
#include "SDS011.h"
#include <DHT.h>
#include "SdsDustSensor.h"
//#include "therm_hygro_meter.h"

namespace Supla {
namespace Sensor {

SDS011::SDS011(int rxPin, int txPin, int Period ){

	_rxPin = rxPin;
	_txPin = txPin;
	SdsDustSensor sds(_rxPin, _txPin);
	channel.setType(SUPLA_CHANNELTYPE_HUMIDITYANDTEMPSENSOR);
    channel.setDefault(SUPLA_CHANNELFNC_HUMIDITYANDTEMPERATURE);
	sds.begin();
	Serial.println(sds.queryFirmwareVersion().toString()); // prints firmware version
    Serial.println(sds.setActiveReportingMode().toString()); // ensures sensor is in 'active' reporting mode
    Serial.println(sds.setCustomWorkingPeriod(_Period).toString()); // sensor sends data every 3 minutes
	//PmResult pm = sds.readPm();
}

double SDS011::getTemp() {
  double value = TEMPERATURE_NOT_AVAILABLE;
  value = _pm25;
  if (isnan(value)) {
	value = TEMPERATURE_NOT_AVAILABLE;
  }

  if (value == TEMPERATURE_NOT_AVAILABLE) {
	retryCountTemp++;
	if (retryCountTemp > 3) {
	  retryCountTemp = 0;
	} else {
	  value = lastValidTemp;
	}
  } else {
	retryCountTemp = 0;
  }
  lastValidTemp = value;

  return value;
}

double SDS011::getHumi() {
  double value = HUMIDITY_NOT_AVAILABLE;
  value = _pm10;

  if (isnan(value)) {
	value = HUMIDITY_NOT_AVAILABLE;
  }

  if (value == HUMIDITY_NOT_AVAILABLE) {
	retryCountHumi++;
	if (retryCountHumi > 3) {
	  retryCountHumi = 0;
	} else {
	  value = lastValidHumi;
	}
  } else {
	retryCountHumi = 0;
  }
  lastValidHumi = value;

  return value;
}

void SDS011::iterateAlways() {
  if (lastReadTime + 10000 < millis()) {
	lastReadTime = millis();
	channel.setNewValue(getTemp(), getHumi());
	
	PmResult pm = sds.readPm();
	if (pm.isOk()) {
		_pm25 = pm.pm25;
		_pm10 = pm.pm10;
	}
	
  }
}

void SDS011::onInit() {
 
  channel.setNewValue(getTemp(), getHumi());
  
}


};  // namespace Sensor
};  // namespace Supla


Problem jest w :

Kod: Zaznacz cały



C:\Users\Supla\Documents\Arduino\libraries\SuplaDevice\src\supla\sensor\SDS011.cpp: In member function 'virtual void Supla::Sensor::SDS011::iterateAlways()':

C:\Users\Supla\Documents\Arduino\libraries\SuplaDevice\src\supla\sensor\SDS011.cpp:88:16: error: 'sds' was not declared in this scope

  PmResult pm = sds.readPm();

                             ^
exit status 1

Błąd kompilacji dla płytki Generic ESP8266 Module.

Czy może mi ktoś wytłumaczyć dlaczego kompilator krzyczy że "sds nie jest zadeklarowany i gdzie i jak powinien być zadeklarowany
W elektronice jak nie wiadomo o co chodzi to zwykle chodzi o zasilanie

Wezmę udział w Supla Offline Party 2024 :)
vajera
Posty: 395
Rejestracja: śr paź 31, 2018 7:58 am

zrobiłeś z SDS zmienną lokalną widoczną tylko w konstruktorze - przenieś ją do deklaracji klasy do sekcji protected
Awatar użytkownika
shimano73
Posty: 1974
Rejestracja: ndz lut 28, 2016 12:27 pm
Lokalizacja: Orzesze
Kontakt:

Próbowałem tak jak piszesz

Kod: Zaznacz cały

 SdsDustSensor sds(_rxPin,_txPin);

umieściłem w pliku sds011.h w sekcji

Kod: Zaznacz cały

 protected:
 	  int _rxPin;
	  int _txPin;
	  int _Period;
	  int _pm25;
	  int _pm10;
      double lastValidTemp;
      double lastValidHumi;
      int8_t retryCountTemp;
      int8_t retryCountHumi;
	  SdsDustSensor sds(_rxPin,_txPin);

ale wówczas pojawia się błąd

Kod: Zaznacz cały


In file included from C:\Users\Supla\Documents\Arduino\SDS011_newlib\SDS011_newlib.ino:18:0:
C:\Users\Supla\Documents\Arduino\libraries\SuplaDevice\src/supla/sensor/SDS011.h:51:22: error: '_rxPin' is not a type
    SdsDustSensor sds(_rxPin, _txPin);
                                         ^
C:\Users\Supla\Documents\Arduino\libraries\SuplaDevice\src/supla/sensor/SDS011.h:51:29: error: '_txPin' is not a type
    SdsDustSensor sds(_rxPin, _txPin);
                                                     ^
exit status 1
Błąd kompilacji dla płytki Generic ESP8266 Module.




o co chodzi z tym typem?
W elektronice jak nie wiadomo o co chodzi to zwykle chodzi o zasilanie

Wezmę udział w Supla Offline Party 2024 :)
krycha88
Posty: 5197
Rejestracja: pt lis 16, 2018 7:25 am
Kontakt:

spróbuj trochę inaczej:

SDS_011.h

Kod: Zaznacz cały

#ifndef _sds011_h
#define _sds011_h

#include <Arduino.h>
#include <SdsDustSensor.h>

#include <supla/sensor/therm_hygro_meter.h>

namespace Supla {
namespace Sensor {
class SDS011 : public ThermHygroMeter {
 public:
  SDS011(int rxPin, int txPin, int Period);

  double getTemp();
  double getHumi();
  void readValuesFromDevice();
  void iterateAlways();
  void onInit();

 protected:
  SdsDustSensor sds;

  double pm25;
  double pm10;
  int8_t retryCount;

};

};  // namespace Sensor
};  // namespace Supla

#endif
SDS_011.cpp

Kod: Zaznacz cały

#include "SDS_011.h"

namespace Supla {
namespace Sensor {

SDS011::SDS011(int rxPin, int txPin, int Period) : sds(rxPin, txPin) {
  channel.setType(SUPLA_CHANNELTYPE_HUMIDITYANDTEMPSENSOR);
  channel.setDefault(SUPLA_CHANNELFNC_HUMIDITYANDTEMPERATURE);

  sds.begin();
  Serial.println(
      sds.queryFirmwareVersion().toString());  // prints firmware version
  Serial.println(
      sds.setActiveReportingMode()
          .toString());  // ensures sensor is in 'active' reporting mode
  Serial.println(sds.setCustomWorkingPeriod(Period)
                     .toString());  // sensor sends data every 3 minutes
                                    // PmResult pm = sds.readPm();
}

double SDS011::getTemp() {
  return pm25;
}

double SDS011::getHumi() {
  return pm10;
}

void SDS011::readValuesFromDevice() {
  PmResult pm = sds.readPm();
  if (!pm.isOk()) {
    retryCount++;
    if (retryCount > 3) {
      retryCount = 0;
      pm25 = TEMPERATURE_NOT_AVAILABLE;
      pm10 = HUMIDITY_NOT_AVAILABLE;
    }
  } else {
    retryCount = 0;
    pm25 = pm.pm25;
    pm10 = pm.pm10;
  }
}

void SDS011::iterateAlways() {
  if (lastReadTime + 10000 < millis()) {
    lastReadTime = millis();
    readValuesFromDevice();
    channel.setNewValue(getTemp(), getHumi());
  }
}

void SDS011::onInit() {
  readValuesFromDevice();
  channel.setNewValue(getTemp(), getHumi());
}

};  // namespace Sensor
};  // namespace Supla

https://gui-generic-builder.supla.io/
Awatar użytkownika
shimano73
Posty: 1974
Rejestracja: ndz lut 28, 2016 12:27 pm
Lokalizacja: Orzesze
Kontakt:

OK, program się kompiluje bez błędu, ale czy działa to się dopiero okaże :D
Dziękuję bardzo.
W elektronice jak nie wiadomo o co chodzi to zwykle chodzi o zasilanie

Wezmę udział w Supla Offline Party 2024 :)
krycha88
Posty: 5197
Rejestracja: pt lis 16, 2018 7:25 am
Kontakt:

shimano73 pisze: ndz maja 02, 2021 5:01 pm OK, program się kompiluje bez błędu, ale czy działa to się dopiero okaże :D
Dziękuję bardzo.
Daj znać czy działa ;)
https://gui-generic-builder.supla.io/
Awatar użytkownika
dawidd
Posty: 615
Rejestracja: wt gru 19, 2017 12:45 pm

Fajnie jak by taki czujnik sie pojawił w GUI Generic
krycha88
Posty: 5197
Rejestracja: pt lis 16, 2018 7:25 am
Kontakt:

Ogólnie jakoś dziwnie jest napisana ta biblioteka SdsDustSensor.h stosowane są w niej delay(500)...
https://gui-generic-builder.supla.io/
Awatar użytkownika
shimano73
Posty: 1974
Rejestracja: ndz lut 28, 2016 12:27 pm
Lokalizacja: Orzesze
Kontakt:

krycha88 pisze: ndz maja 02, 2021 6:49 pm
shimano73 pisze: ndz maja 02, 2021 5:01 pm OK, program się kompiluje bez błędu, ale czy działa to się dopiero okaże :D
Dziękuję bardzo.
Daj znać czy działa ;)
Działa, działa , jeszcze raz dzięki 😁
W elektronice jak nie wiadomo o co chodzi to zwykle chodzi o zasilanie

Wezmę udział w Supla Offline Party 2024 :)
ODPOWIEDZ

Wróć do „Pomoc”