FACT++  1.0
void ConnectionPowerSwitch::ProcessAnswer ( )
inlineprivate

Definition at line 60 of file temperature.cc.

References Temperature::State::kConnected, Temperature::State::kValid, and temp.

61  {
62  if (fDebugRx)
63  {
64  Out() << "------------------------------------------------------" << endl;
65  Out() << fRdfData << endl;
66  Out() << "------------------------------------------------------" << endl;
67  }
68 
69  const size_t p1 = fRdfData.find("\r\n\r\n");
70  if (p1==string::npos)
71  {
72  Warn("HTTP header not found.");
73  PostClose(false);
74  return;
75  }
76 
77  fRdfData.erase(0, p1+4);
78 
79  vector<float> temp(3);
80  try
81  {
82  std::stringstream ss;
83  ss << fRdfData;
84 
85  pt::ptree tree;
86  pt::read_json(ss, tree);
87 
88  const pt::ptree sub2 = tree.get_child("sensor_values.").begin()->second;
89  const pt::ptree sub3 = sub2.get_child("values").begin()->second.begin()->second;
90 
91  temp[0] = sub3.get_child("v").get_value<float>();
92 
93  auto sub = sub3.get_child("st.").begin();
94 
95  temp[1] = sub++->second.get_value<float>();
96  temp[2] = sub->second.get_value<float>();
97  }
98  catch (std::exception const& e)
99  {
100  Warn("Parsing of JSON failed: "+string(e.what()));
101 
103 
104  PostClose(false);
105  return;
106  }
107 
108  fRdfData = "";
109 
110  Update(temp);
111 
112  ostringstream msg;
113  msg << "T=" << temp[0] << "°C"
114  << " Tmin=" << temp[1] << "°C"
115  << " Tmax=" << temp[2] << "°C";
116  Message(msg);
117 
119 
120  fLastReport = Time();
121  PostClose(false);
122  }
void PostClose(bool restart=true)
Definition: Connection.cc:125
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
float temp
Definition: HeadersPFmini.h:56
std::ostream & Out()
Definition: Connection.h:51
int Warn(const std::string &str)
Definition: MessageImp.h:48
virtual void Update(const vector< float > &)
Definition: temperature.cc:55
int Message(const std::string &str)
Definition: MessageImp.h:46