void CSterbox::GetMeterDetails() { std::string sResult; std::stringstream szURL; //if(m_Password.empty()) //{ szURL << "http://" << m_szIPAddress << ":" << m_usIPPort; //} //else //{ // szURL << "http://" << m_Username << ":" << m_Password << "@" << m_szIPAddress << ":" << m_usIPPort; //} szURL << "/x.cgi"; if (!HTTPClient::GET(szURL.str(),sResult)) { _log.Log(LOG_ERROR,"Sterbox: Error connecting to: %s", m_szIPAddress.c_str()); return; } std::vector<std::string> results; std::vector<std::string> outputs; std::vector<std::string> inputs; std::vector<std::string> analog; StringSplit(sResult, "<br>", results); if (results.size()<8) { _log.Log(LOG_ERROR,"Sterbox: Result 8 Error connecting to: %s", m_szIPAddress.c_str()); return; } //if (results[0] != "<body>") std::string tmpstr; std::string tmpstr2; std::string tmpinp; tmpstr = results[0]; if (tmpstr.find("<title>SterBox_State</title>") != std::string::npos) { _log.Log(LOG_ERROR, "Sterbox: Error getting status"); return; } size_t ii; size_t jj; int pos1; int Idx = 0; if (m_Username.empty()) { StringSplit("o,o,o,o,i,i,i,i", ",", inputs); } else { StringSplit(m_Username, ",", inputs); //_log.Log(LOG_ERROR,"Sterbox: Username : %s , IP: %s", m_Username.c_str(), m_szIPAddress.c_str()); } for (ii = 1; ii < results.size(); ii++) { tmpstr = results[ii]; if (tmpstr.find("OU") != std::string::npos) { tmpstr = tmpstr.substr(strlen("OU")); pos1 = tmpstr.find("="); if (pos1 != std::string::npos) { tmpstr = tmpstr.substr(pos1+1); //_log.Log(LOG_ERROR,"Sterbox: OU Status: %s", tmpstr.c_str()); StringSplit(tmpstr, ",", outputs); for (jj = 0; jj < inputs.size(); jj++) { tmpinp = inputs[jj]; //if (( jj < 4 || jj > 7 )) pos1 = tmpinp.find("o"); if (pos1 != std::string::npos) { int lValue = 0; //tmpstr = tmpstr.substr(pos1+1); tmpstr2 = outputs[jj]; //_log.Log(LOG_ERROR,"Sterbox: OU Status: %s", tmpstr2.c_str()); pos1 = tmpstr2.find("s"); if (pos1 != std::string::npos) { lValue = 1; } else { lValue = 0; } std::stringstream sstr; sstr << "Relay " << jj; UpdateSwitch(1, jj, (lValue == 1) ? true : false, 100, sstr.str()); } } } } else if (tmpstr.find("IN") != std::string::npos) { tmpstr = tmpstr.substr(strlen("IN")); pos1 = tmpstr.find("="); if (pos1 != std::string::npos) { tmpstr = tmpstr.substr(pos1+1); //_log.Log(LOG_ERROR,"Sterbox: OU Status: %s", tmpstr.c_str()); StringSplit(tmpstr, ",", outputs); for (jj = 0; jj < inputs.size(); jj++) { tmpinp = inputs[jj]; //if (( jj > 3 && jj < 8 )) pos1 = tmpinp.find("i"); if (pos1 != std::string::npos) { int lValue = 0; //tmpstr = tmpstr.substr(pos1+1); tmpstr2 = outputs[jj]; //_log.Log(LOG_ERROR,"Sterbox: OU Status: %s", tmpstr2.c_str()); pos1 = tmpstr2.find("S"); if (pos1 != std::string::npos) { lValue = 1; } else { lValue = 0; } std::stringstream sstr; sstr << "Relay " << jj; UpdateSwitch(1, jj, (lValue == 1) ? true : false, 100, sstr.str()); } } } } else if (tmpstr.find("AN") != std::string::npos) { tmpstr = tmpstr.substr(strlen("AN")); pos1 = tmpstr.find("="); if (pos1 != std::string::npos) { tmpstr = tmpstr.substr(pos1+1); StringSplit(tmpstr, ",", outputs); if (m_Password.empty()) { StringSplit("t,t,t", ",", analog); } else { //StringSplit("t,t,t", ",", inputs); StringSplit(m_Password, ",", analog); //_log.Log(LOG_ERROR,"Sterbox: Pass : %s", m_Password.c_str()); } for (jj = 0; jj < 3; jj++) { tmpstr2 = outputs[jj]; tmpinp = analog[jj]; tmpstr2 = tmpstr2.substr(1, 10); float lValue = (float)atof(tmpstr2.c_str()); std::stringstream sstr; sstr << "Analog " << jj; pos1 = tmpinp.find("t"); if (pos1 != std::string::npos) { SendTempSensor(jj,255,lValue, sstr.str()); } pos1 = tmpinp.find("v"); if (pos1 != std::string::npos) { SendVoltageSensor(0, jj, 255, lValue, sstr.str()); } pos1 = tmpinp.find("l"); if (pos1 != std::string::npos) { SendLuxSensor(0, jj, 255,lValue, sstr.str()); } pos1 = tmpinp.find("h"); if (pos1 != std::string::npos) { SendHumiditySensor(jj,255,int(lValue), sstr.str()); } //SendTempSensor(jj,255,lValue, sstr.str()); //_log.Log(LOG_ERROR,"Sterbox: OU Status: %s", tmpstr2.c_str()); } //Idx = atoi(tmpstr.substr(0, pos1).c_str()); //tmpstr = tmpstr.substr(pos1 + 1); //pos1 = tmpstr.find("<"); //if (pos1 != std::string::npos) //{ // int lValue = atoi(tmpstr.substr(0, pos1).c_str()); // float voltage = (float)(5.0f / 1023.0f)*lValue; // if (voltage > 5.0f) // voltage = 5.0f; // std::stringstream sstr; // sstr << "Voltage " << Idx; // SendVoltageSensor(0, Idx, 255, voltage, sstr.str()); //} } } } }
bool CRFLinkBase::ParseLine(const std::string &sLine) { m_LastReceivedTime = mytime(NULL); std::vector<std::string> results; StringSplit(sLine, ";", results); if (results.size() < 2) return false; //not needed bool bHideDebugLog = ( (sLine.find("PONG") != std::string::npos)|| (sLine.find("PING") != std::string::npos) ); int RFLink_ID = atoi(results[0].c_str()); if (RFLink_ID != 20) { return false; //only accept RFLink->Master messages } #ifdef ENABLE_LOGGING if (!bHideDebugLog) _log.Log(LOG_NORM, "RFLink: %s", sLine.c_str()); #endif //std::string Sensor_ID = results[1]; if (results.size() >2) { //Status reply std::string Name_ID = results[2]; if ((Name_ID.find("Nodo RadioFrequencyLink") != std::string::npos) || (Name_ID.find("RFLink Gateway") != std::string::npos)) { _log.Log(LOG_STATUS, "RFLink: Controller Initialized!..."); WriteInt("10;VERSION;\n"); // 20;3C;VER=1.1;REV=37;BUILD=01; //Enable DEBUG //write("10;RFDEBUG=ON;\n"); //Enable Undecoded DEBUG //write("10;RFUDEBUG=ON;\n"); return true; } if (Name_ID.find("VER") != std::string::npos) { //_log.Log(LOG_STATUS, "RFLink: %s", sLine.c_str()); int versionlo = 0; int versionhi = 0; int revision = 0; int build = 0; if (results[2].find("VER") != std::string::npos) { versionhi = RFLinkGetIntStringValue(results[2]); versionlo = RFLinkGetIntDecStringValue(results[2]); } if (results[3].find("REV") != std::string::npos){ revision = RFLinkGetIntStringValue(results[3]); } if (results[4].find("BUILD") != std::string::npos) { build = RFLinkGetIntStringValue(results[4]); } _log.Log(LOG_STATUS, "RFLink Detected, Version: %d.%d Revision: %d Build: %d", versionhi, versionlo, revision, build); std::stringstream sstr; sstr << revision << "." << build; m_Version = sstr.str(); mytime(&m_LastHeartbeatReceive); // keep heartbeat happy mytime(&m_LastHeartbeat); // keep heartbeat happy m_LastReceivedTime = m_LastHeartbeat; m_bTXokay = true; // variable to indicate an OK was received return true; } if (Name_ID.find("PONG") != std::string::npos) { //_log.Log(LOG_STATUS, "RFLink: PONG received!..."); mytime(&m_LastHeartbeatReceive); // keep heartbeat happy mytime(&m_LastHeartbeat); // keep heartbeat happy m_LastReceivedTime = m_LastHeartbeat; m_bTXokay = true; // variable to indicate an OK was received return true; } if (Name_ID.find("OK") != std::string::npos) { //_log.Log(LOG_STATUS, "RFLink: OK received!..."); mytime(&m_LastHeartbeatReceive); // keep heartbeat happy mytime(&m_LastHeartbeat); // keep heartbeat happy m_LastReceivedTime = m_LastHeartbeat; m_bTXokay = true; // variable to indicate an OK was received return true; } else if (Name_ID.find("CMD UNKNOWN") != std::string::npos) { _log.Log(LOG_ERROR, "RFLink: Error/Unknown command received!..."); m_bTXokay = true; // variable to indicate an ERROR was received return true; } } if (results.size() < 4) return true; if (results[3].find("ID=") == std::string::npos) return false; //?? mytime(&m_LastHeartbeatReceive); // keep heartbeat happy mytime(&m_LastHeartbeat); // keep heartbeat happy //_log.Log(LOG_STATUS, "RFLink: t1=%d t2=%d", m_LastHeartbeat, m_LastHeartbeatReceive); m_LastReceivedTime = m_LastHeartbeat; std::stringstream ss; unsigned int ID; ss << std::hex << results[3].substr(3); ss >> ID; int Node_ID = (ID & 0xFF00) >> 8; int Child_ID = ID & 0xFF; bool bHaveTemp = false; float temp = 0; bool bHaveHum = false; int humidity = 0; bool bHaveHumStatus = false; int humstatus = 0; bool bHaveBaro = false; float baro = 0; int baroforecast = 0; bool bHaveRain = false; float raincounter = 0; bool bHaveLux = false; float lux = 0; bool bHaveUV = false; float uv = 0; bool bHaveWindDir = false; int windir = 0; bool bHaveWindSpeed = false; float windspeed = 0; bool bHaveWindGust = false; float windgust = 0; bool bHaveWindTemp = false; float windtemp = 0; bool bHaveWindChill = false; float windchill = 0; bool bHaveRGB = false; int rgb = 0; bool bHaveRGBW = false; int rgbw = 0; bool bHaveSound = false; int sound = 0; bool bHaveCO2 = false; int co2 = 0; bool bHaveBlind = false; int blind = 0; bool bHaveKWatt = false; float kwatt = 0; bool bHaveWatt = false; float watt = 0; bool bHaveDistance = false; float distance = 0; bool bHaveMeter = false; float meter = 0; bool bHaveVoltage = false; float voltage = 0; bool bHaveCurrent = false; float current = 0; bool bHaveCurrent2 = false; float current2 = 0; bool bHaveCurrent3 = false; float current3 = 0; bool bHaveImpedance = false; float impedance = 0; bool bHaveSwitch = false; int switchunit = 0; bool bHaveSwitchCmd = false; std::string switchcmd = ""; int switchlevel = 0; int BatteryLevel = 255; std::string tmpstr; int iTemp; for (size_t ii = 4; ii < results.size(); ii++) { if (results[ii].find("TEMP") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveTemp = true; if ((iTemp & 0x8000) == 0x8000) { //negative temp iTemp = -(iTemp & 0xFFF); } temp = float(iTemp) / 10.0f; } else if (results[ii].find("HUM") != std::string::npos) { bHaveHum = true; humidity = RFLinkGetIntStringValue(results[ii]); } else if (results[ii].find("HSTATUS") != std::string::npos) { bHaveHumStatus = true; humstatus = RFLinkGetIntStringValue(results[ii]); } else if (results[ii].find("BARO") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveBaro = true; baro = float(iTemp); } else if (results[ii].find("BFORECAST") != std::string::npos) { baroforecast = RFLinkGetIntStringValue(results[ii]); } else if (results[ii].find("RAIN") != std::string::npos) { bHaveRain = true; iTemp = RFLinkGetHexStringValue(results[ii]); raincounter = float(iTemp) / 10.0f; } else if (results[ii].find("LUX") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveLux = true; lux = float(iTemp); } else if (results[ii].find("UV") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveUV = true; uv = float(iTemp) /10.0f; } else if (results[ii].find("BAT") != std::string::npos) { tmpstr = RFLinkGetStringValue(results[ii]); BatteryLevel = (tmpstr == "OK") ? 100 : 0; } else if (results[ii].find("WINDIR") != std::string::npos) { bHaveWindDir = true; windir = RFLinkGetIntStringValue(results[ii]); } else if (results[ii].find("WINSP") != std::string::npos) { bHaveWindSpeed = true; iTemp = RFLinkGetHexStringValue(results[ii]); // received value is km/u windspeed = (float(iTemp) * 0.0277778f); //convert to m/s } else if (results[ii].find("WINGS") != std::string::npos) { bHaveWindGust = true; iTemp = RFLinkGetHexStringValue(results[ii]); // received value is km/u windgust = (float(iTemp) * 0.0277778f); //convert to m/s } else if (results[ii].find("WINTMP") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveWindTemp = true; if ((iTemp & 0x8000) == 0x8000) { //negative temp iTemp = -(iTemp & 0xFFF); } windtemp = float(iTemp) / 10.0f; } else if (results[ii].find("WINCHL") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveWindChill = true; if ((iTemp & 0x8000) == 0x8000) { //negative temp iTemp = -(iTemp & 0xFFF); } windchill = float(iTemp) / 10.0f; } else if (results[ii].find("SOUND") != std::string::npos) { bHaveSound = true; sound = RFLinkGetIntStringValue(results[ii]); } else if (results[ii].find("CO2") != std::string::npos) { bHaveCO2 = true; co2 = RFLinkGetIntStringValue(results[ii]); } else if (results[ii].find("RGBW") != std::string::npos) { bHaveRGBW = true; rgbw = RFLinkGetIntStringValue(results[ii]); } else if (results[ii].find("RGB") != std::string::npos) { bHaveRGB = true; rgb = RFLinkGetIntStringValue(results[ii]); } else if (results[ii].find("BLIND") != std::string::npos) { bHaveBlind = true; blind = RFLinkGetIntStringValue(results[ii]); } else if (results[ii].find("KWATT") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveKWatt = true; kwatt = float(iTemp) / 1000.0f; } else if (results[ii].find("WATT") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveWatt = true; watt = float(iTemp) / 10.0f; } else if (results[ii].find("DIST") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveDistance = true; distance = float(iTemp) / 10.0f; } else if (results[ii].find("METER") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveMeter = true; meter = float(iTemp) / 10.0f; } else if (results[ii].find("VOLT") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveVoltage = true; voltage = float(iTemp) / 10.0f; } else if (results[ii].find("CURRENT") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveCurrent = true; current = float(iTemp) / 10.0f; } else if (results[ii].find("CURRENT2") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveCurrent2 = true; current2 = float(iTemp) / 10.0f; } else if (results[ii].find("CURRENT3") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveCurrent3 = true; current3 = float(iTemp) / 10.0f; } else if (results[ii].find("IMPEDANCE") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveCurrent = true; current = float(iTemp) / 10.0f; } else if (results[ii].find("SWITCH") != std::string::npos) { bHaveSwitch = true; switchunit = RFLinkGetHexStringValue(results[ii]); } else if (results[ii].find("CMD") != std::string::npos) { bHaveSwitchCmd = true; switchcmd = RFLinkGetStringValue(results[ii]); } else if (results[ii].find("SMOKEALERT") != std::string::npos) { bHaveSwitch = true; switchunit = 1; bHaveSwitchCmd = true; switchcmd = RFLinkGetStringValue(results[ii]); } else if (results[ii].find("CHIME") != std::string::npos) { bHaveSwitch = true; switchunit = 2; bHaveSwitchCmd = true; switchcmd = "ON"; } } std::string tmp_Name = results[2]; if (bHaveTemp&&bHaveHum&&bHaveBaro) { SendTempHumBaroSensor(ID, BatteryLevel, temp, humidity, baro, baroforecast, tmp_Name); } else if (bHaveTemp&&bHaveHum) { SendTempHumSensor(ID, BatteryLevel, temp, humidity, tmp_Name); } else if (bHaveTemp) { SendTempSensor(ID, BatteryLevel, temp, tmp_Name); } else if (bHaveHum) { SendHumiditySensor(ID, BatteryLevel, humidity, tmp_Name); } else if (bHaveBaro) { SendBaroSensor(Node_ID, Child_ID, BatteryLevel, baro, baroforecast, tmp_Name); } if (bHaveLux) { SendLuxSensor(Node_ID, Child_ID, BatteryLevel, lux, tmp_Name); } if (bHaveUV) { SendUVSensor(Node_ID, Child_ID, BatteryLevel, uv, tmp_Name); } if (bHaveRain) { SendRainSensor(ID, BatteryLevel, float(raincounter), tmp_Name); } if (bHaveWindDir && bHaveWindSpeed && bHaveWindGust && bHaveWindChill) { SendWind(ID, BatteryLevel, float(windir), windspeed, windgust, windtemp, windchill, bHaveWindTemp, tmp_Name); } else if (bHaveWindDir && bHaveWindGust) { SendWind(ID, BatteryLevel, float(windir), windspeed, windgust, windtemp, windchill, bHaveWindTemp, tmp_Name); } else if (bHaveWindSpeed) { SendWind(ID, BatteryLevel, float(windir), windspeed, windgust, windtemp, windchill, bHaveWindTemp, tmp_Name); } if (bHaveCO2) { SendAirQualitySensor((ID & 0xFF00) >> 8, ID & 0xFF, BatteryLevel, co2, tmp_Name); } if (bHaveSound) { SendSoundSensor(ID, BatteryLevel, sound, tmp_Name); } if (bHaveRGB) { //RRGGBB SendRGBWSwitch(Node_ID, Child_ID, BatteryLevel, rgb, false, tmp_Name); } if (bHaveRGBW) { //RRGGBBWW SendRGBWSwitch(Node_ID, Child_ID, BatteryLevel, rgbw, true, tmp_Name); } if (bHaveBlind) { SendBlindSensor(Node_ID, Child_ID, BatteryLevel, blind, tmp_Name); } if (bHaveKWatt&bHaveWatt) { SendKwhMeterOldWay(Node_ID, Child_ID, BatteryLevel, watt / 100.0f, kwatt, tmp_Name); } else if (bHaveKWatt) { SendKwhMeterOldWay(Node_ID, Child_ID, BatteryLevel, watt / 100.0f, kwatt, tmp_Name); } else if (bHaveWatt) { SendKwhMeterOldWay(Node_ID, Child_ID, BatteryLevel, watt / 100.0f, kwatt, tmp_Name); } if (bHaveDistance) { SendDistanceSensor(Node_ID, Child_ID, BatteryLevel, distance, tmp_Name); } if (bHaveMeter) { SendMeterSensor(Node_ID, Child_ID, BatteryLevel, meter, tmp_Name); } if (bHaveVoltage) { SendVoltageSensor(Node_ID, Child_ID, BatteryLevel, voltage, tmp_Name); } if (bHaveCurrent && bHaveCurrent2 && bHaveCurrent3) { SendCurrentSensor(ID, BatteryLevel, current, current2, current3, tmp_Name); } else if (bHaveCurrent) { SendCurrentSensor(ID, BatteryLevel, current, 0, 0, tmp_Name); } if (bHaveImpedance) { SendPercentageSensor(Node_ID, Child_ID, BatteryLevel, impedance, tmp_Name); } if (bHaveSwitch && bHaveSwitchCmd) { std::string switchType = results[2]; SendSwitchInt(ID, switchunit, BatteryLevel, switchType, switchcmd, switchlevel); } return true; }
bool CRFLink::ParseLine(const std::string &sLine) { m_LastReceivedTime = mytime(NULL); std::vector<std::string> results; StringSplit(sLine, ";", results); if (results.size() < 2) return false; //not needed bool bHideDebugLog = ( (sLine.find("PONG") != std::string::npos)|| (sLine.find("PING") != std::string::npos) ); int RFLink_ID = atoi(results[0].c_str()); if (RFLink_ID != 20) { return false; //only accept RFLink->Master messages } #ifdef ENABLE_LOGGING if (!bHideDebugLog) _log.Log(LOG_NORM, "RFLink: %s", sLine.c_str()); #endif //std::string Sensor_ID = results[1]; if (results.size() >2) { //Status reply std::string Name_ID = results[2]; if (Name_ID.find("Nodo RadioFrequencyLink") != std::string::npos) { _log.Log(LOG_STATUS, "RFLink: Controller Initialized!..."); //Enable DEBUG //write("10;RFDEBUG=ON;\n"); //Enable Undecoded DEBUG //write("10;RFUDEBUG=ON;\n"); return true; } if (Name_ID.find("OK") != std::string::npos) { //_log.Log(LOG_STATUS, "RFLink: OK received!..."); m_bTXokay = true; // variable to indicate an OK was received return true; } } if (results.size() < 4) return true; if (results[3].find("ID=") == std::string::npos) return false; //?? std::stringstream ss; unsigned int ID; ss << std::hex << results[3].substr(3); ss >> ID; int Node_ID = (ID & 0xFF00) >> 8; int Child_ID = ID & 0xFF; bool bHaveTemp = false; float temp = 0; bool bHaveHum = false; int humidity = 0; bool bHaveHumStatus = false; int humstatus = 0; bool bHaveBaro = false; float baro = 0; int baroforecast = 0; bool bHaveRain = false; int raincounter = 0; bool bHaveLux = false; float lux = 0; bool bHaveUV = false; float uv = 0; bool bHaveWindDir = false; int windir = 0; bool bHaveWindSpeed = false; float windspeed = 0; bool bHaveWindGust = false; float windgust = 0; bool bHaveWindTemp = false; float windtemp = 0; bool bHaveWindChill = false; float windchill = 0; bool bHaveRGB = false; int rgb = 0; bool bHaveRGBW = false; int rgbw = 0; bool bHaveSound = false; int sound = 0; bool bHaveCO2 = false; int co2 = 0; bool bHaveBlind = false; int blind = 0; bool bHaveKWatt = false; float kwatt = 0; bool bHaveWatt = false; float watt = 0; bool bHaveDistance = false; float distance = 0; bool bHaveMeter = false; float meter = 0; bool bHaveVoltage = false; float voltage = 0; bool bHaveCurrent = false; float current = 0; bool bHaveSwitch = false; int switchunit = 0; bool bHaveSwitchCmd = false; std::string switchcmd = ""; int switchlevel = 0; int BatteryLevel = 255; std::string tmpstr; int iTemp; for (size_t ii = 4; ii < results.size(); ii++) { if (results[ii].find("TEMP") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveTemp = true; if ((iTemp & 0x8000) == 0x8000) { //negative temp iTemp = -(iTemp & 0xFFF); } temp = float(iTemp) / 10.0f; } else if (results[ii].find("HUM") != std::string::npos) { bHaveHum = true; humidity = RFLinkGetIntStringValue(results[ii]); } else if (results[ii].find("HSTATUS") != std::string::npos) { bHaveHumStatus = true; humstatus = RFLinkGetIntStringValue(results[ii]); } else if (results[ii].find("BARO") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveBaro = true; baro = float(iTemp); } else if (results[ii].find("BFORECAST") != std::string::npos) { baroforecast = RFLinkGetIntStringValue(results[ii]); } else if (results[ii].find("RAIN") != std::string::npos) { bHaveRain = true; raincounter = RFLinkGetHexStringValue(results[ii]); } else if (results[ii].find("LUX") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveLux = true; lux = float(iTemp); } else if (results[ii].find("UV") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveUV = true; uv = float(iTemp); } else if (results[ii].find("BAT") != std::string::npos) { tmpstr = RFLinkGetStringValue(results[ii]); BatteryLevel = (tmpstr == "OK") ? 100 : 0; } else if (results[ii].find("WINDIR") != std::string::npos) { bHaveWindDir = true; windir = RFLinkGetIntStringValue(results[ii]); } else if (results[ii].find("WINSP") != std::string::npos) { bHaveWindSpeed = true; iTemp = RFLinkGetHexStringValue(results[ii]); windspeed = float(iTemp) * 0.0277778f; //convert to m/s } else if (results[ii].find("WINGS") != std::string::npos) { bHaveWindGust = true; iTemp = RFLinkGetHexStringValue(results[ii]); windgust = float(iTemp) * 0.0277778f; //convert to m/s } else if (results[ii].find("WINTMP") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveWindTemp = true; if ((iTemp & 0x8000) == 0x8000) { //negative temp iTemp = -(iTemp & 0xFFF); } windtemp = float(iTemp) / 10.0f; } else if (results[ii].find("WINCHL") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveWindChill = true; if ((iTemp & 0x8000) == 0x8000) { //negative temp iTemp = -(iTemp & 0xFFF); } windchill = float(iTemp) / 10.0f; } else if (results[ii].find("SOUND") != std::string::npos) { bHaveSound = true; sound = RFLinkGetIntStringValue(results[ii]); } else if (results[ii].find("CO2") != std::string::npos) { bHaveCO2 = true; co2 = RFLinkGetIntStringValue(results[ii]); } else if (results[ii].find("RGBW") != std::string::npos) { bHaveRGBW = true; rgbw = RFLinkGetIntStringValue(results[ii]); } else if (results[ii].find("RGB") != std::string::npos) { bHaveRGB = true; rgb = RFLinkGetIntStringValue(results[ii]); } else if (results[ii].find("BLIND") != std::string::npos) { bHaveBlind = true; blind = RFLinkGetIntStringValue(results[ii]); } else if (results[ii].find("KWATT") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveKWatt = true; kwatt = float(iTemp) / 10.0f; } else if (results[ii].find("WATT") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveWatt = true; watt = float(iTemp) / 10.0f; } else if (results[ii].find("DIST") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveDistance = true; distance = float(iTemp) / 10.0f; } else if (results[ii].find("METER") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveMeter = true; meter = float(iTemp) / 10.0f; } else if (results[ii].find("VOLT") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveVoltage = true; voltage = float(iTemp) / 10.0f; } else if (results[ii].find("CURRENT") != std::string::npos) { iTemp = RFLinkGetHexStringValue(results[ii]); bHaveCurrent = true; current = float(iTemp) / 10.0f; } else if (results[ii].find("SWITCH") != std::string::npos) { bHaveSwitch = true; switchunit = RFLinkGetHexStringValue(results[ii]); } else if (results[ii].find("CMD") != std::string::npos) { bHaveSwitchCmd = true; switchcmd = RFLinkGetStringValue(results[ii]); } else if (results[ii].find("SMOKEALERT") != std::string::npos) { bHaveSwitch = true; switchunit = 1; bHaveSwitchCmd = true; switchcmd = RFLinkGetStringValue(results[ii]); } } if (bHaveTemp&&bHaveHum&&bHaveBaro) { SendTempHumBaroSensor(ID, BatteryLevel, temp, humidity, baro, baroforecast); } else if (bHaveTemp&&bHaveHum) { SendTempHumSensor(ID, BatteryLevel, temp, humidity, "TempHum"); } else if (bHaveTemp) { SendTempSensor(ID, BatteryLevel, temp,"Temp"); } else if (bHaveHum) { SendHumiditySensor(ID, BatteryLevel, humidity); } else if (bHaveBaro) { SendBaroSensor(Node_ID, Child_ID, BatteryLevel, baro, baroforecast); } if (bHaveLux) { SendLuxSensor(Node_ID, Child_ID, BatteryLevel, lux, "Lux"); } if (bHaveUV) { SendUVSensor(Node_ID, Child_ID, BatteryLevel, uv); } if (bHaveRain) { SendRainSensor(ID, BatteryLevel, float(raincounter), "Rain"); } if (bHaveWindDir && bHaveWindSpeed && bHaveWindGust && bHaveWindChill) { SendWind(ID, BatteryLevel, float(windir), windspeed, windgust, windtemp, windchill, bHaveWindTemp, "Wind"); } else if (bHaveWindDir && bHaveWindGust) { SendWind(ID, BatteryLevel, float(windir), windspeed, windgust, windtemp, windchill, bHaveWindTemp, "Wind"); } else if (bHaveWindSpeed) { SendWind(ID, BatteryLevel, float(windir), windspeed, windgust, windtemp, windchill, bHaveWindTemp, "Wind"); } if (bHaveCO2) { SendAirQualitySensor((ID & 0xFF00) >> 8, ID & 0xFF, BatteryLevel, co2, "CO2"); } if (bHaveSound) { SendSoundSensor(ID, BatteryLevel, sound, "Sound"); } if (bHaveRGB) { //RRGGBB SendRGBWSwitch(Node_ID, Child_ID, BatteryLevel, rgb, false, "RGB Light"); } if (bHaveRGBW) { //RRGGBBWW SendRGBWSwitch(Node_ID, Child_ID, BatteryLevel, rgbw, true, "RGBW Light"); } if (bHaveBlind) { SendBlindSensor(Node_ID, Child_ID, BatteryLevel, blind, "Blinds/Window"); } if (bHaveKWatt) { SendKwhMeter(Node_ID, Child_ID, BatteryLevel, kwatt / 1000.0f, kwatt, "Meter"); } if (bHaveWatt) { SendKwhMeter(Node_ID, Child_ID, BatteryLevel, 0, watt, "Meter"); } if (bHaveDistance) { SendDistanceSensor(Node_ID, Child_ID, BatteryLevel, distance); } if (bHaveMeter) { SendMeterSensor(Node_ID, Child_ID, BatteryLevel, meter); } if (bHaveVoltage) { SendVoltageSensor(Node_ID, Child_ID, BatteryLevel, voltage, "Voltage"); } if (bHaveCurrent) { SendCurrentSensor(ID, BatteryLevel, current, 0, 0, "Current"); } if (bHaveSwitch && bHaveSwitchCmd) { std::string switchType = results[2]; SendSwitchInt(ID, switchunit, BatteryLevel, switchType, switchcmd, switchlevel); } return true; }
void MySensorsBase::SendSensor2Domoticz(_tMySensorNode *pNode, _tMySensorChild *pChild, const _eSetType vType) { m_iLastSendNodeBatteryValue = 255; if (pChild->hasBattery) { m_iLastSendNodeBatteryValue = pChild->batValue; } int cNode = (pChild->nodeID << 8) | pChild->childID; int intValue; float floatValue; std::string stringValue; switch (vType) { case V_TEMP: { float Temp = 0; pChild->GetValue(V_TEMP, Temp); _tMySensorChild *pChildHum = FindChildWithValueType(pChild->nodeID, V_HUM); _tMySensorChild *pChildBaro = FindChildWithValueType(pChild->nodeID, V_PRESSURE); if (pChildHum && pChildBaro) { int Humidity; float Baro; bool bHaveHumidity = pChildHum->GetValue(V_HUM, Humidity); bool bHaveBaro = pChildBaro->GetValue(V_PRESSURE, Baro); if (bHaveHumidity && bHaveBaro) { int forecast = bmpbaroforecast_unknown; _tMySensorChild *pSensorForecast = FindChildWithValueType(pChild->nodeID, V_FORECAST); if (pSensorForecast) { pSensorForecast->GetValue(V_FORECAST, forecast); } if (forecast == bmpbaroforecast_cloudy) { if (Baro < 1010) forecast = bmpbaroforecast_rain; } //We are using the TempHumBaro Float type now, convert the forecast int nforecast = wsbaroforcast_some_clouds; if (Baro <= 980) nforecast = wsbaroforcast_heavy_rain; else if (Baro <= 995) { if (Temp > 1) nforecast = wsbaroforcast_rain; else nforecast = wsbaroforcast_snow; break; } else if (Baro >= 1029) nforecast = wsbaroforcast_sunny; switch (forecast) { case bmpbaroforecast_sunny: nforecast = wsbaroforcast_sunny; break; case bmpbaroforecast_cloudy: nforecast = wsbaroforcast_cloudy; break; case bmpbaroforecast_thunderstorm: nforecast = wsbaroforcast_heavy_rain; break; case bmpbaroforecast_rain: if (Temp>1) nforecast = wsbaroforcast_rain; else nforecast = wsbaroforcast_snow; break; } SendTempHumBaroSensorFloat(cNode, pChild->batValue, Temp, Humidity, Baro, nforecast, (!pChild->childName.empty()) ? pChild->childName : "TempHumBaro"); } } else if (pChildHum) { int Humidity; bool bHaveHumidity = pChildHum->GetValue(V_HUM, Humidity); if (bHaveHumidity) { SendTempHumSensor(cNode, pChild->batValue, Temp, Humidity, (!pChild->childName.empty()) ? pChild->childName : "TempHum"); } } else { SendTempSensor(cNode, pChild->batValue, Temp, (!pChild->childName.empty()) ? pChild->childName : "Temp"); } } break; case V_HUM: { _tMySensorChild *pChildTemp = FindChildWithValueType(pChild->nodeID, V_TEMP); _tMySensorChild *pChildBaro = FindChildWithValueType(pChild->nodeID, V_PRESSURE); int forecast = bmpbaroforecast_unknown; _tMySensorChild *pSensorForecast = FindChildWithValueType(pChild->nodeID, V_FORECAST); if (pSensorForecast) { pSensorForecast->GetValue(V_FORECAST, forecast); } if (forecast == bmpbaroforecast_cloudy) { if (pChildBaro) { float Baro; if (pChildBaro->GetValue(V_PRESSURE, Baro)) { if (Baro < 1010) forecast = bmpbaroforecast_rain; } } } float Temp; float Baro; int Humidity; pChild->GetValue(V_HUM, Humidity); if (pChildTemp && pChildBaro) { bool bHaveTemp = pChildTemp->GetValue(V_TEMP, Temp); bool bHaveBaro = pChildBaro->GetValue(V_PRESSURE, Baro); if (bHaveTemp && bHaveBaro) { cNode = (pChildTemp->nodeID << 8) | pChildTemp->childID; //We are using the TempHumBaro Float type now, convert the forecast int nforecast = wsbaroforcast_some_clouds; if (Baro <= 980) nforecast = wsbaroforcast_heavy_rain; else if (Baro <= 995) { if (Temp > 1) nforecast = wsbaroforcast_rain; else nforecast = wsbaroforcast_snow; break; } else if (Baro >= 1029) nforecast = wsbaroforcast_sunny; switch (forecast) { case bmpbaroforecast_sunny: nforecast = wsbaroforcast_sunny; break; case bmpbaroforecast_cloudy: nforecast = wsbaroforcast_cloudy; break; case bmpbaroforecast_thunderstorm: nforecast = wsbaroforcast_heavy_rain; break; case bmpbaroforecast_rain: if (Temp > 1) nforecast = wsbaroforcast_rain; else nforecast = wsbaroforcast_snow; break; } SendTempHumBaroSensorFloat(cNode, pChildTemp->batValue, Temp, Humidity, Baro, nforecast, (!pChild->childName.empty()) ? pChild->childName : "TempHumBaro"); } } else if (pChildTemp) { bool bHaveTemp = pChildTemp->GetValue(V_TEMP, Temp); if (bHaveTemp) { cNode = (pChildTemp->nodeID << 8) | pChildTemp->childID; SendTempHumSensor(cNode, pChildTemp->batValue, Temp, Humidity, (!pChild->childName.empty()) ? pChild->childName : "TempHum"); } } else { SendHumiditySensor(cNode, pChild->batValue, Humidity); } } break; case V_PRESSURE: { float Baro; pChild->GetValue(V_PRESSURE, Baro); _tMySensorChild *pSensorTemp = FindChildWithValueType(pChild->nodeID, V_TEMP); _tMySensorChild *pSensorHum = FindChildWithValueType(pChild->nodeID, V_HUM); int forecast = bmpbaroforecast_unknown; _tMySensorChild *pSensorForecast = FindChildWithValueType(pChild->nodeID, V_FORECAST); if (pSensorForecast) { pSensorForecast->GetValue(V_FORECAST, forecast); } if (forecast == bmpbaroforecast_cloudy) { if (Baro < 1010) forecast = bmpbaroforecast_rain; } if (pSensorTemp && pSensorHum) { float Temp; int Humidity; bool bHaveTemp = pSensorTemp->GetValue(V_TEMP, Temp); bool bHaveHumidity = pSensorHum->GetValue(V_HUM, Humidity); if (bHaveTemp && bHaveHumidity) { cNode = (pSensorTemp->nodeID << 8) | pSensorTemp->childID; //We are using the TempHumBaro Float type now, convert the forecast int nforecast = wsbaroforcast_some_clouds; if (Baro <= 980) nforecast = wsbaroforcast_heavy_rain; else if (Baro <= 995) { if (Temp > 1) nforecast = wsbaroforcast_rain; else nforecast = wsbaroforcast_snow; break; } else if (Baro >= 1029) nforecast = wsbaroforcast_sunny; switch (forecast) { case bmpbaroforecast_sunny: nforecast = wsbaroforcast_sunny; break; case bmpbaroforecast_cloudy: nforecast = wsbaroforcast_cloudy; break; case bmpbaroforecast_thunderstorm: nforecast = wsbaroforcast_heavy_rain; break; case bmpbaroforecast_rain: if (Temp > 1) nforecast = wsbaroforcast_rain; else nforecast = wsbaroforcast_snow; break; } SendTempHumBaroSensorFloat(cNode, pSensorTemp->batValue, Temp, Humidity, Baro, nforecast, (!pChild->childName.empty()) ? pChild->childName : "TempHumBaro"); } } else SendBaroSensor(pChild->nodeID, pChild->childID, pChild->batValue, Baro, forecast); } break; case V_TRIPPED: // Tripped status of a security sensor. 1 = Tripped, 0 = Untripped if (pChild->GetValue(vType, intValue)) UpdateSwitch(pChild->nodeID, pChild->childID, (intValue == 1), 100, (!pChild->childName.empty()) ? pChild->childName : "Security Sensor"); break; case V_ARMED: //Armed status of a security sensor. 1 = Armed, 0 = Bypassed if (pChild->GetValue(vType, intValue)) UpdateSwitch(pChild->nodeID, pChild->childID, (intValue == 1), 100, (!pChild->childName.empty()) ? pChild->childName : "Security Sensor"); break; case V_LOCK_STATUS: //Lock status. 1 = Locked, 0 = Unlocked if (pChild->GetValue(vType, intValue)) UpdateSwitch(pChild->nodeID, pChild->childID, (intValue == 1), 100, (!pChild->childName.empty()) ? pChild->childName : "Lock Sensor"); break; case V_STATUS: // Light status. 0 = off 1 = on if (pChild->GetValue(vType, intValue)) UpdateSwitch(pChild->nodeID, pChild->childID, (intValue != 0), 100, (!pChild->childName.empty()) ? pChild->childName : "Light"); break; case V_SCENE_ON: if (pChild->GetValue(vType, intValue)) UpdateSwitch(pChild->nodeID, pChild->childID + intValue, true, 100, (!pChild->childName.empty()) ? pChild->childName : "Scene"); break; case V_SCENE_OFF: if (pChild->GetValue(vType, intValue)) UpdateSwitch(pChild->nodeID, pChild->childID + intValue, false, 100, (!pChild->childName.empty()) ? pChild->childName : "Scene"); break; case V_PERCENTAGE: // Dimmer value. 0 - 100 % if (pChild->GetValue(vType, intValue)) { int level = intValue; UpdateSwitch(pChild->nodeID, pChild->childID, (level != 0), level, (!pChild->childName.empty()) ? pChild->childName : "Light"); } break; case V_RGB: //RRGGBB if (pChild->GetValue(vType, intValue)) SendRGBWSwitch(pChild->nodeID, pChild->childID, pChild->batValue, intValue, false, (!pChild->childName.empty()) ? pChild->childName : "RGB Light"); break; case V_RGBW: //RRGGBBWW if (pChild->GetValue(vType, intValue)) SendRGBWSwitch(pChild->nodeID, pChild->childID, pChild->batValue, intValue, true, (!pChild->childName.empty()) ? pChild->childName : "RGBW Light"); break; case V_UP: case V_DOWN: case V_STOP: if (pChild->GetValue(vType, intValue)) SendBlindSensor(pChild->nodeID, pChild->childID, pChild->batValue, intValue, (!pChild->childName.empty()) ? pChild->childName : "Blinds/Window"); break; case V_LIGHT_LEVEL: if (pChild->GetValue(vType, floatValue)) { _tLightMeter lmeter; lmeter.id1 = 0; lmeter.id2 = 0; lmeter.id3 = 0; lmeter.id4 = pChild->nodeID; lmeter.dunit = pChild->childID; lmeter.fLux = floatValue; lmeter.battery_level = pChild->batValue; if (pChild->hasBattery) lmeter.battery_level = pChild->batValue; sDecodeRXMessage(this, (const unsigned char *)&lmeter); } break; case V_LEVEL: if (pChild->GetValue(vType, intValue)) { if (pChild->presType == S_DUST) { SendAirQualitySensor(pChild->nodeID, pChild->childID, pChild->batValue, intValue, (!pChild->childName.empty()) ? pChild->childName : "Dust"); } else if (pChild->presType == S_AIR_QUALITY) { SendAirQualitySensor(pChild->nodeID, pChild->childID, pChild->batValue, intValue, (!pChild->childName.empty()) ? pChild->childName : "Air Quality"); } else if (pChild->presType == S_LIGHT_LEVEL) { SendLuxSensor(pChild->nodeID, pChild->childID, pChild->batValue, (float)intValue, (!pChild->childName.empty()) ? pChild->childName : "Lux"); } else if (pChild->presType == S_SOUND) { SendSoundSensor(cNode, pChild->batValue, intValue, (!pChild->childName.empty()) ? pChild->childName : "Sound Level"); } else if (pChild->presType == S_MOISTURE) { SendMoistureSensor(cNode, pChild->batValue, intValue, (!pChild->childName.empty()) ? pChild->childName : "Moisture"); } } break; case V_RAIN: if (pChild->GetValue(vType, floatValue)) SendRainSensor(cNode, pChild->batValue, floatValue, (!pChild->childName.empty()) ? pChild->childName : "Rain"); break; case V_WATT: { if (pChild->GetValue(vType, floatValue)) { _tMySensorChild *pSensorKwh = pNode->FindChildWithValueType(pChild->childID, V_KWH);// FindChildWithValueType(pChild->nodeID, V_KWH); if (pSensorKwh) { float Kwh; if (pSensorKwh->GetValue(V_KWH, Kwh)) SendKwhMeter(pSensorKwh->nodeID, pSensorKwh->childID, pSensorKwh->batValue, floatValue, Kwh, (!pChild->childName.empty()) ? pChild->childName : "Meter"); } else { SendWattMeter(pChild->nodeID, pChild->childID, pChild->batValue, floatValue, (!pChild->childName.empty()) ? pChild->childName : "Usage"); } } } break; case V_KWH: if (pChild->GetValue(vType, floatValue)) { _tMySensorChild *pSensorWatt = pNode->FindChildWithValueType(pChild->childID, V_WATT);// FindChildWithValueType(pChild->nodeID, V_WATT); if (pSensorWatt) { float Watt; if (pSensorWatt->GetValue(V_WATT, Watt)) SendKwhMeter(pChild->nodeID, pChild->childID, pChild->batValue, Watt, floatValue, (!pChild->childName.empty()) ? pChild->childName : "Meter"); } else { SendKwhMeter(pChild->nodeID, pChild->childID, pChild->batValue, 0, floatValue, (!pChild->childName.empty()) ? pChild->childName : "Meter"); } } break; case V_DISTANCE: if (pChild->GetValue(vType, floatValue)) SendDistanceSensor(pChild->nodeID, pChild->childID, pChild->batValue, floatValue, (!pChild->childName.empty()) ? pChild->childName : "Distance"); break; case V_FLOW: //Flow of water/gas in meter (for now send as a percentage sensor) if (pChild->GetValue(vType, floatValue)) SendPercentageSensor(pChild->nodeID, pChild->childID, pChild->batValue, floatValue, (!pChild->childName.empty()) ? pChild->childName : "Water Flow"); break; case V_VOLUME: //Water or Gas Volume if (pChild->GetValue(vType, floatValue)) { if (pChild->presType == S_WATER) SendMeterSensor(pChild->nodeID, pChild->childID, pChild->batValue, floatValue, (!pChild->childName.empty()) ? pChild->childName : "Water"); else SendMeterSensor(pChild->nodeID, pChild->childID, pChild->batValue, floatValue, (!pChild->childName.empty()) ? pChild->childName : "Gas"); } break; case V_VOLTAGE: if (pChild->GetValue(vType, floatValue)) SendVoltageSensor(pChild->nodeID, pChild->childID, pChild->batValue, floatValue, (!pChild->childName.empty()) ? pChild->childName : "Voltage"); break; case V_UV: if (pChild->GetValue(vType, floatValue)) SendUVSensor(pChild->nodeID, pChild->childID, pChild->batValue, floatValue, (!pChild->childName.empty()) ? pChild->childName : "UV"); break; case V_IMPEDANCE: if (pChild->GetValue(vType, floatValue)) SendPercentageSensor(pChild->nodeID, pChild->childID, pChild->batValue, floatValue, (!pChild->childName.empty()) ? pChild->childName : "Impedance"); break; case V_WEIGHT: if (pChild->GetValue(vType, floatValue)) { while (1 == 0); } break; case V_CURRENT: if (pChild->GetValue(vType, floatValue)) SendCurrentSensor(cNode, pChild->batValue, floatValue, 0, 0, (!pChild->childName.empty()) ? pChild->childName : "Current"); break; case V_FORECAST: if (pChild->GetValue(vType, intValue)) { _tMySensorChild *pSensorBaro = FindChildWithValueType(pChild->nodeID, V_PRESSURE); if (pSensorBaro) { float Baro; if (pSensorBaro->GetValue(V_PRESSURE, Baro)) { int forecast = intValue; if (forecast == bmpbaroforecast_cloudy) { if (Baro < 1010) forecast = bmpbaroforecast_rain; } SendBaroSensor(pSensorBaro->nodeID, pSensorBaro->childID, pSensorBaro->batValue, Baro, forecast); } } else { if (pChild->GetValue(V_FORECAST, stringValue)) { std::stringstream sstr; sstr << pChild->nodeID; std::string devname = (!pChild->childName.empty()) ? pChild->childName : "Forecast"; m_sql.UpdateValue(m_HwdID, sstr.str().c_str(), pChild->childID, pTypeGeneral, sTypeTextStatus, 12, pChild->batValue, 0, stringValue.c_str(), devname); } } } break; case V_WIND: case V_GUST: case V_DIRECTION: MakeAndSendWindSensor(pChild->nodeID, (!pChild->childName.empty()) ? pChild->childName : "Wind"); break; case V_HVAC_SETPOINT_HEAT: if (pChild->GetValue(vType, floatValue)) SendSetPointSensor(pNode->nodeID, pChild->childID, (unsigned char)vType, floatValue, (!pChild->childName.empty()) ? pChild->childName : "Setpoint Heat"); break; case V_HVAC_SETPOINT_COOL: if (pChild->GetValue(vType, floatValue)) SendSetPointSensor(pNode->nodeID, pChild->childID, (unsigned char)vType, floatValue, (!pChild->childName.empty()) ? pChild->childName : "Setpoint Cool"); break; case V_TEXT: if (pChild->GetValue(vType, stringValue)) { SendTextSensor(pNode->nodeID, pChild->childID, pChild->batValue, stringValue, (!pChild->childName.empty()) ? pChild->childName : "Text Sensor"); } break; case V_IR_RECEIVE: if (pChild->GetValue(vType, intValue)) { _tGeneralSwitch gswitch; gswitch.subtype = sSwitchTypeMDREMOTE; gswitch.id = intValue; gswitch.unitcode = pNode->nodeID; gswitch.cmnd = gswitch_sOn; gswitch.level = 100; gswitch.battery_level = pChild->batValue; gswitch.rssi = 12; gswitch.seqnbr = 0; sDecodeRXMessage(this, (const unsigned char *)&gswitch); } break; } }
void CAnnaThermostat::GetMeterDetails() { if (m_UserName.size() == 0) return; if (m_Password.size() == 0) return; std::string sResult; #ifdef DEBUG_AnnaThermostat sResult = ReadFile("E:\\appliances.xml"); #else //Get Data std::stringstream szURL; if (m_Password.empty()) { szURL << "http://" << m_IPAddress << ":" << m_IPPort; } else { szURL << "http://" << m_UserName << ":" << m_Password << "@" << m_IPAddress << ":" << m_IPPort; } szURL << ANNA_GET_STATUS; if (!HTTPClient::GET(szURL.str(), sResult)) { _log.Log(LOG_ERROR, "AnnaThermostat: Error getting current state!"); return; } #endif if (sResult.empty()) { _log.Log(LOG_ERROR, "AnnaThermostat: Invalid data received!"); return; } stdreplace(sResult, "\r\n", ""); TiXmlDocument doc; if (doc.Parse(sResult.c_str())) { _log.Log(LOG_ERROR, "AnnaThermostat: Invalid data received!"); return; } TiXmlElement *pRoot; TiXmlElement *pAppliance, *pElem; TiXmlAttribute *pAttribute; std::string sname, tmpstr; pRoot = doc.FirstChildElement("appliances"); if (!pRoot) { _log.Log(LOG_ERROR, "AnnaThermostat: Invalid data received!"); return; } pAppliance = pRoot->FirstChildElement("appliance"); while (pAppliance) { TiXmlHandle hAppliance = TiXmlHandle(pAppliance); pElem = pAppliance->FirstChildElement("name"); if (pElem == NULL) { _log.Log(LOG_ERROR, "AnnaThermostat: Invalid data received!"); return; } std::string ApplianceName=pElem->GetText(); if ((m_ThermostatID.empty()) && (ApplianceName == "Anna")) { pAttribute = pAppliance->FirstAttribute(); if (pAttribute != NULL) { std::string aName = pAttribute->Name(); if (aName == "id") { m_ThermostatID = pAttribute->Value(); } } } //Handle point_log pElem = hAppliance.FirstChild("logs").FirstChild().Element(); if (!pElem) { _log.Log(LOG_ERROR, "AnnaThermostat: Invalid data received!"); return; } TiXmlHandle hLogs = TiXmlHandle(pElem); pElem = hAppliance.FirstChild("logs").Child("point_log", 0).ToElement(); if (!pElem) { _log.Log(LOG_ERROR, "AnnaThermostat: Invalid data received!"); return; } for (pElem; pElem; pElem = pElem->NextSiblingElement()) { sname = GetElementChildValue(pElem, "type"); if (sname == "temperature") { tmpstr = GetPeriodMeasurement(pElem); if (!tmpstr.empty()) { float temperature = (float)atof(tmpstr.c_str()); SendTempSensor(1, 255, temperature, sname); } } else if (sname == "illuminance") { tmpstr = GetPeriodMeasurement(pElem); if (!tmpstr.empty()) { float illuminance = (float)atof(tmpstr.c_str()); SendLuxSensor(2, 1, 255, illuminance, sname); } } else if (sname == "thermostat") { tmpstr = GetPeriodMeasurement(pElem); if (!tmpstr.empty()) { float temperature = (float)atof(tmpstr.c_str()); SendSetPointSensor(3, temperature, sname); } } /* else if (sname == "intended_boiler_temperature") { tmpstr = GetPeriodMeasurement(pElem); if (!tmpstr.empty()) { float temperature = (float)atof(tmpstr.c_str()); SendTempSensor(4, 255, temperature, sname); } } */ else if (sname == "return_water_temperature") { tmpstr = GetPeriodMeasurement(pElem); if (!tmpstr.empty()) { float temperature = (float)atof(tmpstr.c_str()); SendTempSensor(5, 255, temperature, sname); } } else if (sname == "boiler_temperature") { tmpstr = GetPeriodMeasurement(pElem); if (!tmpstr.empty()) { float temperature = (float)atof(tmpstr.c_str()); SendTempSensor(6, 255, temperature, sname); } } else if (sname == "maximum_boiler_temperature") { tmpstr = GetPeriodMeasurement(pElem); if (!tmpstr.empty()) { float temperature = (float)atof(tmpstr.c_str()); SendTempSensor(7, 255, temperature, sname); } } } pAppliance = pAppliance->NextSiblingElement("appliance"); } return; }