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

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

Update: OT_Data conversion

File size: 2.6 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  // Check for Ethernet hardware present
[11]33/*  Not needed anymore
[8]34  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
[10]35    CONSOLE(println("Ethernet shield was not found.  Sorry, can't run without hardware. :("));
[8]36    while (true) {
37      delay(1); // do nothing, no point running without Ethernet hardware
38    }
39  }
40*/
41}
42
43void loop()
44{
[9]45  loops++;
[8]46/*
47  Serial.print("[");
[9]48  Serial.print(loops);
[8]49  Serial.print("|");
50  Serial.print(state,HEX);
51  Serial.println("]");
52*/
53  maintainEthernet();
[11]54  boiler.maintain();
[8]55/*
56  delay(1000);
57*/
58}
59
60void maintainEthernet ()
61{
62  byte rc = Ethernet.maintain();
63  switch (rc) {
64    case 1: // renew failed
[10]65      CONSOLE(println("Ethernet: renew failed!"));
[8]66      break;
67    case 2: // renew success
[10]68      CONSOLE(println("Ethernet: renew success!"));
[8]69      break;
70    case 3: // rebind failed
[10]71      CONSOLE(println("Ethernet: rebind failed!"));
[8]72      break;
73    case 4: // rebind success 
[10]74      CONSOLE(println("Ethernet: rebind success!"));
[8]75      break;
76  }
77  if (client.connected()) {
78    if (!_connected) {
79      _connected = true;
[10]80      CONSOLE(println("Ethernet: connected!")); 
[8]81    }
82  } else {
83    if (_connected) {
84      _connected = false;
[10]85      CONSOLE(println("Ethernet: connection lost!"));
[8]86    }
[10]87//    CONSOLE(println("Ethernet: restarting..."));
[8]88    client.stop();
[10]89//    CONSOLE(println("Ethernet: connecting..."));
[8]90    client.connect(server, 23456); 
91  }
92}
93
[11]94void    Sent_OT_Data (const OT_Action& data)
[8]95{
96  state = OPENTHERM::getMode();
[9]97  if (client.connected()) {
98    client.print("[");
99    client.print(loops);
100    client.print("|");
101    client.print(state,HEX);
102    client.print("]\t");
[11]103/*
[9]104    client.print(data.type,HEX);
105    client.print(":");
106    client.print(data.id,HEX);
107    client.print(":");
108    client.print(data.valueHB,HEX);
109    client.print(":");
110    client.print(data.valueLB,HEX);
[11]111*/
[12]112    client.print(data.GetRequestValue(),HEX);
[11]113    client.print("\t");
[12]114    client.print(data.GetResponseValue(),HEX);
[9]115    client.println("");
116  }
[8]117}
Note: See TracBrowser for help on using the repository browser.