source: trunk/Arduino/testing/slave/slave.ino @ 22

Last change on this file since 22 was 3, checked in by markus, 7 years ago

Setup project structure

File size: 1.3 KB
RevLine 
[3]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  Serial.print("STARTING...");
22  if (OPENTHERM::getMessage(message)) {
23    Serial.print("-> ");
24    OPENTHERM::printToSerial(message);
25    Serial.println();
26    delay(100); // Opentherm defines delay between request and response
27    message.type = OT_MSGTYPE_UNKNOWN_DATAID; // construct fake response
28    message.valueHB = 0;
29    message.valueLB = 0;
30    OPENTHERM::send(THERMOSTAT_OUT, message, listenAfterResponse); // send some response and wait for antoher request from thermostat set by callback
31  }
32  else if (OPENTHERM::isSent() || OPENTHERM::isIdle() || OPENTHERM::isError()) { // wait for request from thermostat
33    OPENTHERM::listen(THERMOSTAT_IN, -1);
34  }
35}
36
37void listenAfterResponse() {
38  Serial.print("<- ");
39  OPENTHERM::printToSerial(message);
40  Serial.println();
41  Serial.println();
42  OPENTHERM::listen(THERMOSTAT_IN, -1);
43}
Note: See TracBrowser for help on using the repository browser.