コード例 #1
0
ファイル: ETH8020.cpp プロジェクト: Rimco/domoticz
void CETH8020::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 << "/status.xml";

	if (!HTTPClient::GET(szURL.str(),sResult))
	{
		_log.Log(LOG_ERROR,"ETH8020: Error connecting to: %s", m_szIPAddress.c_str());
		return;
	}
	std::vector<std::string> results;
	StringSplit(sResult, "\r\n", results);
	if (results.size()<8)
	{
		_log.Log(LOG_ERROR,"ETH8020: Error connecting to: %s", m_szIPAddress.c_str());
		return;
	}
	if (results[0] != "<response>")
	{
		_log.Log(LOG_ERROR, "ETH8020: Error getting status");
		return;
	}
	size_t ii;
	std::string tmpstr;
	int pos1;
	int Idx = 0;
	for (ii = 1; ii < results.size(); ii++)
	{
		tmpstr = results[ii];
		if (tmpstr.find("<relay") != std::string::npos)
		{
			tmpstr = tmpstr.substr(strlen("<relay"));
			pos1 = tmpstr.find(">");
			if (pos1 != std::string::npos)
			{
				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());
					std::stringstream sstr;
					sstr << "Relay " << Idx;
					UpdateSwitch(1, Idx, (lValue == 1) ? true : false, 100, sstr.str());
				}
			}
		}
		else if (tmpstr.find("<adc") != std::string::npos)
		{
			tmpstr = tmpstr.substr(strlen("<adc"));
			pos1 = tmpstr.find(">");
			if (pos1 != std::string::npos)
			{
				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;
					SendVoltage(Idx, voltage, sstr.str());
				}
			}
		}
	}
}
コード例 #2
0
ファイル: PVOutput_Input.cpp プロジェクト: remb0/domoticz
void CPVOutputInput::GetMeterDetails()
{
	if (m_SID.size()==0)
		return;
	if (m_KEY.size()==0)
		return;

	std::string sResult;

	std::stringstream sstr;
	sstr << "http://pvoutput.org/service/r2/getstatus.jsp?sid=" << m_SID << "&key=" << m_KEY;
	if (!HTTPClient::GET(sstr.str(),sResult))
	{
		_log.Log(LOG_ERROR,"PVOutput (Input): Error login!");
		return;
	}
	std::vector<std::string> splitresult;
	StringSplit(sResult,",",splitresult);
	if (splitresult.size()<9)
	{
		_log.Log(LOG_ERROR,"PVOutput (Input): Invalid Data received!");
		return;
	}

	double Usage=atof(splitresult[3].c_str());
	if (Usage < 0)
		Usage = 0;

	bool bHaveConsumption=false;
	double Consumption=0;
	if (splitresult[5]!="NaN")
	{
		Consumption=atof(splitresult[5].c_str());
		if (Consumption < 0)
			Consumption = 0;
		bHaveConsumption=true;
	}

	if (splitresult[6]!="NaN")
	{
		double Efficiency=atof(splitresult[6].c_str())*100.0;
		if (Efficiency>100.0)
			Efficiency=100.0;
		SendPercentage(1,float(Efficiency),"Efficiency");
	}
	if (splitresult[7]!="NaN")
	{
		double Temperature=atof(splitresult[7].c_str());
		SendTempSensor(1,float(Temperature),"Temperature");
	}
	if (splitresult[8]!="NaN")
	{
		double Voltage=atof(splitresult[8].c_str());
		if (Voltage>=0)
			SendVoltage(1,float(Voltage),"Voltage");
	}

	sstr.clear();
	sstr.str("");

	sstr << "http://pvoutput.org/service/r2/getstatistic.jsp?sid=" << m_SID << "&key=" << m_KEY << "&c=1";
	if (!HTTPClient::GET(sstr.str(),sResult))
	{
		_log.Log(LOG_ERROR,"PVOutput (Input): Error login!");
		return;
	}
	StringSplit(sResult,",",splitresult);
	if (splitresult.size()<11)
	{
		_log.Log(LOG_ERROR,"PVOutput (Input): Invalid Data received!");
		return;
	}

	double kWhCounterUsage=atof(splitresult[0].c_str());
	SendMeter(0, 1, Usage / 1000.0, kWhCounterUsage / 1000.0, "SolarMain");

	if (bHaveConsumption)
	{
		if (splitresult.size() > 11)
		{
			double kWhCounterConsumed = atof(splitresult[11].c_str());
			if (kWhCounterConsumed != 0)
			{
				SendMeter(0, 2, Consumption / 1000.0, kWhCounterConsumed / 1000.0, "SolarConsumed");
			}
		}
	}
}