Skip to content

Commit cc90c54

Browse files
committed
Added Monitor and Slave mode support
Added examples: OpenThermMaster_Demo.ino, OpenThermMonitor_Demo.ino, OpenThermSlave_Demo.ino isCentralHeatingEnabled, isHotWaterEnabled, isCoolingEnabled renamed to isCentralHeatingActive, isHotWaterActive, isCoolingActive
1 parent 425e00b commit cc90c54

File tree

6 files changed

+252
-110
lines changed

6 files changed

+252
-110
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
OpenTherm Master Communication Example
3+
By: Ihor Melnyk
4+
Date: January 19th, 2018
5+
6+
Uses the OpenTherm library to get/set boiler status and water temperature
7+
Open serial monitor at 115200 baud to see output.
8+
9+
Hardware Connections (OpenTherm Adapter (http://ihormelnyk.com/pages/OpenTherm) to Arduino/ESP8266):
10+
-OT1/OT2 = Boiler X1/X2
11+
-VCC = 5V or 3.3V
12+
-GND = GND
13+
-IN = Arduino (3) / ESP8266 (5) Output Pin
14+
-OUT = Arduino (2) / ESP8266 (4) Input Pin
15+
16+
Controller(Arduino/ESP8266) input pin should support interrupts.
17+
Arduino digital pins usable for interrupts: Uno, Nano, Mini: 2,3; Mega: 2, 3, 18, 19, 20, 21
18+
ESP8266: Interrupts may be attached to any GPIO pin except GPIO16,
19+
but since GPIO6-GPIO11 are typically used to interface with the flash memory ICs on most esp8266 modules, applying interrupts to these pins are likely to cause problems
20+
*/
21+
22+
23+
#include <Arduino.h>
24+
#include <OpenTherm.h>
25+
26+
const int inPin = 2; //4 for ESP8266
27+
const int outPin = 3; //5 dor ESP8266
28+
OpenTherm ot(inPin, outPin);
29+
30+
void handleInterrupt() {
31+
ot.handleInterrupt();
32+
}
33+
34+
void setup()
35+
{
36+
Serial.begin(9600);
37+
Serial.println("Start");
38+
39+
ot.begin(handleInterrupt);
40+
}
41+
42+
void loop()
43+
{
44+
//Set/Get Boiler Status
45+
bool enableCentralHeating = true;
46+
bool enableHotWater = true;
47+
bool enableCooling = false;
48+
unsigned long response = ot.setBoilerStatus(enableCentralHeating, enableHotWater, enableCooling);
49+
OpenThermResponseStatus responseStatus = ot.getLastResponseStatus();
50+
if (responseStatus == OpenThermResponseStatus::SUCCESS) {
51+
Serial.println("Central Heating: " + String(ot.isCentralHeatingActive(response) ? "on" : "off"));
52+
Serial.println("Hot Water: " + String(ot.isHotWaterActive(response) ? "on" : "off"));
53+
Serial.println("Flame: " + String(ot.isFlameOn(response) ? "on" : "off"));
54+
}
55+
if (responseStatus == OpenThermResponseStatus::NONE) {
56+
Serial.println("Error: OpenTherm is not initialized");
57+
}
58+
else if (responseStatus == OpenThermResponseStatus::INVALID) {
59+
Serial.println("Error: Invalid response " + String(response, HEX));
60+
}
61+
else if (responseStatus == OpenThermResponseStatus::TIMEOUT) {
62+
Serial.println("Error: Response timeout");
63+
}
64+
65+
//Set Boiler Temperature to 64 degrees C
66+
ot.setBoilerTemperature(64);
67+
68+
//Get Boiler Temperature
69+
float temperature = ot.getBoilerTemperature();
70+
Serial.println("Boiler temperature is " + String(temperature) + " degrees C");
71+
72+
Serial.println();
73+
delay(1000);
74+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
OpenTherm Monitor Example
3+
By: Ihor Melnyk
4+
Date: May 1st, 2019
5+
*/
6+
7+
8+
#include <Arduino.h>
9+
#include <OpenTherm.h>
10+
11+
const int mInPin = 4; //ESP8266
12+
const int mOutPin = 5; //ESP8266
13+
14+
const int sInPin = 12; //ESP8266
15+
const int sOutPin = 13; //ESP8266
16+
17+
OpenTherm mOT(mInPin, mOutPin);
18+
OpenTherm sOT(sInPin, sOutPin, true);
19+
20+
void mHandleInterrupt() {
21+
mOT.handleInterrupt();
22+
}
23+
24+
void sHandleInterrupt() {
25+
sOT.handleInterrupt();
26+
}
27+
28+
void processRequest(unsigned long request, OpenThermResponseStatus status) {
29+
Serial.println("T" + String(request, HEX)); //master/thermostat request
30+
unsigned long response = mOT.sendRequest(request);
31+
if (response) {
32+
Serial.println("B" + String(response, HEX)); //slave/boiler response
33+
sOT.sendResponse(response);
34+
}
35+
}
36+
37+
void setup()
38+
{
39+
Serial.begin(9600); //9600 supported by OpenTherm Monitor App
40+
mOT.begin(mHandleInterrupt);
41+
sOT.begin(sHandleInterrupt, processRequest);
42+
}
43+
44+
void loop()
45+
{
46+
sOT.process();
47+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
OpenTherm Slave Example
3+
By: Ihor Melnyk
4+
Date: May 1st, 2019
5+
*/
6+
7+
#include <Arduino.h>
8+
#include <OpenTherm.h>
9+
10+
const int inPin = 12; //ESP8266
11+
const int outPin = 13; //ESP8266
12+
OpenTherm ot(inPin, outPin, true);
13+
14+
void handleInterrupt() {
15+
ot.handleInterrupt();
16+
}
17+
18+
void processRequest(unsigned long request, OpenThermResponseStatus status) {
19+
//receive request
20+
Serial.println("T" + String(request, HEX)); //master/thermostat request
21+
22+
//build UNKNOWN-DATAID response
23+
unsigned long response = ot.buildResponse(OpenThermMessageType::UNKNOWN_DATA_ID, ot.getDataID(request), 0);
24+
25+
//send response
26+
ot.sendResponse(response);
27+
Serial.println("B" + String(response, HEX)); //slave/boiler response
28+
}
29+
30+
void setup()
31+
{
32+
Serial.begin(9600);
33+
Serial.println("Start");
34+
35+
ot.begin(handleInterrupt, processRequest);
36+
}
37+
38+
39+
void loop()
40+
{
41+
ot.process();
42+
}

examples/OpenTherm_Demo/OpenTherm_Demo.ino

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)