Chodzi o te "setMTreg"?
Wygląda ok. Tylko ten setMTreg dla lux <= 10 wywoła się przy lux = nan, bo ustawiamy tam te -275 stopni. Ale przy braku odczytu chyba i tak to nie ma większego znaczenia.
Chodzi o te "setMTreg"?
Tak, zauważyłem to i tak, nie ma to znaczeniaklew wrote: Fri May 22, 2020 10:24 amChodzi o te "setMTreg"?
Wygląda ok. Tylko ten setMTreg dla lux <= 10 wywoła się przy lux = nan, bo ustawiamy tam te -275 stopni. Ale przy braku odczytu chyba i tak to nie ma większego znaczenia.
Code: Select all
#ifndef _humidity_h
#define _humidity_h
#include "supla/channel.h"
#include "supla/element.h"
#define HUMIDITY_NOT_AVAILABLE -1
namespace Supla {
namespace Sensor {
class myHumidity: public Element {
public:
myHumidity() {
channel.setType(SUPLA_CHANNELTYPE_HUMIDITYSENSOR);
channel.setDefault(SUPLA_CHANNELFNC_HUMIDITY);
channel.setNewValue(HUMIDITY_NOT_AVAILABLE);
}
virtual double getValue() {
return HUMIDITY_NOT_AVAILABLE;
}
void iterateAlways() {
if (lastReadTime + 10000 < millis()) {
lastReadTime = millis();
channel.setNewValue(getValue());
}
}
protected:
Channel *getChannel() {
return &channel;
}
Channel channel;
};
}; // namespace Sensor
}; // namespace Supla
#endif
Inaczej..klew wrote: Wed Jun 10, 2020 3:09 pm Musisz zaimplementować metodę getValue - wstaw tam odczyt wartości analogowej
Code: Select all
#ifdef ANALOG_SENSOR
int a0_value;
class AnalogSensor : public Supla::Sensor::????? {
public: AnalogSensor(int pin) : pin(pin) {}
void onInit() {
pinMode(pin, INPUT);
channel.setNewValue(getValue()); }
double getValue() {
a0_value = analogRead(pin);
return a0_value; }
protected: int pin;
};
#endif
Tutaj masz przykład z BH1750: viewtopic.php?p=69579#p69579dogu18 wrote: Tue Sep 15, 2020 8:58 pm Witam wiem ze nie na temat ale może tutorial jakiś jak dodać do nowego SuplaDevice swoje sensory.
np BH1750 jak dodać go żebym mógł go używać:)
pozdrawiam
Code: Select all
#ifndef _DiffHCSR04_h
#define _DiffHCSR04_h
#include "supla/channel.h"
#include "supla/sensor/distance.h"
#include "supla/sensor/HC_SR04.h"
namespace Supla {
namespace Sensor {
double goodValue;
class DiffHCSR04: public Supla::Sensor::HC_SR04 {
public:
DiffHCSR04(int8_t trigPin, int8_t echoPin) : HC_SR04(trigPin, echoPin) {}
double getValue() {
if ((0.5 - Supla::Sensor::HC_SR04::getValue()) > 0) {
goodValue = (0.5 - Supla::Sensor::HC_SR04::getValue());
return 0.5 - Supla::Sensor::HC_SR04::getValue();
}
else {
return goodValue;
}
}
// double getValue() {
// return 0.5 - Supla::Sensor::HC_SR04::getValue();
// }
};
}; // namespace Sensor
}; // namespace Supla
#endif
Z tego co kojarzę to tak jak dodałem powyżejbigthomas wrote: Fri Oct 23, 2020 8:10 pm Witam,
W jaki sposób mogę wymusić aby odczyt z czujnika HCSR04 wykonywał się co 10 minut.Code: Select all
#ifndef _DiffHCSR04_h #define _DiffHCSR04_h #include "supla/channel.h" #include "supla/sensor/distance.h" #include "supla/sensor/HC_SR04.h" namespace Supla { namespace Sensor { double goodValue; class DiffHCSR04: public Supla::Sensor::HC_SR04 { public: DiffHCSR04(int8_t trigPin, int8_t echoPin) : HC_SR04(trigPin, echoPin) {} double getValue() { if ((0.5 - Supla::Sensor::HC_SR04::getValue()) > 0) { goodValue = (0.5 - Supla::Sensor::HC_SR04::getValue()); return 0.5 - Supla::Sensor::HC_SR04::getValue(); } else { return goodValue; } } void iterateAlways() { if (lastReadTime + 600000 < millis()) { lastReadTime = millis(); channel.setNewValue(getValue()); } } // double getValue() { // return 0.5 - Supla::Sensor::HC_SR04::getValue(); // } }; }; // namespace Sensor }; // namespace Supla #endif