source: trunk/resources/arduino-opentherm/examples/slave/slave.ino @ 9

Last change on this file since 9 was 1, checked in by markus, 8 years ago

Initial setup

File size: 1.3 KB
Line 
1#include <opentherm.h>
2
3#define THERMOSTAT_IN 2
4#define THERMOSTAT_OUT 4
5
6OpenthermData message;
7
8void setup() {
9  pinMode(THERMOSTAT_IN, INPUT);
10  digitalWrite(THERMOSTAT_OUT, HIGH);
11  pinMode(THERMOSTAT_OUT, OUTPUT); // low output = high current, high output = low current
12
13  Serial.begin(19200);
14}
15
16/**
17 * Loop will act as boiler (slave) connected to Opentherm thermostat.
18 * It will wait for requests from thermostat and response with unknown data id as a fake response.
19 */
20void loop() {
21  if (OPENTHERM::getMessage(message)) {
22    Serial.print("-> ");
23    OPENTHERM::printToSerial(message);
24    Serial.println();
25    delay(100); // Opentherm defines delay between request and response
26    message.type = OT_MSGTYPE_UNKNOWN_DATAID; // construct fake response
27    message.valueHB = 0;
28    message.valueLB = 0;
29    OPENTHERM::send(THERMOSTAT_OUT, message, listenAfterResponse); // send some response and wait for antoher request from thermostat set by callback
30  }
31  else if (OPENTHERM::isSent() || OPENTHERM::isIdle() || OPENTHERM::isError()) { // wait for request from thermostat
32    OPENTHERM::listen(THERMOSTAT_IN, -1);
33  }
34}
35
36void listenAfterResponse() {
37  Serial.print("<- ");
38  OPENTHERM::printToSerial(message);
39  Serial.println();
40  Serial.println();
41  OPENTHERM::listen(THERMOSTAT_IN, -1);
42}
Note: See TracBrowser for help on using the repository browser.