‪Black Box
BBThermostatDataRequest.cs
Go to the documentation of this file.
1 /*
2 * FILE : BBthermostatDataRequest.cs
3 * PROJECT : Black Box
4 * PROGRAMMER : BRIAN HINDS
5 * FIRST VERSION : 1.0.0.0
6 * DESCRIPTION : This library file manage the data request to the thermostat.
7 */
8 
11 using Newtonsoft.Json;
12 using System;
13 
15 {
17  {
18  private static string ‪BBThermostatData;
19  private static string ‪BBThermostatAllStat;
20  private static string ‪BBThermostatHumidity;
21 
25  private static void ‪GetBBThermostatAllData()
26  {
29 
30  // Current temperature
31  ‪BBThermostatData += ‪TempConvertor(buffer.temp) + ",";
32 
33  // Temporary target heat set point
34  ‪BBThermostatData += ‪TempConvertor(buffer.t_heat) + ",";
35 
36  // Temporary target cool set point
37  ‪BBThermostatData += ‪TempConvertor(buffer.t_cool) + ",";
38 
39  //Thermostat operation mode
40  if (buffer.tmode.ToString() == "0")
41  {
42  ‪BBThermostatData += "OFF,";
43  }
44  if (buffer.tmode.ToString() == "1")
45  {
46  ‪BBThermostatData += "HEAT,";
47  }
48  if (buffer.tmode.ToString() == "2")
49  {
50  ‪BBThermostatData += "COOL,";
51  }
52  if (buffer.tmode.ToString() == "3")
53  {
54  ‪BBThermostatData += "AUTO,";
55  }
56 
57  //Thermostat fan operation mode
58  if (buffer.fmode.ToString() == "0")
59  {
60  ‪BBThermostatData += "AUTO,";
61  }
62  if (buffer.fmode.ToString() == "1")
63  {
64  ‪BBThermostatData += "AUTO/CIRCULATE,";
65  }
66  if (buffer.fmode.ToString() == "2")
67  {
68  ‪BBThermostatData += "ON,";
69  }
70 
71  //Thermostat target temperature hold status
72  if (buffer.hold.ToString() == "0")
73  {
74  ‪BBThermostatData += "DISABLE,";
75  }
76  if (buffer.hold.ToString() == "1")
77  {
78  ‪BBThermostatData += "ENABLE,";
79  }
80 
81  //Thermostat HVAC Operation state
82  if (buffer.tstate.ToString() == "0")
83  {
84  ‪BBThermostatData += "OFF,";
85  }
86  if (buffer.tstate.ToString() == "1")
87  {
88  ‪BBThermostatData += "HEAT,";
89  }
90  if (buffer.tstate.ToString() == "2")
91  {
92  ‪BBThermostatData += "COOL,";
93  }
94 
95  //Thermostat current Operation target
96  if (buffer.ttarget.ToString() == "0")
97  {
98  ‪BBThermostatData += "OFF,";
99  }
100  if (buffer.ttarget.ToString() == "1")
101  {
102  ‪BBThermostatData += "HEAT,";
103  }
104  if (buffer.ttarget.ToString() == "2")
105  {
106  ‪BBThermostatData += "COOL,";
107  }
108 
109  //Thermostat operation mode
110  if (buffer.program_mode.ToString() == "0")
111  {
112  ‪BBThermostatData += "Program A,";
113  }
114  if (buffer.program_mode.ToString() == "1")
115  {
116  ‪BBThermostatData += "Program B,";
117  }
118  if (buffer.program_mode.ToString() == "2")
119  {
120  ‪BBThermostatData += "Vacation,";
121  }
122  if (buffer.program_mode.ToString() == "3")
123  {
124  ‪BBThermostatData += "Holiday,";
125  }
126 
127  //Thermostat fan operation status
128  if (buffer.fstate.ToString() == "0")
129  {
130  ‪BBThermostatData += "OFF,";
131  }
132  if (buffer.fstate.ToString() == "1")
133  {
134  ‪BBThermostatData += "ON,";
135  }
136 
137  // Current date and time the data was recorded
138  ‪BBThermostatData += DateTime.Now.ToString("HH:mm:ss") + "," + DateTime.Now.ToString("yyyy-MM-dd");
139  }
140 
144  private static void ‪GetBBThermostatHumidtyData()
145  {
148  ‪BBThermostatData += buffer.humidity.ToString() + ",";
149  }
150 
156  private static string ‪TempConvertor(float value)
157  {
158  return Convert.ToString(((int)value - 32) * 5 / 9);
159  }
160 
164  public static void ‪BBThermosataCheck()
165  {
166  try
167  {
171  Console.WriteLine(‪BBThermostatData);
172  Console.WriteLine(Environment.NewLine);
173  ‪BBThermostatData = "";
174  }
175  catch (Exception ex)
176  {
177  // Set operation status to false
179  ‪BBSensorErrorLog.‪SaveErrorData(ex.Message.ToString());
180  }
181  }
182  }
183 }
‪static string BBThermostatRequestB()
‪this method retrieve the humidity from the thermostat
‪static string BBThermostatRequestA()
‪this method retrieve the full status of the thermostat
‪static void SaveErrorData(string error)
‪Log all the error that occurs in the program
‪static void BBThermosataCheck()
‪Get thermostat data and encrypt
‪static void EncryptData(string SensorData)
‪This method encrypts the thermostat data
‪static void GetBBThermostatAllData()
‪This method request and parse the thermostat stat data
‪static void GetBBThermostatHumidtyData()
‪This method request and parse the thermostat humidity data
‪static string TempConvertor(float value)
‪This method converts the temperature from imperial to metric