2021-06-02 17:55:07 +02:00
|
|
|
#include <Arduino.h>
|
2019-05-13 22:31:45 +02:00
|
|
|
#include <knx.h>
|
|
|
|
|
2021-06-14 08:10:48 +02:00
|
|
|
#if MASK_VERSION != 0x07B0 && (defined ARDUINO_ARCH_ESP8266 || defined ARDUINO_ARCH_ESP32)
|
2019-05-27 20:13:57 +02:00
|
|
|
#include <WiFiManager.h>
|
|
|
|
#endif
|
2019-05-13 22:31:45 +02:00
|
|
|
|
|
|
|
// create named references for easy access to group objects
|
|
|
|
#define goCurrent knx.getGroupObject(1)
|
|
|
|
#define goMax knx.getGroupObject(2)
|
|
|
|
#define goMin knx.getGroupObject(3)
|
|
|
|
#define goReset knx.getGroupObject(4)
|
|
|
|
|
|
|
|
float currentValue = 0;
|
|
|
|
float maxValue = 0;
|
|
|
|
float minValue = RAND_MAX;
|
|
|
|
long lastsend = 0;
|
|
|
|
|
|
|
|
void measureTemp()
|
|
|
|
{
|
|
|
|
long now = millis();
|
|
|
|
if ((now - lastsend) < 2000)
|
|
|
|
return;
|
|
|
|
|
|
|
|
lastsend = now;
|
|
|
|
int r = rand();
|
|
|
|
currentValue = (r * 1.0) / (RAND_MAX * 1.0);
|
|
|
|
currentValue *= 100 * 100;
|
|
|
|
|
|
|
|
// write new value to groupobject
|
2019-06-02 01:39:08 +02:00
|
|
|
goCurrent.value(currentValue);
|
2019-05-13 22:31:45 +02:00
|
|
|
|
|
|
|
if (currentValue > maxValue)
|
|
|
|
{
|
|
|
|
maxValue = currentValue;
|
2019-06-02 01:39:08 +02:00
|
|
|
goMax.value(maxValue);
|
2019-05-13 22:31:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (currentValue < minValue)
|
|
|
|
{
|
|
|
|
minValue = currentValue;
|
2019-06-02 01:39:08 +02:00
|
|
|
goMin.value(minValue);
|
2019-05-13 22:31:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// callback from reset-GO
|
|
|
|
void resetCallback(GroupObject& go)
|
|
|
|
{
|
2019-06-12 00:01:21 +02:00
|
|
|
if (go.value())
|
2019-05-13 22:31:45 +02:00
|
|
|
{
|
|
|
|
maxValue = 0;
|
|
|
|
minValue = 10000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
2019-09-09 18:19:09 +02:00
|
|
|
Serial.begin(115200);
|
2019-09-09 20:10:56 +02:00
|
|
|
ArduinoPlatform::SerialDebug = &Serial;
|
2019-05-13 22:31:45 +02:00
|
|
|
|
|
|
|
randomSeed(millis());
|
2019-05-27 21:41:04 +02:00
|
|
|
|
2021-06-14 08:10:48 +02:00
|
|
|
#if MASK_VERSION != 0x07B0 && (defined ARDUINO_ARCH_ESP8266 || defined ARDUINO_ARCH_ESP32)
|
2019-05-27 21:41:04 +02:00
|
|
|
WiFiManager wifiManager;
|
2019-05-27 20:13:57 +02:00
|
|
|
wifiManager.autoConnect("knx-demo");
|
2019-05-27 21:41:04 +02:00
|
|
|
#endif
|
2019-05-13 22:31:45 +02:00
|
|
|
|
|
|
|
// read adress table, association table, groupobject table and parameters from eeprom
|
|
|
|
knx.readMemory();
|
|
|
|
|
|
|
|
// print values of parameters if device is already configured
|
|
|
|
if (knx.configured())
|
|
|
|
{
|
|
|
|
// register callback for reset GO
|
|
|
|
goReset.callback(resetCallback);
|
2019-09-02 22:55:23 +02:00
|
|
|
goReset.dataPointType(DPT_Trigger);
|
|
|
|
goCurrent.dataPointType(DPT_Value_Temp);
|
|
|
|
goMin.dataPointType(DPT_Value_Temp);
|
|
|
|
goMax.dataPointType(DPT_Value_Temp);
|
2019-05-27 21:41:04 +02:00
|
|
|
|
2019-09-09 18:19:09 +02:00
|
|
|
Serial.print("Timeout: ");
|
|
|
|
Serial.println(knx.paramByte(0));
|
|
|
|
Serial.print("Zykl. senden: ");
|
|
|
|
Serial.println(knx.paramByte(1));
|
|
|
|
Serial.print("Min/Max senden: ");
|
|
|
|
Serial.println(knx.paramByte(2));
|
|
|
|
Serial.print("Aenderung senden: ");
|
|
|
|
Serial.println(knx.paramByte(3));
|
|
|
|
Serial.print("Abgleich: ");
|
|
|
|
Serial.println(knx.paramByte(4));
|
2019-05-13 22:31:45 +02:00
|
|
|
}
|
2019-05-27 21:41:04 +02:00
|
|
|
|
2019-08-26 13:45:14 +02:00
|
|
|
// pin or GPIO the programming led is connected to. Default is LED_BUILTIN
|
2019-05-27 21:41:04 +02:00
|
|
|
// knx.ledPin(LED_BUILTIN);
|
|
|
|
// is the led active on HIGH or low? Default is LOW
|
|
|
|
// knx.ledPinActiveOn(HIGH);
|
|
|
|
// pin or GPIO programming button is connected to. Default is 0
|
|
|
|
// knx.buttonPin(0);
|
|
|
|
|
|
|
|
// start the framework.
|
2019-05-13 22:31:45 +02:00
|
|
|
knx.start();
|
|
|
|
}
|
|
|
|
|
2019-05-27 21:41:04 +02:00
|
|
|
void loop()
|
2019-05-13 22:31:45 +02:00
|
|
|
{
|
|
|
|
// 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
|
|
|
|
if (!knx.configured())
|
|
|
|
return;
|
|
|
|
|
|
|
|
measureTemp();
|
2019-09-09 18:19:09 +02:00
|
|
|
}
|