2016-03-30 21:08:18 +02:00
|
|
|
#include <Homie.h> // https://github.com/marvinroger/homie-esp8266
|
|
|
|
|
2016-04-09 00:21:18 +02:00
|
|
|
#include "DeviceLed.h"
|
2016-04-08 10:18:59 +02:00
|
|
|
#include "DeviceLdr.h"
|
2016-04-09 01:12:59 +02:00
|
|
|
#include "DeviceDht.h"
|
2016-04-08 10:18:59 +02:00
|
|
|
|
2016-04-09 01:12:59 +02:00
|
|
|
#undef HAS_LDR
|
|
|
|
#undef HAS_LED
|
|
|
|
#define HAS_DHT
|
2016-03-30 21:08:18 +02:00
|
|
|
|
|
|
|
// HAS_LED
|
|
|
|
#define PIN_LED_RED D8
|
|
|
|
#define PIN_LED_GREEN D6
|
|
|
|
#define PIN_LED_BLUE D7
|
2016-04-09 00:21:18 +02:00
|
|
|
DeviceLed deviceLed(PIN_LED_RED, PIN_LED_GREEN, PIN_LED_BLUE);
|
2016-03-30 21:08:18 +02:00
|
|
|
|
|
|
|
// HAS_LDR
|
|
|
|
#define PIN_LDR A0
|
2016-04-08 10:18:59 +02:00
|
|
|
DeviceLdr deviceLdr(PIN_LDR);
|
2016-03-30 21:08:18 +02:00
|
|
|
|
|
|
|
// HAS_DHT
|
|
|
|
#define PIN_DHT D4
|
|
|
|
#define TYPE_DHT DHT22
|
2016-04-09 01:12:59 +02:00
|
|
|
DeviceDht deviceDht(PIN_DHT, TYPE_DHT);
|
2016-03-30 21:08:18 +02:00
|
|
|
|
|
|
|
void setupHandler() {
|
|
|
|
#ifdef HAS_LDR
|
2016-04-08 10:18:59 +02:00
|
|
|
deviceLdr.setup();
|
2016-03-30 21:08:18 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAS_LED
|
2016-04-09 00:21:18 +02:00
|
|
|
deviceLed.setup();
|
2016-03-30 21:08:18 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAS_DHT
|
2016-04-09 01:12:59 +02:00
|
|
|
deviceDht.setup();
|
2016-03-30 21:08:18 +02:00
|
|
|
#endif
|
2016-02-23 11:12:04 +01:00
|
|
|
}
|
|
|
|
|
2016-03-30 21:08:18 +02:00
|
|
|
void loopHandler() {
|
|
|
|
#ifdef HAS_LDR
|
2016-04-08 10:18:59 +02:00
|
|
|
deviceLdr.loop();
|
2016-03-30 21:08:18 +02:00
|
|
|
#endif
|
2016-04-09 00:21:18 +02:00
|
|
|
#ifdef HAS_LED
|
|
|
|
deviceLed.loop();
|
|
|
|
#endif
|
2016-03-30 21:08:18 +02:00
|
|
|
#ifdef HAS_DHT
|
2016-04-09 01:12:59 +02:00
|
|
|
deviceDht.loop();
|
2016-03-30 21:08:18 +02:00
|
|
|
#endif
|
2016-02-24 07:43:01 +01:00
|
|
|
}
|
|
|
|
|
2016-02-23 11:12:04 +01:00
|
|
|
void setup() {
|
2016-03-30 21:08:18 +02:00
|
|
|
Homie.setFirmware("things", "1.0.0");
|
|
|
|
#ifdef HAS_LDR
|
2016-04-08 10:18:59 +02:00
|
|
|
deviceLdr.homieRegister();
|
2016-03-30 21:08:18 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAS_LED
|
2016-04-09 00:21:18 +02:00
|
|
|
deviceLed.homieRegister();
|
2016-03-30 21:08:18 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAS_DHT
|
2016-04-09 01:12:59 +02:00
|
|
|
deviceDht.homieRegister();
|
2016-03-30 21:08:18 +02:00
|
|
|
#endif
|
|
|
|
Homie.setSetupFunction(setupHandler);
|
|
|
|
Homie.setLoopFunction(loopHandler);
|
|
|
|
Homie.setup();
|
2016-02-23 11:12:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2016-03-30 21:08:18 +02:00
|
|
|
Homie.loop();
|
2016-02-23 11:12:04 +01:00
|
|
|
}
|