/
thermona-opentherm.ino
61 lines (53 loc) · 1.51 KB
/
thermona-opentherm.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <opentherm.h>
// Wemos D1 R1
//#define BOILER_IN 5
//#define BOILER_OUT 14
// Wemos D1 R2
//#define BOILER_IN 5
//#define BOILER_OUT 0
// Arduino UNO
#define BOILER_IN 3
#define BOILER_OUT 5
// Wemos D1 R32
// #define BOILER_IN 25
// #define BOILER_OUT 16
OpenthermData message;
void setup() {
pinMode(BOILER_IN, INPUT);
digitalWrite(BOILER_IN, HIGH); // pull up
digitalWrite(BOILER_OUT, HIGH);
pinMode(BOILER_OUT, OUTPUT); // low output = high voltage, high output = low voltage
Serial.begin(115200);
}
/**
* Loop will act as thermostat (master) connected to Opentherm boiler.
* It will request slave configration from boiler every 100ms or so and waits for response from boiler.
*/
void loop() {
if (OPENTHERM::isIdle()) {
message.type = OT_MSGTYPE_READ_DATA;
message.id = OT_MSGID_SLAVE_CONFIG;
message.valueHB = 0;
message.valueLB = 0;
Serial.print(F("-> "));
OPENTHERM::printToSerial(message);
Serial.println();
OPENTHERM::send(BOILER_OUT, message); // send message to boiler
}
else if (OPENTHERM::isSent()) {
OPENTHERM::listen(BOILER_IN, 800); // wait for boiler to respond
}
else if (OPENTHERM::getMessage(message)) { // boiler responded
OPENTHERM::stop();
Serial.print(F("<- "));
OPENTHERM::printToSerial(message);
Serial.println();
Serial.println();
delay(100); // minimal delay before next communication
}
else if (OPENTHERM::isError()) {
OPENTHERM::stop();
Serial.println(F("<- Timeout"));
Serial.println();
}
}