Changeset 7 for trunk/Arduino/projects
- Timestamp:
- Jun 28, 2019, 1:07:05 AM (7 years ago)
- Location:
- trunk/Arduino/projects
- Files:
-
- 2 added
- 1 deleted
- 2 edited
-
OT_boiler/OT_boiler.ino (modified) (6 diffs)
-
OT_slave/OT_slave.ino (modified) (1 diff)
-
OT_slave/trace.2019062501.txt (deleted)
-
OT_slave/trace.r5.2019062501.txt (added)
-
OT_slave/trace.r6.2019062502.txt (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Arduino/projects/OT_boiler/OT_boiler.ino
r3 r7 1 1 #include <SPI.h> 2 2 #include <Ethernet.h> 3 #include <opentherm.h> 4 5 #define THERMOSTAT_IN 2 6 #define THERMOSTAT_OUT 4 3 #include <ot_slave_2.h> 7 4 8 5 byte mac[] = { 0x02, 0xDE, 0xAD, 0xDE, 0xAD, 0x01 }; … … 12 9 volatile bool _connected = false; 13 10 14 O penthermData message;11 OT_V2R2_Slave boiler; 15 12 16 13 EthernetClient client; … … 18 15 void setup() 19 16 { 20 pinMode(THERMOSTAT_IN, INPUT); 21 digitalWrite(THERMOSTAT_OUT, HIGH); 22 pinMode(THERMOSTAT_OUT, OUTPUT); // low output = high current, high output = low current 17 boiler.Setup(); 23 18 24 19 // Console … … 51 46 void loop() 52 47 { 48 /* 53 49 Serial.print("["); 54 50 Serial.print(++loops); … … 56 52 Serial.print(state,HEX); 57 53 Serial.println("]"); 54 */ 58 55 maintainEthernet(); 59 if (OPENTHERM::getMessage(message)) { 60 Serial.print("-> "); 61 OPENTHERM::printToSerial(message); 62 Serial.println(); 63 Sent_OT_Data(message); 64 65 delay(100); // Opentherm defines delay between request and response 66 message.type = OT_MSGTYPE_UNKNOWN_DATAID; // construct fake response 67 message.valueHB = 0; 68 message.valueLB = 0; 69 OPENTHERM::send(THERMOSTAT_OUT, message, listenAfterResponse); // send some response and wait for antoher request from thermostat set by callback 70 } else { 71 if (OPENTHERM::isSent() || OPENTHERM::isIdle() || OPENTHERM::isError()) { // wait for request from thermostat 72 OPENTHERM::listen(THERMOSTAT_IN, -1); 73 } 74 OpenthermData dummy; 75 dummy.type = OT_MSGTYPE_UNKNOWN_DATAID; 76 dummy.id = OT_MSGID_STATUS; 77 dummy.valueHB = (loops >> 8) & 0xFF; 78 dummy.valueLB = loops & 0xFF; 79 Sent_OT_Data(dummy); 80 } 56 boiler.Loop(); 57 /* 81 58 delay(1000); 59 */ 82 60 } 83 61 … … 132 110 } 133 111 } 134 135 void listenAfterResponse () {136 Serial.print("<- ");137 OPENTHERM::printToSerial(message);138 Serial.println();139 Serial.println();140 OPENTHERM::listen(THERMOSTAT_IN, -1);141 } -
trunk/Arduino/projects/OT_slave/OT_slave.ino
r6 r7 1 1 #include <opentherm.h> 2 3 #define THERMOSTAT_IN 2 4 #define THERMOSTAT_OUT 4 5 6 class OT_V2R2_Slave { 7 8 protected: 9 static OpenthermData message; 10 bool chEnable; 11 bool chActive; 12 float chTemperature; 13 bool dhwEnable; 14 bool dhwActive; 15 float dhwTemperature; 16 17 18 public: 19 OT_V2R2_Slave (); 20 21 virtual void Setup (); 22 virtual void Loop (); 23 24 virtual void HandleRequest (OpenthermData& message); 25 virtual void ConfigReq (OpenthermData& message); 26 virtual void StatusReq (OpenthermData& message); 27 virtual void FaultReq (OpenthermData& message); 28 29 virtual bool CH_Enable (bool enable = true); 30 virtual bool CH_Disable (); 31 virtual void CH_Temperature (float); 32 virtual bool DHW_Enable (bool enable = true); 33 virtual bool DHW_Disable (); 34 virtual void DHW_Temperature (float); 35 36 private: 37 static void ListenAfterResponse (); 38 39 }; 40 41 OpenthermData OT_V2R2_Slave::message; 42 43 OT_V2R2_Slave::OT_V2R2_Slave () 44 : 45 chEnable(false), 46 chActive(false), 47 chTemperature(0), 48 dhwEnable(false), 49 dhwActive(false), 50 dhwTemperature(0) 51 { 52 } 53 54 void OT_V2R2_Slave::Setup () 55 { 56 pinMode(THERMOSTAT_IN, INPUT); 57 digitalWrite(THERMOSTAT_OUT, HIGH); 58 pinMode(THERMOSTAT_OUT, OUTPUT); // low output = high current, high output = low current 59 } 60 61 /** 62 * Loop will act as boiler (slave) connected to Opentherm thermostat. 63 * It will wait for requests from thermostat and response with unknown data id as a fake response. 64 */ 65 void OT_V2R2_Slave::Loop () 66 { 67 if (OPENTHERM::getMessage(message)) { 68 HandleRequest(message); 69 } else if (OPENTHERM::isSent() || OPENTHERM::isIdle() || OPENTHERM::isError()) { // wait for request from thermostat 70 OPENTHERM::listen(THERMOSTAT_IN, -1); 71 } 72 } 73 74 void OT_V2R2_Slave::HandleRequest (OpenthermData& message) 75 { 76 Serial.print("-> "); 77 OPENTHERM::printToSerial(message); 78 Serial.println(); 79 delay(100); // Opentherm defines delay between request and response 80 switch (message.id) { 81 case OT_MSGID_STATUS: // 0 (Master and slave status flags) [M:ReadAck] 82 StatusReq(message); 83 break; 84 case OT_MSGID_CH_SETPOINT: // 1 (Control setpoint ie CH water temp. setpoint) [M:WriteAck] 85 message.type = OT_MSGTYPE_WRITE_ACK; 86 CH_Temperature(message.f88()); 87 break; 88 case OT_MSGID_SLAVE_CONFIG: // 3 (Slave configuration flags) [M:ReadAck] 89 ConfigReq(message); 90 break; 91 case OT_MSGID_FAULT_FLAGS: // 5 (Application-specific fault flags / OEM fault code) 92 FaultReq(message); 93 break; 94 case 14: // 14 (Maximum relative modulation level setting) [M:WriteAck] 95 message.type = OT_MSGTYPE_WRITE_ACK; 96 break; 97 case OT_MSGID_MODULATION_LEVEL: // 17 (Relative modulation level) [M:ReadAck|DataInvalid] 98 message.type = OT_MSGTYPE_DATA_INVALID; 99 break; 100 case OT_MSGID_FEED_TEMP: // 25 (Boiler temperature) [M:ReadAck|DataInvalid] 101 message.type = OT_MSGTYPE_DATA_INVALID; 102 break; 103 case OT_MSGID_DHW_SETPOINT: // 56 (DHW setpoint) 104 if (message.type == OT_MSGTYPE_READ_DATA) { 105 message.type = OT_MSGTYPE_READ_ACK; 106 message.f88(dhwTemperature); 107 break; 108 } else if (message.type == OT_MSGTYPE_WRITE_DATA) { 109 message.type = OT_MSGTYPE_WRITE_ACK; 110 DHW_Temperature(message.f88()); 111 } else { 112 message.type = OT_MSGTYPE_UNKNOWN_DATAID; // construct fake response 113 } 114 break; 115 case OT_MSGID_VERSION_SLAVE: // 127 (Slave product version number and type) 116 message.type = OT_MSGTYPE_READ_ACK; 117 message.valueHB = 0; // product type 118 message.valueLB = 0; // product version 119 break; 120 default: 121 message.type = OT_MSGTYPE_UNKNOWN_DATAID; // construct fake response 122 message.valueHB = 0; 123 message.valueLB = 0; 124 } 125 OPENTHERM::send(THERMOSTAT_OUT, message, OT_V2R2_Slave::ListenAfterResponse); // send some response and wait for antoher request from thermostat set by callback 126 } 127 128 void OT_V2R2_Slave::ConfigReq (OpenthermData& message) 129 { 130 message.type = OT_MSGTYPE_READ_ACK; 131 message.valueHB = 0; // 0x11; // slave configuration: 132 message.valueLB = 0; // Slave MemberID code 133 } 134 135 void OT_V2R2_Slave::StatusReq (OpenthermData& message) 136 { 137 message.type = OT_MSGTYPE_READ_ACK; 138 CH_Enable(message.valueHB & 0x01); 139 DHW_Enable(message.valueHB & 0x02); 140 message.valueLB = 0; // Slave status 141 if (chActive) { 142 message.valueLB |= 0x02; 143 } else { 144 message.valueLB &= ~0x02; 145 } 146 if (dhwActive) { 147 message.valueLB |= 0x04; 148 } else { 149 message.valueLB &= ~0x04; 150 } 151 } 152 153 void OT_V2R2_Slave::FaultReq (OpenthermData& message) 154 { 155 message.type = OT_MSGTYPE_READ_ACK; 156 message.valueHB = 0; // Application-specific fault flags 157 message.valueLB = 0; // OEM fault code 158 } 159 160 bool OT_V2R2_Slave::CH_Enable (bool enable) 161 { 162 chEnable = enable; 163 chActive = enable; 164 return chEnable; 165 } 166 167 bool OT_V2R2_Slave::CH_Disable () 168 { 169 chEnable = false; 170 chActive = false; 171 return chEnable; 172 } 173 174 void OT_V2R2_Slave::CH_Temperature (float temp) 175 { 176 chTemperature = temp; 177 } 178 179 bool OT_V2R2_Slave::DHW_Enable (bool enable) 180 { 181 dhwEnable = enable; 182 dhwActive = enable; 183 return dhwEnable; 184 } 185 186 bool OT_V2R2_Slave::DHW_Disable () 187 { 188 dhwEnable = false; 189 dhwActive = false; 190 return dhwEnable; 191 } 192 193 void OT_V2R2_Slave::DHW_Temperature (float temp) 194 { 195 dhwTemperature = temp; 196 } 197 198 void OT_V2R2_Slave::ListenAfterResponse () 199 { 200 Serial.print("<- "); 201 OPENTHERM::printToSerial(message); 202 Serial.println(); 203 Serial.println(); 204 OPENTHERM::listen(THERMOSTAT_IN, -1); 205 } 2 #include <ot_slave_2.h> 206 3 207 4 OT_V2R2_Slave boiler;
Note: See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/trac/Paradigma/chrome/site/paradigma.png)