source: trunk/Arduino/projects/OT_slave/OT_slave.ino @ 4

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

Prototyp for virtual OT-Slave (OT_V2R2_Slave)

File size: 1.7 KB
Line 
1#include <opentherm.h>
2
3#define THERMOSTAT_IN 2
4#define THERMOSTAT_OUT 4
5
6class OT_V2R2_Slave {
7
8protected:
9  static OpenthermData message;
10 
11
12public:
13  OT_V2R2_Slave ();
14
15  virtual void  Setup ();
16  virtual void  Loop ();
17
18private:
19  static void ListenAfterResponse ();
20
21};
22
23static OpenthermData  OT_V2R2_Slave::message;
24
25OT_V2R2_Slave::OT_V2R2_Slave ()
26{
27}
28
29void  OT_V2R2_Slave::Setup ()
30{
31  pinMode(THERMOSTAT_IN, INPUT);
32  digitalWrite(THERMOSTAT_OUT, HIGH);
33  pinMode(THERMOSTAT_OUT, OUTPUT); // low output = high current, high output = low current
34 
35}
36
37void  OT_V2R2_Slave::Loop ()
38{
39  if (OPENTHERM::getMessage(message)) {
40    Serial.print("-> ");
41    OPENTHERM::printToSerial(message);
42    Serial.println();
43    delay(100); // Opentherm defines delay between request and response
44    message.type = OT_MSGTYPE_UNKNOWN_DATAID; // construct fake response
45    message.valueHB = 0;
46    message.valueLB = 0;
47    OPENTHERM::send(THERMOSTAT_OUT, message, OT_V2R2_Slave::ListenAfterResponse); // send some response and wait for antoher request from thermostat set by callback
48  }
49  else if (OPENTHERM::isSent() || OPENTHERM::isIdle() || OPENTHERM::isError()) { // wait for request from thermostat
50    OPENTHERM::listen(THERMOSTAT_IN, -1);
51  }
52}
53
54void  OT_V2R2_Slave::ListenAfterResponse()
55{
56  Serial.print("<- ");
57  OPENTHERM::printToSerial(message);
58  Serial.println();
59  Serial.println();
60  OPENTHERM::listen(THERMOSTAT_IN, -1);
61}
62
63OT_V2R2_Slave boiler;
64
65void setup()
66{
67  boiler.Setup();
68  Serial.begin(19200);
69}
70
71/**
72 * Loop will act as boiler (slave) connected to Opentherm thermostat.
73 * It will wait for requests from thermostat and response with unknown data id as a fake response.
74 */
75void loop()
76{
77  boiler.Loop();
78}
Note: See TracBrowser for help on using the repository browser.