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