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

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

Fixed: cbPostReq will be called\nChanged: Output format

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