source: trunk/Arduino/projects/OT_boiler/OT_boiler.ino @ 15

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

Simulation of T_Boiler and T_Ret

File size: 2.4 KB
Line 
1#include <SPI.h>
2#include <Ethernet.h>
3#include <OT_Slave.h>
4
5#define CONSOLE(cmd)  do { if (Serial) Serial.cmd; } while (0)
6
7void  Sent_OT_Data (const OT_Action& data);
8
9byte  mac[] = { 0x02, 0xDE, 0xAD, 0xDE, 0xAD, 0x01 };
10byte  server[] = { 192, 168, 0, 22 };
11volatile long  loops = 0;
12volatile long  state = 0;
13volatile bool  _connected = false;
14
15OT_Slave boiler;
16
17EthernetClient client;
18
19void setup()
20{
21  // Console
22  Serial.begin(19200);
23  CONSOLE(println("\nSystem starting..."));
24  // Setup OT
25  CONSOLE(print("OpenTherm.setup..."));
26  boiler.begin(Sent_OT_Data);
27  CONSOLE(println("done"));
28  // Setup Ethernet
29  CONSOLE(print("Ethernet.begin..."));
30  Ethernet.begin(mac);
31  CONSOLE(println("done"));
32}
33
34void loop()
35{
36  loops++;
37/*
38  Serial.print("[");
39  Serial.print(loops);
40  Serial.print("|");
41  Serial.print(state,HEX);
42  Serial.println("]");
43*/
44  maintainEthernet();
45  boiler.maintain();
46/*
47  delay(1000);
48*/
49}
50
51void maintainEthernet ()
52{
53  // Check for Ethernet hardware present
54  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
55    return;
56  }
57  byte rc = Ethernet.maintain();
58  switch (rc) {
59    case 1: // renew failed
60      CONSOLE(println("Ethernet: renew failed!"));
61      break;
62    case 2: // renew success
63      CONSOLE(println("Ethernet: renew success!"));
64      break;
65    case 3: // rebind failed
66      CONSOLE(println("Ethernet: rebind failed!"));
67      break;
68    case 4: // rebind success 
69      CONSOLE(println("Ethernet: rebind success!"));
70      break;
71  }
72  if (client.connected()) {
73    if (!_connected) {
74      _connected = true;
75      CONSOLE(println("Ethernet: connected!")); 
76    }
77  } else {
78    if (_connected) {
79      _connected = false;
80      CONSOLE(println("Ethernet: connection lost!"));
81    }
82//    CONSOLE(println("Ethernet: restarting..."));
83    client.stop();
84//    CONSOLE(println("Ethernet: connecting..."));
85    client.connect(server, 23456); 
86  }
87}
88
89void    Sent_OT_Data (const OT_Action& data)
90{
91  state = OPENTHERM::getMode();
92  if (client.connected()) {
93    client.print("[");
94    client.print(loops);
95    client.print("|");
96    client.print(state,HEX);
97    client.print("]\t");
98/*
99    client.print(data.type,HEX);
100    client.print(":");
101    client.print(data.id,HEX);
102    client.print(":");
103    client.print(data.valueHB,HEX);
104    client.print(":");
105    client.print(data.valueLB,HEX);
106*/
107    client.print(data.GetRequestValue(),HEX);
108    client.print("\t");
109    client.print(data.GetResponseValue(),HEX);
110    client.println("");
111  }
112}
Note: See TracBrowser for help on using the repository browser.