2019-01-03 22:20:50 +01:00
|
|
|
#include <knx.h>
|
2019-06-04 00:09:40 +02:00
|
|
|
#ifdef ARDUINO_ARCH_ESP8266
|
2019-02-26 22:42:06 +01:00
|
|
|
#include <WiFiManager.h>
|
2019-06-04 00:09:40 +02:00
|
|
|
#endif
|
2019-01-03 22:20:50 +01:00
|
|
|
|
|
|
|
#define RELAYPIN 12
|
|
|
|
|
|
|
|
// create named references for easy access to group objects
|
2019-05-13 22:31:45 +02:00
|
|
|
#define goSwitch knx.getGroupObject(1)
|
|
|
|
#define goBlock knx.getGroupObject(2)
|
|
|
|
#define goStatus knx.getGroupObject(3)
|
2019-01-03 22:20:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
// callback from switch-GO
|
|
|
|
void switchCallback(GroupObject& go)
|
|
|
|
{
|
2019-06-12 00:01:21 +02:00
|
|
|
if (goBlock.value())
|
2019-01-03 22:20:50 +01:00
|
|
|
return;
|
|
|
|
|
2019-06-04 00:09:40 +02:00
|
|
|
bool value = goSwitch.value();
|
2019-01-03 22:20:50 +01:00
|
|
|
digitalWrite(RELAYPIN, value);
|
2019-06-04 00:09:40 +02:00
|
|
|
goStatus.value(value);
|
2019-01-03 22:20:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
SerialDBG.begin(115200);
|
|
|
|
|
2019-06-04 00:09:40 +02:00
|
|
|
#ifdef ARDUINO_ARCH_ESP8266
|
2019-05-09 20:52:04 +02:00
|
|
|
WiFiManager wifiManager;
|
2019-02-26 22:42:06 +01:00
|
|
|
wifiManager.autoConnect("knx-sonoffS20");
|
2019-06-04 00:09:40 +02:00
|
|
|
#endif
|
2019-02-26 22:42:06 +01:00
|
|
|
|
2019-01-03 22:20:50 +01:00
|
|
|
// read adress table, association table, groupobject table and parameters from eeprom
|
|
|
|
knx.readMemory();
|
|
|
|
|
2019-05-09 20:52:04 +02:00
|
|
|
if (knx.configured())
|
|
|
|
{
|
|
|
|
// register callback for reset GO
|
|
|
|
goSwitch.callback(switchCallback);
|
2019-06-04 00:09:40 +02:00
|
|
|
goSwitch.dataPointType(Dpt(1, 0));
|
|
|
|
goBlock.dataPointType(Dpt(1, 0));
|
|
|
|
goStatus.dataPointType(Dpt(1, 0));
|
2019-05-09 20:52:04 +02:00
|
|
|
}
|
|
|
|
|
2019-01-03 22:20:50 +01:00
|
|
|
// start the framework. Will get wifi first.
|
|
|
|
knx.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
// don't delay here to much. Otherwise you might lose packages or mess up the timing with ETS
|
|
|
|
knx.loop();
|
|
|
|
|
|
|
|
// only run the application code if the device was configured with ETS
|
2019-05-09 20:52:04 +02:00
|
|
|
if(!knx.configured())
|
2019-01-03 22:20:50 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
// nothing else to do.
|
|
|
|
}
|