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);
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
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.