knx/examples/knx-demo/knx-demo.ino

100 lines
2.4 KiB
Arduino
Raw Normal View History

2018-08-16 23:58:57 +02:00
#include <knx_esp.h>
2018-04-09 23:58:35 +02:00
2018-04-10 00:16:34 +02:00
// declare array of all groupobjects with their sizes in byte
GroupObject groupObjects[]
{
GroupObject(2),
GroupObject(2),
GroupObject(2),
GroupObject(1)
};
// create named references for easy access to group objects
GroupObject& goCurrent = groupObjects[0];
GroupObject& goMax = groupObjects[1];
GroupObject& goMin = groupObjects[2];
GroupObject& goReset = groupObjects[3];
float currentValue = 0;
float maxValue = 0;
float minValue = RAND_MAX;
long lastsend = 0;
void measureTemp()
{
long now = millis();
if ((now - lastsend) < 2000)
return;
2018-04-09 23:58:35 +02:00
2018-04-10 00:16:34 +02:00
lastsend = now;
int r = rand();
currentValue = (r * 1.0) / (RAND_MAX * 1.0);
currentValue *= 100 * 100;
// write new value to groupobject
goCurrent.objectWriteFloatDpt9(currentValue);
2018-04-10 00:16:34 +02:00
if (currentValue > maxValue)
{
maxValue = currentValue;
goMax.objectWriteFloatDpt9(maxValue);
2018-04-10 00:16:34 +02:00
}
if (currentValue < minValue)
{
minValue = currentValue;
goMin.objectWriteFloatDpt9(minValue);
2018-04-10 00:16:34 +02:00
}
}
// callback from reset-GO
void resetCallback(GroupObject& go)
{
if (go.objectReadBool())
{
maxValue = 0;
minValue = 10000;
}
2018-04-09 23:58:35 +02:00
}
void setup()
{
Serial.begin(115200);
2018-04-10 00:16:34 +02:00
randomSeed(millis());
// register group objects
knx.registerGroupObjects(groupObjects, 4);
// read adress table, association table, groupobject table and parameters from eeprom
knx.readMemory();
// register callback for reset GO
goReset.updateHandler = resetCallback;
// print values of parameters if device is already configured
if (knx.configured())
{
2018-11-07 00:32:36 +01:00
SerialDBG.print("Timeout: "); SerialDBG.println(knx.paramByte(0));
SerialDBG.print("Zykl. senden: "); SerialDBG.println(knx.paramByte(1));
SerialDBG.print("Min/Max senden: "); SerialDBG.println(knx.paramByte(2));
SerialDBG.print("Aenderung senden: "); SerialDBG.println(knx.paramByte(3));
SerialDBG.print("Abgleich: "); SerialDBG.println(knx.paramByte(4));
2018-04-09 23:58:35 +02:00
}
2018-04-10 00:16:34 +02:00
// start the framework. Will get wifi first.
2018-04-09 23:58:35 +02:00
knx.start();
}
void loop()
{
2018-04-10 00:16:34 +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;
2018-04-09 23:58:35 +02:00
measureTemp();
}