‪Black Box
BBThermostatConnect.cs
Go to the documentation of this file.
1 /*
2 * FILE : BBthermostatConnect.cs
3 * PROJECT : Black Box
4 * PROGRAMMER : BRIAN HINDS
5 * DATE : March 20, 2019
6 * FIRST VERSION : 1.0.0.0
7 * DESCRIPTION : This library file manage the connection protocol for the thermostat.
8 */
9 
12 using System.IO;
13 using System.Net;
14 
16 {
18  {
22  {
23  GET
24  }
25 
28  private static ‪BBThermostatProtocol ‪BBThermostatMethod { get; set; }
29 
32  public static string ‪results;
33 
38  public static string ‪BBThermostatRequestA()
39  {
41 
42  HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://192.168.137.18/tstat/");
43 
44  request.Method = ‪BBThermostatMethod.ToString();
45 
46  using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
47  {
48  // Set operation status to true
50 
51  if (response.StatusCode != HttpStatusCode.OK)
52  {
53  ‪BBSensorErrorLog.‪SaveErrorData("Thermostat unable to get request from 192.168.137.18//tstat//");
54  // Set operation status to false
56  }
57 
58  using (Stream BBThermostatRequestStream = response.GetResponseStream())
59  {
60  if (BBThermostatRequestStream != null)
61  {
62  using (StreamReader reader = new StreamReader(BBThermostatRequestStream))
63  {
64  ‪results = reader.ReadToEnd();
65  }
66  }
67  }
68  }
69 
70  return ‪results;
71  }
72 
77  public static string ‪BBThermostatRequestB()
78  {
80 
81  HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://192.168.137.18/tstat/humidity");
82  request.Method = ‪BBThermostatMethod.ToString();
83 
84  using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
85  {
86  // Set operation status to true
88 
89  if (response.StatusCode != HttpStatusCode.OK)
90  {
91  ‪BBSensorErrorLog.‪SaveErrorData("Thermostat unable to get request from 192.168.137.18//humidity//");
92 
93  // Set operation status to true
95  }
96 
97  using (Stream BBThermostatRequestStream = response.GetResponseStream())
98  {
99  if (BBThermostatRequestStream != null)
100  {
101  using (StreamReader reader = new StreamReader(BBThermostatRequestStream))
102  {
103  ‪results = reader.ReadToEnd();
104  }
105  }
106  }
107  }
108 
109  return ‪results;
110  }
111 
116  public static string ‪BBThermostatType()
117  {
119 
120  HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://192.168.137.18/tstat/model");
121  request.Method = ‪BBThermostatMethod.ToString();
122 
123  using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
124  {
125  // Set operation status to true
127 
128  if (response.StatusCode != HttpStatusCode.OK)
129  {
130  ‪BBSensorErrorLog.‪SaveErrorData("Thermostat unable to get request from 192.168.137.18//tstat//model");
131  // Set operation status to false
133  }
134 
135  using (Stream BBThermostatRequestStream = response.GetResponseStream())
136  {
137  if (BBThermostatRequestStream != null)
138  {
139  using (StreamReader reader = new StreamReader(BBThermostatRequestStream))
140  {
141  ‪results = reader.ReadToEnd();
142  }
143  }
144  }
145  }
146 
147  return ‪results;
148  }
149  }
150 }
‪static string BBThermostatRequestB()
‪this method retrieve the humidity from the thermostat
‪static BBThermostatProtocol BBThermostatMethod
‪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 string BBThermostatType()
‪This method retrieve thermostat model