knx/examples/knx-hdc1008/knx-hdc1008.ino

99 lines
2.1 KiB
Arduino
Raw Normal View History

2019-01-07 21:15:57 +01:00
#include <HDC100X.h>
#include <knx.h>
2019-06-03 23:56:21 +02:00
#ifdef ARDUINO_ARCH_ESP8266
#include <WiFiManager.h>
2019-06-03 23:56:21 +02:00
#endif
2019-01-07 21:15:57 +01:00
HDC100X HDC1(0x43);
2019-05-15 21:25:04 +02:00
// create macros easy access to group objects
#define goTemperature knx.getGroupObject(1)
#define goHumidity knx.getGroupObject(2)
2019-01-07 21:15:57 +01:00
long lastsend = 0;
// Helper functions declarations
void errLeds(void);
uint8_t sendCounter = 0;
uint32_t cyclSend = 0;
// Entry point for the example
void setup(void)
{
SerialDBG.begin(115200);
delay(5000);
SerialDBG.println("start");
2019-06-03 23:56:21 +02:00
#ifdef ARDUINO_ARCH_ESP8266
WiFiManager wifiManager;
wifiManager.autoConnect("knx-hdc1008");
2019-06-03 23:56:21 +02:00
#endif
2019-01-07 21:15:57 +01:00
// Programming LED on digital pin D5
knx.ledPin(5);
// Programming button on digital pin D7
knx.buttonPin(7);
// read adress table, association table, groupobject table and parameters from eeprom
knx.readMemory();
HDC1.begin(HDC100X_TEMP_HUMI,HDC100X_14BIT,HDC100X_14BIT,DISABLE);
if (knx.configured())
{
2019-06-03 23:56:21 +02:00
2019-01-07 21:15:57 +01:00
cyclSend = knx.paramInt(0);
SerialDBG.print("Zykl. send:");
SerialDBG.println(cyclSend);
}
// start the framework.
knx.start();
String output = "Timestamp [ms], temperature [°C], relative humidity [%]";
SerialDBG.println(output);
}
// Function that is looped forever
void loop(void)
{
// 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;
long now = millis();
if ((now - lastsend) < 3000)
return;
lastsend = now;
float temp = HDC1.getTemp();
float humi = HDC1.getHumi();
String output = String(millis());
output += ", " + String(temp);
output += ", " + String(humi);
SerialDBG.println(output);
if (sendCounter++ == cyclSend)
{
sendCounter = 0;
2019-06-03 23:56:21 +02:00
goTemperature.value(temp);
goHumidity.value(humi);
2019-01-07 21:15:57 +01:00
}
}
void errLeds(void)
{
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
}