示例#1
0
void CDomoticzHardwareBase::SendTempHumBaroSensor(const int NodeID, const int BatteryLevel, const float temperature, const int humidity, const float pressure, int forecast)
{
	RBUF tsen;
	memset(&tsen, 0, sizeof(RBUF));
	tsen.TEMP_HUM_BARO.packetlength = sizeof(tsen.TEMP_HUM_BARO) - 1;
	tsen.TEMP_HUM_BARO.packettype = pTypeTEMP_HUM_BARO;
	tsen.TEMP_HUM_BARO.subtype = sTypeTHB1;
	tsen.TEMP_HUM_BARO.battery_level = BatteryLevel;
	tsen.TEMP_HUM_BARO.rssi = 12;
	tsen.TEMP_HUM_BARO.id1 = (NodeID & 0xFF00) >> 8;
	tsen.TEMP_HUM_BARO.id2 = NodeID & 0xFF;

	tsen.TEMP_HUM_BARO.tempsign = (temperature >= 0) ? 0 : 1;
	int at10 = round(abs(temperature*10.0f));
	tsen.TEMP_HUM_BARO.temperatureh = (BYTE)(at10 / 256);
	at10 -= (tsen.TEMP_HUM_BARO.temperatureh * 256);
	tsen.TEMP_HUM_BARO.temperaturel = (BYTE)(at10);
	tsen.TEMP_HUM_BARO.humidity = (BYTE)humidity;
	tsen.TEMP_HUM_BARO.humidity_status = Get_Humidity_Level(tsen.TEMP_HUM.humidity);

	int ab10 = round(pressure);
	tsen.TEMP_HUM_BARO.baroh = (BYTE)(ab10 / 256);
	ab10 -= (tsen.TEMP_HUM_BARO.baroh * 256);
	tsen.TEMP_HUM_BARO.barol = (BYTE)(ab10);

	tsen.TEMP_HUM_BARO.forecast = (BYTE)forecast;

	sDecodeRXMessage(this, (const unsigned char *)&tsen.TEMP_HUM_BARO);
}
示例#2
0
void C1Wire::ReportTemperatureHumidity(const std::string& deviceId,float temperature,float humidity)
{
	if ((temperature == -1000.0) || (humidity == -1000.0))
		return;
	unsigned char deviceIdByteArray[DEVICE_ID_SIZE]={0};
	DeviceIdToByteArray(deviceId,deviceIdByteArray);

	RBUF tsen;
	memset(&tsen,0,sizeof(RBUF));
	tsen.TEMP_HUM.packetlength=sizeof(tsen.TEMP_HUM)-1;
	tsen.TEMP_HUM.packettype=pTypeTEMP_HUM;
	tsen.TEMP_HUM.subtype=sTypeTH5;
	tsen.TEMP_HUM.battery_level=9;
	tsen.TEMP_HUM.rssi=12;
	tsen.TEMP.id1=(BYTE)deviceIdByteArray[0];
	tsen.TEMP.id2=(BYTE)deviceIdByteArray[1];

	tsen.TEMP_HUM.tempsign=(temperature>=0)?0:1;
	int at10=round(abs(temperature*10.0f));
	tsen.TEMP_HUM.temperatureh=(BYTE)(at10/256);
	at10-=(tsen.TEMP_HUM.temperatureh*256);
	tsen.TEMP_HUM.temperaturel=(BYTE)(at10);
	tsen.TEMP_HUM.humidity=(BYTE)round(humidity);
	tsen.TEMP_HUM.humidity_status=Get_Humidity_Level(tsen.TEMP_HUM.humidity);

	sDecodeRXMessage(this, (const unsigned char *)&tsen.TEMP_HUM, NULL, 255);
}
示例#3
0
void CDomoticzHardwareBase::SendHumiditySensor(const int NodeID, const int BatteryLevel, const int humidity)
{
	RBUF tsen;
	memset(&tsen, 0, sizeof(RBUF));
	tsen.HUM.packetlength = sizeof(tsen.HUM) - 1;
	tsen.HUM.packettype = pTypeHUM;
	tsen.HUM.subtype = sTypeHUM1;
	tsen.HUM.battery_level = BatteryLevel;
	tsen.HUM.rssi = 12;
	tsen.HUM.id1 = (NodeID & 0xFF00) >> 8;
	tsen.HUM.id2 = NodeID & 0xFF;
	tsen.HUM.humidity = (BYTE)humidity;
	tsen.HUM.humidity_status = Get_Humidity_Level(tsen.HUM.humidity);
	sDecodeRXMessage(this, (const unsigned char *)&tsen.HUM);
}
示例#4
0
void CDomoticzHardwareBase::SendTempHumBaroSensorFloat(const int NodeID, const int BatteryLevel, const float temperature, const int humidity, const float pressure, int forecast, const std::string &defaultname)
{
	char szIdx[10];
	sprintf(szIdx, "%d", NodeID & 0xFFFF);
	int Unit = NodeID & 0xFF;

	std::vector<std::vector<std::string> > result;
	bool bDeviceExits = true;
	result = m_sql.safe_query("SELECT Name FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID=='%q') AND (Unit == %d) AND (Type==%d) AND (Subtype==%d)",
		m_HwdID, szIdx, Unit, int(pTypeTEMP_HUM_BARO), int(sTypeTHBFloat));
	if (result.size() < 1)
	{
		bDeviceExits = false;
	}

	RBUF tsen;
	memset(&tsen, 0, sizeof(RBUF));
	tsen.TEMP_HUM_BARO.packetlength = sizeof(tsen.TEMP_HUM_BARO) - 1;
	tsen.TEMP_HUM_BARO.packettype = pTypeTEMP_HUM_BARO;
	tsen.TEMP_HUM_BARO.subtype = sTypeTHBFloat;
	tsen.TEMP_HUM_BARO.battery_level = 9;
	tsen.TEMP_HUM_BARO.rssi = 12;
	tsen.TEMP_HUM_BARO.id1 = (NodeID & 0xFF00) >> 8;
	tsen.TEMP_HUM_BARO.id2 = NodeID & 0xFF;

	tsen.TEMP_HUM_BARO.tempsign = (temperature >= 0) ? 0 : 1;
	int at10 = round(abs(temperature*10.0f));
	tsen.TEMP_HUM_BARO.temperatureh = (BYTE)(at10 / 256);
	at10 -= (tsen.TEMP_HUM_BARO.temperatureh * 256);
	tsen.TEMP_HUM_BARO.temperaturel = (BYTE)(at10);
	tsen.TEMP_HUM_BARO.humidity = (BYTE)humidity;
	tsen.TEMP_HUM_BARO.humidity_status = Get_Humidity_Level(tsen.TEMP_HUM.humidity);

	int ab10 = round(pressure*10.0f);
	tsen.TEMP_HUM_BARO.baroh = (BYTE)(ab10 / 256);
	ab10 -= (tsen.TEMP_HUM_BARO.baroh * 256);
	tsen.TEMP_HUM_BARO.barol = (BYTE)(ab10);
	tsen.TEMP_HUM_BARO.forecast = forecast;

	sDecodeRXMessage(this, (const unsigned char *)&tsen.TEMP_HUM_BARO);

	if (!bDeviceExits)
	{
		//Assign default name for device
		m_sql.safe_query("UPDATE DeviceStatus SET Name='%q' WHERE (HardwareID==%d) AND (DeviceID=='%q') AND (Unit == %d) AND (Type==%d) AND (Subtype==%d)",
			defaultname.c_str(), m_HwdID, szIdx, Unit, int(pTypeTEMP_HUM_BARO), int(sTypeTHBFloat));
	}
}
示例#5
0
void CDavisLoggerSerial::UpdateHumSensor(const unsigned char Idx, const int Hum)
{
	RBUF tsen;
	memset(&tsen,0,sizeof(RBUF));

	tsen.HUM.packetlength=sizeof(tsen.HUM)-1;
	tsen.HUM.packettype=pTypeHUM;
	tsen.HUM.subtype=sTypeHUM2;
	tsen.HUM.battery_level=9;
	tsen.HUM.rssi=12;
	tsen.HUM.id1=0;
	tsen.HUM.id2=Idx;

	tsen.HUM.humidity=(BYTE)Hum;
	tsen.HUM.humidity_status=Get_Humidity_Level(tsen.HUM.humidity);

	sDecodeRXMessage(this, (const unsigned char *)&tsen.HUM);//decode message
}
示例#6
0
文件: 1Wire.cpp 项目: ZaaaV/domoticz
void C1Wire::ReportHumidity(const std::string& deviceId,float humidity)
{
   unsigned char deviceIdByteArray[DEVICE_ID_SIZE]={0};
   DeviceIdToByteArray(deviceId,deviceIdByteArray);

   RBUF tsen;
   memset(&tsen,0,sizeof(RBUF));
   tsen.HUM.packetlength=sizeof(tsen.HUM)-1;
   tsen.HUM.packettype=pTypeHUM;
   tsen.HUM.subtype=sTypeHUM2;
   tsen.HUM.battery_level=9;
   tsen.HUM.rssi=12;
   tsen.TEMP.id1=(BYTE)deviceIdByteArray[0];
   tsen.TEMP.id2=(BYTE)deviceIdByteArray[1];

   tsen.HUM.humidity=(BYTE)round(humidity);
   tsen.HUM.humidity_status=Get_Humidity_Level(tsen.HUM.humidity);

   sDecodeRXMessage(this, (const unsigned char *)&tsen.HUM);//decode message
}
示例#7
0
void Meteostick::SendTempHumSensor(const unsigned char Idx, const float Temp, const int Hum, const std::string &defaultname)
{
	bool bDeviceExits = true;
	std::stringstream szQuery;
	std::vector<std::vector<std::string> > result;
	szQuery << "SELECT Name FROM DeviceStatus WHERE (HardwareID==" << m_HwdID << ") AND (DeviceID==" << int(Idx) << ") AND (Type==" << int(pTypeTEMP_HUM) << ") AND (Subtype==" << int(sTypeTH5) << ")";
	result = m_sql.query(szQuery.str());
	if (result.size() < 1)
	{
		bDeviceExits = false;
	}

	RBUF tsen;
	memset(&tsen, 0, sizeof(RBUF));
	tsen.TEMP_HUM.packetlength = sizeof(tsen.TEMP_HUM) - 1;
	tsen.TEMP_HUM.packettype = pTypeTEMP_HUM;
	tsen.TEMP_HUM.subtype = sTypeTH5;
	tsen.TEMP_HUM.battery_level = 9;
	tsen.TEMP_HUM.rssi = 12;
	tsen.TEMP_HUM.id1 = 0;
	tsen.TEMP_HUM.id2 = Idx;

	tsen.TEMP_HUM.tempsign = (Temp >= 0) ? 0 : 1;
	int at10 = round(abs(Temp*10.0f));
	tsen.TEMP_HUM.temperatureh = (BYTE)(at10 / 256);
	at10 -= (tsen.TEMP_HUM.temperatureh * 256);
	tsen.TEMP_HUM.temperaturel = (BYTE)(at10);
	tsen.TEMP_HUM.humidity = (BYTE)Hum;
	tsen.TEMP_HUM.humidity_status = Get_Humidity_Level(tsen.TEMP_HUM.humidity);

	sDecodeRXMessage(this, (const unsigned char *)&tsen.TEMP_HUM);

	if (!bDeviceExits)
	{
		//Assign default name for device
		szQuery.clear();
		szQuery.str("");
		szQuery << "UPDATE DeviceStatus SET Name='" << defaultname << "' WHERE (HardwareID==" << m_HwdID << ") AND (DeviceID==" << int(Idx) << ") AND (Type==" << int(pTypeTEMP_HUM) << ") AND (Subtype==" << int(sTypeTH5) << ")";
		result = m_sql.query(szQuery.str());
	}
}
示例#8
0
void Meteostick::SendTempHumSensor(const unsigned char Idx, const float Temp, const int Hum, const std::string &defaultname)
{
	RBUF tsen;
	memset(&tsen, 0, sizeof(RBUF));
	tsen.TEMP_HUM.packetlength = sizeof(tsen.TEMP_HUM) - 1;
	tsen.TEMP_HUM.packettype = pTypeTEMP_HUM;
	tsen.TEMP_HUM.subtype = sTypeTH5;
	tsen.TEMP_HUM.battery_level = 9;
	tsen.TEMP_HUM.rssi = 12;
	tsen.TEMP_HUM.id1 = 0;
	tsen.TEMP_HUM.id2 = Idx;

	tsen.TEMP_HUM.tempsign = (Temp >= 0) ? 0 : 1;
	int at10 = round(abs(Temp*10.0f));
	tsen.TEMP_HUM.temperatureh = (BYTE)(at10 / 256);
	at10 -= (tsen.TEMP_HUM.temperatureh * 256);
	tsen.TEMP_HUM.temperaturel = (BYTE)(at10);
	tsen.TEMP_HUM.humidity = (BYTE)Hum;
	tsen.TEMP_HUM.humidity_status = Get_Humidity_Level(tsen.TEMP_HUM.humidity);

	sDecodeRXMessage(this, (const unsigned char *)&tsen.TEMP_HUM, defaultname.c_str());
}
示例#9
0
void CDavisLoggerSerial::UpdateTempHumSensor(const unsigned char Idx, const float Temp, const int Hum)
{
	RBUF tsen;
	memset(&tsen,0,sizeof(RBUF));
	tsen.TEMP_HUM.packetlength=sizeof(tsen.TEMP_HUM)-1;
	tsen.TEMP_HUM.packettype=pTypeTEMP_HUM;
	tsen.TEMP_HUM.subtype=sTypeTH5;
	tsen.TEMP_HUM.battery_level=9;
	tsen.TEMP_HUM.rssi=12;
	tsen.TEMP_HUM.id1=0;
	tsen.TEMP_HUM.id2=Idx;

	tsen.TEMP_HUM.tempsign=(Temp>=0)?0:1;
	int at10=round(abs(Temp*10.0f));
	tsen.TEMP_HUM.temperatureh=(BYTE)(at10/256);
	at10-=(tsen.TEMP_HUM.temperatureh*256);
	tsen.TEMP_HUM.temperaturel=(BYTE)(at10);
	tsen.TEMP_HUM.humidity=(BYTE)Hum;
	tsen.TEMP_HUM.humidity_status=Get_Humidity_Level(tsen.TEMP_HUM.humidity);

	sDecodeRXMessage(this, (const unsigned char *)&tsen.TEMP_HUM);//decode message
}
示例#10
0
void CDomoticzHardwareBase::SendTempHumSensor(const int NodeID, const int BatteryLevel, const float temperature, const int humidity, const std::string &defaultname)
{
	RBUF tsen;
	memset(&tsen, 0, sizeof(RBUF));
	tsen.TEMP_HUM.packetlength = sizeof(tsen.TEMP_HUM) - 1;
	tsen.TEMP_HUM.packettype = pTypeTEMP_HUM;
	tsen.TEMP_HUM.subtype = sTypeTH5;
	tsen.TEMP_HUM.battery_level = BatteryLevel;
	tsen.TEMP_HUM.rssi = 12;
	tsen.TEMP_HUM.id1 = (NodeID&0xFF00)>>8;
	tsen.TEMP_HUM.id2 = NodeID & 0xFF;

	tsen.TEMP_HUM.tempsign = (temperature >= 0) ? 0 : 1;
	int at10 = round(abs(temperature*10.0f));
	tsen.TEMP_HUM.temperatureh = (BYTE)(at10 / 256);
	at10 -= (tsen.TEMP_HUM.temperatureh * 256);
	tsen.TEMP_HUM.temperaturel = (BYTE)(at10);
	tsen.TEMP_HUM.humidity = (BYTE)humidity;
	tsen.TEMP_HUM.humidity_status = Get_Humidity_Level(tsen.TEMP_HUM.humidity);

	sDecodeRXMessage(this, (const unsigned char *)&tsen.TEMP_HUM, defaultname.c_str(), BatteryLevel);
}
示例#11
0
void CWunderground::GetMeterDetails()
{
	std::string sResult;
#ifdef DEBUG_WUNDERGROUND
	sResult=readWUndergroundTestFile("E:\\underground.json");
#else
	std::stringstream sURL;
	std::string szLoc = CURLEncode::URLEncode(m_Location);
	sURL << "http://api.wunderground.com/api/" << m_APIKey << "/conditions/q/" << szLoc << ".json";
	bool bret;
	std::string szURL=sURL.str();
	bret=HTTPClient::GET(szURL,sResult);
	if (!bret)
	{
		_log.Log(LOG_ERROR,"Wunderground: Error getting http data!");
		return;
	}

#endif
	Json::Value root;

	Json::Reader jReader;
	bool ret=jReader.parse(sResult,root);
	if (!ret)
	{
		_log.Log(LOG_ERROR,"WUnderground: Invalid data received!");
		return;
	}
	if (root["current_observation"].empty()==true)
	{
		_log.Log(LOG_ERROR,"WUnderground: Invalid data received, or unknown location!");
		return;
	}
	std::string tmpstr;
	int pos;
	float temp;
	int humidity=0;
	int barometric=0;
	int barometric_forcast=baroForecastNoInfo;

	temp=root["current_observation"]["temp_c"].asFloat();

	if (root["current_observation"]["relative_humidity"].empty()==false)
	{
		tmpstr=root["current_observation"]["relative_humidity"].asString();
		pos=tmpstr.find("%");
		if (pos==std::string::npos)
		{
			_log.Log(LOG_ERROR,"WUnderground: Invalid data received!");
			return;
		}
		humidity=atoi(tmpstr.substr(0,pos).c_str());
	}
	if (root["current_observation"]["pressure_mb"].empty()==false)
	{
		barometric=atoi(root["current_observation"]["pressure_mb"].asString().c_str());
		if (barometric<1000)
			barometric_forcast=baroForecastRain;
		else if (barometric<1020)
			barometric_forcast=baroForecastCloudy;
		else if (barometric<1030)
			barometric_forcast=baroForecastPartlyCloudy;
		else
			barometric_forcast=baroForecastSunny;

		if (root["current_observation"]["icon"].empty()==false)
		{
			std::string forcasticon=root["current_observation"]["icon"].asString();
			if (forcasticon=="partlycloudy")
			{
				barometric_forcast=baroForecastPartlyCloudy;
			}
			else if (forcasticon=="cloudy")
			{
				barometric_forcast=baroForecastCloudy;
			}
			else if (forcasticon=="sunny")
			{
				barometric_forcast=baroForecastSunny;
			}
			else if (forcasticon=="rain")
			{
				barometric_forcast=baroForecastRain;
			}
		}

	}

	if (barometric!=0)
	{
		//Add temp+hum+baro device
		RBUF tsen;
		memset(&tsen,0,sizeof(RBUF));
		tsen.TEMP_HUM_BARO.packetlength=sizeof(tsen.TEMP_HUM_BARO)-1;
		tsen.TEMP_HUM_BARO.packettype=pTypeTEMP_HUM_BARO;
		tsen.TEMP_HUM_BARO.subtype=sTypeTHB1;
		tsen.TEMP_HUM_BARO.battery_level=9;
		tsen.TEMP_HUM_BARO.rssi=12;
		tsen.TEMP_HUM_BARO.id1=0;
		tsen.TEMP_HUM_BARO.id2=1;

		tsen.TEMP_HUM_BARO.tempsign=(temp>=0)?0:1;
		int at10=round(abs(temp*10.0f));
		tsen.TEMP_HUM_BARO.temperatureh=(BYTE)(at10/256);
		at10-=(tsen.TEMP_HUM_BARO.temperatureh*256);
		tsen.TEMP_HUM_BARO.temperaturel=(BYTE)(at10);
		tsen.TEMP_HUM_BARO.humidity=(BYTE)humidity;
		tsen.TEMP_HUM_BARO.humidity_status=Get_Humidity_Level(tsen.TEMP_HUM.humidity);

		int ab10=round(barometric);
		tsen.TEMP_HUM_BARO.baroh=(BYTE)(ab10/256);
		ab10-=(tsen.TEMP_HUM_BARO.baroh*256);
		tsen.TEMP_HUM_BARO.barol=(BYTE)(ab10);
		
		tsen.TEMP_HUM_BARO.forecast=barometric_forcast;


		sDecodeRXMessage(this, (const unsigned char *)&tsen.TEMP_HUM_BARO);//decode message
	}
	else if (humidity!=0)
	{
		//add temp+hum device
		RBUF tsen;
		memset(&tsen,0,sizeof(RBUF));
		tsen.TEMP_HUM.packetlength=sizeof(tsen.TEMP_HUM)-1;
		tsen.TEMP_HUM.packettype=pTypeTEMP_HUM;
		tsen.TEMP_HUM.subtype=sTypeTH5;
		tsen.TEMP_HUM.battery_level=9;
		tsen.TEMP_HUM.rssi=12;
		tsen.TEMP_HUM.id1=0;
		tsen.TEMP_HUM.id2=1;

		tsen.TEMP_HUM.tempsign=(temp>=0)?0:1;
		int at10=round(abs(temp*10.0f));
		tsen.TEMP_HUM.temperatureh=(BYTE)(at10/256);
		at10-=(tsen.TEMP_HUM.temperatureh*256);
		tsen.TEMP_HUM.temperaturel=(BYTE)(at10);
		tsen.TEMP_HUM.humidity=(BYTE)humidity;
		tsen.TEMP_HUM.humidity_status=Get_Humidity_Level(tsen.TEMP_HUM.humidity);

		sDecodeRXMessage(this, (const unsigned char *)&tsen.TEMP_HUM);//decode message
	}
	else
	{
		//add temp device
		RBUF tsen;
		memset(&tsen,0,sizeof(RBUF));
		tsen.TEMP.packetlength=sizeof(tsen.TEMP)-1;
		tsen.TEMP.packettype=pTypeTEMP;
		tsen.TEMP.subtype=sTypeTEMP10;
		tsen.TEMP.battery_level=9;
		tsen.TEMP.rssi=12;
		tsen.TEMP.id1=0;
		tsen.TEMP.id2=1;

		tsen.TEMP.tempsign=(temp>=0)?0:1;
		int at10=round(abs(temp*10.0f));
		tsen.TEMP.temperatureh=(BYTE)(at10/256);
		at10-=(tsen.TEMP.temperatureh*256);
		tsen.TEMP.temperaturel=(BYTE)(at10);

		sDecodeRXMessage(this, (const unsigned char *)&tsen.TEMP);//decode message
	}

	//Wind
	int wind_degrees=-1;
	float wind_mph=-1;
	float wind_gust_mph=-1;
	float windspeed_ms=0;
	float windgust_ms=0;
	float wind_temp=temp;
	float wind_chill=temp;
	int windgust=1;
	float windchill=-1;

	if (root["current_observation"]["wind_degrees"].empty()==false)
	{
		wind_degrees=atoi(root["current_observation"]["wind_degrees"].asString().c_str());
	}
	if (root["current_observation"]["wind_mph"].empty()==false)
	{
		if (root["current_observation"]["wind_mph"]!="N/A")
		{
			float temp_wind_mph = static_cast<float>(atof(root["current_observation"]["wind_mph"].asString().c_str()));
			if (temp_wind_mph!=-9999.00f)
			{
				wind_mph=temp_wind_mph;
				//convert to m/s
				windspeed_ms=wind_mph*0.44704f;
			}
		}
	}
	if (root["current_observation"]["wind_gust_mph"].empty()==false)
	{
		if (root["current_observation"]["wind_gust_mph"]!="N/A")
		{
			float temp_wind_gust_mph = static_cast<float>(atof(root["current_observation"]["wind_gust_mph"].asString().c_str()));
			if (temp_wind_gust_mph!=-9999.00f)
			{
				wind_gust_mph=temp_wind_gust_mph;
				//convert to m/s
				windgust_ms=wind_gust_mph*0.44704f;
			}
		}
	}
	if (root["current_observation"]["feelslike_c"].empty()==false)
	{
		if (root["current_observation"]["feelslike_c"]!="N/A")
		{
			wind_chill = static_cast<float>(atof(root["current_observation"]["feelslike_c"].asString().c_str()));
		}
	}
	if (wind_degrees!=-1)
	{
		RBUF tsen;
		memset(&tsen,0,sizeof(RBUF));
		tsen.WIND.packetlength=sizeof(tsen.WIND)-1;
		tsen.WIND.packettype=pTypeWIND;
		tsen.WIND.subtype=sTypeWIND4;
		tsen.WIND.battery_level=9;
		tsen.WIND.rssi=12;
		tsen.WIND.id1=0;
		tsen.WIND.id2=1;

		float winddir=float(wind_degrees);
		int aw=round(winddir);
		tsen.WIND.directionh=(BYTE)(aw/256);
		aw-=(tsen.WIND.directionh*256);
		tsen.WIND.directionl=(BYTE)(aw);

		tsen.WIND.av_speedh=0;
		tsen.WIND.av_speedl=0;
		int sw=round(windspeed_ms*10.0f);
		tsen.WIND.av_speedh=(BYTE)(sw/256);
		sw-=(tsen.WIND.av_speedh*256);
		tsen.WIND.av_speedl=(BYTE)(sw);

		tsen.WIND.gusth=0;
		tsen.WIND.gustl=0;
		int gw=round(windgust_ms*10.0f);
		tsen.WIND.gusth=(BYTE)(gw/256);
		gw-=(tsen.WIND.gusth*256);
		tsen.WIND.gustl=(BYTE)(gw);

		//this is not correct, why no wind temperature? and only chill?
		tsen.WIND.chillh=0;
		tsen.WIND.chilll=0;
		tsen.WIND.temperatureh=0;
		tsen.WIND.temperaturel=0;

		tsen.WIND.tempsign=(wind_temp>=0)?0:1;
		int at10=round(abs(wind_temp*10.0f));
		tsen.WIND.temperatureh=(BYTE)(at10/256);
		at10-=(tsen.WIND.temperatureh*256);
		tsen.WIND.temperaturel=(BYTE)(at10);

		tsen.WIND.chillsign=(wind_temp>=0)?0:1;
		at10=round(abs(wind_chill*10.0f));
		tsen.WIND.chillh=(BYTE)(at10/256);
		at10-=(tsen.WIND.chillh*256);
		tsen.WIND.chilll=(BYTE)(at10);

		sDecodeRXMessage(this, (const unsigned char *)&tsen.WIND);//decode message
	}

	//UV
	if (root["current_observation"]["UV"].empty()==false)
	{
		if (root["current_observation"]["UV"]!="N/A")
		{
			float UV = static_cast<float>(atof(root["current_observation"]["UV"].asString().c_str()));
			if ((UV<16)&&(UV>=0))
			{
				RBUF tsen;
				memset(&tsen,0,sizeof(RBUF));
				tsen.UV.packetlength=sizeof(tsen.UV)-1;
				tsen.UV.packettype=pTypeUV;
				tsen.UV.subtype=sTypeUV1;
				tsen.UV.battery_level=9;
				tsen.UV.rssi=12;
				tsen.UV.id1=0;
				tsen.UV.id2=1;

				tsen.UV.uv=(BYTE)round(UV*10);
				sDecodeRXMessage(this, (const unsigned char *)&tsen.UV);//decode message
			}
		}
	}

	//Rain
	if (root["current_observation"]["precip_today_metric"].empty()==false)
	{
		if (root["current_observation"]["precip_today_metric"]!="N/A")
		{
			float RainCount = static_cast<float>(atof(root["current_observation"]["precip_today_metric"].asString().c_str()));
			if ((RainCount!=-9999.00f)&&(RainCount>=0.00f))
			{
				RBUF tsen;
				memset(&tsen,0,sizeof(RBUF));
				tsen.RAIN.packetlength=sizeof(tsen.RAIN)-1;
				tsen.RAIN.packettype=pTypeRAIN;
				tsen.RAIN.subtype=sTypeRAINWU;
				tsen.RAIN.battery_level=9;
				tsen.RAIN.rssi=12;
				tsen.RAIN.id1=0;
				tsen.RAIN.id2=1;

				tsen.RAIN.rainrateh=0;
				tsen.RAIN.rainratel=0;

				if (root["current_observation"]["precip_1hr_metric"].empty()==false)
				{
					if (root["current_observation"]["precip_1hr_metric"]!="N/A")
					{
						float rainrateph = static_cast<float>(atof(root["current_observation"]["precip_1hr_metric"].asString().c_str()));
						if (rainrateph!=-9999.00f)
						{
							int at10=round(abs(rainrateph*10.0f));
							tsen.RAIN.rainrateh=(BYTE)(at10/256);
							at10-=(tsen.RAIN.rainrateh*256);
							tsen.RAIN.rainratel=(BYTE)(at10);
						}
					}
				}

				int tr10=int((float(RainCount)*10.0f));
				tsen.RAIN.raintotal1=0;
				tsen.RAIN.raintotal2=(BYTE)(tr10/256);
				tr10-=(tsen.RAIN.raintotal2*256);
				tsen.RAIN.raintotal3=(BYTE)(tr10);

				sDecodeRXMessage(this, (const unsigned char *)&tsen.RAIN);//decode message
			}
		}
	}

	//Visibility
	if (root["current_observation"]["visibility_km"].empty()==false)
	{
		if (root["current_observation"]["visibility_km"]!="N/A")
		{
			float visibility = static_cast<float>(atof(root["current_observation"]["visibility_km"].asString().c_str()));
			if (visibility>=0)
			{
				_tGeneralDevice gdevice;
				gdevice.subtype=sTypeVisibility;
				gdevice.floatval1=visibility;
				sDecodeRXMessage(this, (const unsigned char *)&gdevice);
			}
		}
	}
	//Solar Radiation
	if (root["current_observation"]["solarradiation"].empty()==false)
	{
		if (root["current_observation"]["solarradiation"]!="N/A")
		{
			float radiation = static_cast<float>(atof(root["current_observation"]["solarradiation"].asString().c_str()));
			if (radiation>=0.0f)
			{
				_tGeneralDevice gdevice;
				gdevice.subtype=sTypeSolarRadiation;
				gdevice.floatval1=radiation;
				sDecodeRXMessage(this, (const unsigned char *)&gdevice);
			}
		}
	}

}
示例#12
0
void CTE923::GetSensorDetails()
{
	Te923DataSet_t data;
	Te923DevSet_t dev;
#ifndef _DEBUG
	CTE923Tool _te923tool;
	if (!_te923tool.OpenDevice())
	{
		return;
	}
	if (!_te923tool.GetData(&data,&dev))
	{
		//give it one more change!
		_te923tool.CloseDevice();
		boost::this_thread::sleep( boost::posix_time::milliseconds(500) );

		CTE923Tool _te923tool2;
		if (!_te923tool2.OpenDevice())
		{
			return;
		}
		if (!_te923tool2.GetData(&data,&dev))
		{
			_log.Log(LOG_ERROR, "TE923: Could not read weather data!");
			return;
		}
		else
			_te923tool2.CloseDevice();
	}
	else
		_te923tool.CloseDevice();
#else
	FILE *fIn=fopen("weatherdata.bin","rb+");
	fread(&data,1,sizeof(Te923DataSet_t),fIn);
	fclose(fIn);
#endif

	if (data._press != 0 )
	{
		_log.Log(LOG_ERROR, "TE923: No Barometric pressure in weather station, reading skipped!");
		return;
	}
	if ((data.press<800)||(data.press>1200))
	{
		_log.Log(LOG_ERROR, "TE923: Invalid weather station data received (baro)!");
		return;
	}

	int ii;
	for (ii=0; ii<6; ii++)
	{
		if (data._t[ii]==0)
		{
			if ((data.t[ii]<-60)||(data.t[ii]>60))
			{
				_log.Log(LOG_ERROR, "TE923: Invalid weather station data received (temp)!");
				return;
			}
		}
	}

	//Add temp sensors
	for (ii=0; ii<6; ii++)
	{
		if ((data._t[ii]==0)&&(data._h[ii]==0))
		{
			//Temp+Hum
			RBUF tsen;
			memset(&tsen,0,sizeof(RBUF));

			//special case if baro is present for first sensor
			if ((ii==0)&&(data._press == 0 ))
			{
				tsen.TEMP_HUM_BARO.packetlength=sizeof(tsen.TEMP_HUM_BARO)-1;
				tsen.TEMP_HUM_BARO.packettype=pTypeTEMP_HUM_BARO;
				tsen.TEMP_HUM_BARO.subtype=sTypeTHBFloat;

				tsen.TEMP_HUM_BARO.battery_level=9;
				tsen.TEMP_HUM_BARO.rssi=12;
				tsen.TEMP_HUM_BARO.id1=0;
				tsen.TEMP_HUM_BARO.id2=ii;

				tsen.TEMP_HUM_BARO.tempsign=(data.t[ii]>=0)?0:1;
				int at10=round(abs(data.t[ii]*10.0f));
				tsen.TEMP_HUM_BARO.temperatureh=(BYTE)(at10/256);
				at10-=(tsen.TEMP_HUM_BARO.temperatureh*256);
				tsen.TEMP_HUM_BARO.temperaturel=(BYTE)(at10);
				tsen.TEMP_HUM_BARO.humidity=(BYTE)data.h[ii];
				tsen.TEMP_HUM_BARO.humidity_status=Get_Humidity_Level(tsen.TEMP_HUM.humidity);

				int ab10=round(data.press*10.0f);
				tsen.TEMP_HUM_BARO.baroh=(BYTE)(ab10/256);
				ab10-=(tsen.TEMP_HUM_BARO.baroh*256);
				tsen.TEMP_HUM_BARO.barol=(BYTE)(ab10);
				tsen.TEMP_HUM_BARO.forecast=data.forecast;

				sDecodeRXMessage(this, (const unsigned char *)&tsen.TEMP_HUM_BARO);//decode message
			}
			else
			{
				tsen.TEMP_HUM.packetlength=sizeof(tsen.TEMP_HUM)-1;
				tsen.TEMP_HUM.packettype=pTypeTEMP_HUM;
				tsen.TEMP_HUM.subtype=sTypeTH5;
				if (dev.battery[ii-1])
					tsen.TEMP_HUM.battery_level=9;
				else
					tsen.TEMP_HUM.battery_level=0;
				tsen.TEMP_HUM.rssi=12;
				tsen.TEMP_HUM.id1=0;
				tsen.TEMP_HUM.id2=ii;

				tsen.TEMP_HUM.tempsign=(data.t[ii]>=0)?0:1;
				int at10=round(abs(data.t[ii]*10.0f));
				tsen.TEMP_HUM.temperatureh=(BYTE)(at10/256);
				at10-=(tsen.TEMP_HUM.temperatureh*256);
				tsen.TEMP_HUM.temperaturel=(BYTE)(at10);
				tsen.TEMP_HUM.humidity=(BYTE)data.h[ii];
				tsen.TEMP_HUM.humidity_status=Get_Humidity_Level(tsen.TEMP_HUM.humidity);

				sDecodeRXMessage(this, (const unsigned char *)&tsen.TEMP_HUM);//decode message
			}
		}
		else if (data._t[ii]==0)
		{
			//Temp
			RBUF tsen;
			memset(&tsen,0,sizeof(RBUF));
			tsen.TEMP.packetlength=sizeof(tsen.TEMP)-1;
			tsen.TEMP.packettype=pTypeTEMP;
			tsen.TEMP.subtype=sTypeTEMP10;
			if (ii>0)
			{
				if (dev.battery[ii-1])
					tsen.TEMP.battery_level=9;
				else
					tsen.TEMP.battery_level=0;
			}
			else
			{
				tsen.TEMP.battery_level=9;
			}
			tsen.TEMP.rssi=12;
			tsen.TEMP.id1=0;
			tsen.TEMP.id2=ii;

			tsen.TEMP.tempsign=(data.t[ii]>=0)?0:1;
			int at10=round(abs(data.t[ii]*10.0f));
			tsen.TEMP.temperatureh=(BYTE)(at10/256);
			at10-=(tsen.TEMP.temperatureh*256);
			tsen.TEMP.temperaturel=(BYTE)(at10);

			sDecodeRXMessage(this, (const unsigned char *)&tsen.TEMP);//decode message
		}
		else if (data._h[ii]==0)
		{
			//Hum
			RBUF tsen;
			memset(&tsen,0,sizeof(RBUF));
			tsen.HUM.packetlength=sizeof(tsen.HUM)-1;
			tsen.HUM.packettype=pTypeHUM;
			tsen.HUM.subtype=sTypeHUM2;
			if (ii>0)
			{
				if (dev.battery[ii-1])
					tsen.HUM.battery_level=9;
				else
					tsen.HUM.battery_level=0;
			}
			else
			{
				tsen.HUM.battery_level=9;
			}
			tsen.HUM.rssi=12;
			tsen.HUM.id1=0;
			tsen.HUM.id2=ii;

			tsen.HUM.humidity=(BYTE)data.h[ii];
			tsen.HUM.humidity_status=Get_Humidity_Level(tsen.HUM.humidity);

			sDecodeRXMessage(this, (const unsigned char *)&tsen.HUM);//decode message
		}
	}

	//Wind
	if (data._wDir==0)
	{
		RBUF tsen;
		memset(&tsen,0,sizeof(RBUF));
		tsen.WIND.packetlength=sizeof(tsen.WIND)-1;
		tsen.WIND.packettype=pTypeWIND;
		tsen.WIND.subtype=sTypeWINDNoTemp;
		if (dev.batteryWind)
			tsen.WIND.battery_level=9;
		else
			tsen.WIND.battery_level=0;
		tsen.WIND.rssi=12;
		tsen.WIND.id1=0;
		tsen.WIND.id2=1;

		float winddir=float(data.wDir)*22.5f;
		int aw=round(winddir);
		tsen.WIND.directionh=(BYTE)(aw/256);
		aw-=(tsen.WIND.directionh*256);
		tsen.WIND.directionl=(BYTE)(aw);

		tsen.WIND.av_speedh=0;
		tsen.WIND.av_speedl=0;
		if (data._wSpeed==0)
		{
			int sw=round(data.wSpeed*10.0f);
			tsen.WIND.av_speedh=(BYTE)(sw/256);
			sw-=(tsen.WIND.av_speedh*256);
			tsen.WIND.av_speedl=(BYTE)(sw);
		}
		tsen.WIND.gusth=0;
		tsen.WIND.gustl=0;
		if (data._wGust==0)
		{
			int gw=round(data.wGust*10.0f);
			tsen.WIND.gusth=(BYTE)(gw/256);
			gw-=(tsen.WIND.gusth*256);
			tsen.WIND.gustl=(BYTE)(gw);
		}

		//this is not correct, why no wind temperature? and only chill?
		tsen.WIND.chillh=0;
		tsen.WIND.chilll=0;
		tsen.WIND.temperatureh=0;
		tsen.WIND.temperaturel=0;
		if (data._wChill==0)
		{
			tsen.WIND.tempsign=(data.wChill>=0)?0:1;
			tsen.WIND.chillsign=(data.wChill>=0)?0:1;
			int at10=round(abs(data.wChill*10.0f));
			tsen.WIND.temperatureh=(BYTE)(at10/256);
			tsen.WIND.chillh=(BYTE)(at10/256);
			at10-=(tsen.WIND.chillh*256);
			tsen.WIND.temperaturel=(BYTE)(at10);
			tsen.WIND.chilll=(BYTE)(at10);
		}

		sDecodeRXMessage(this, (const unsigned char *)&tsen.WIND);//decode message
	}

	//Rain
	if (data._RainCount==0)
	{
		RBUF tsen;
		memset(&tsen,0,sizeof(RBUF));
		tsen.RAIN.packetlength=sizeof(tsen.RAIN)-1;
		tsen.RAIN.packettype=pTypeRAIN;
		tsen.RAIN.subtype=sTypeRAIN3;
		if (dev.batteryRain)
			tsen.RAIN.battery_level=9;
		else
			tsen.RAIN.battery_level=0;
		tsen.RAIN.rssi=12;
		tsen.RAIN.id1=0;
		tsen.RAIN.id2=1;

		tsen.RAIN.rainrateh=0;
		tsen.RAIN.rainratel=0;

		int tr10=int((float(data.RainCount)*10.0f)*0.7f);

		tsen.RAIN.raintotal1=0;
		tsen.RAIN.raintotal2=(BYTE)(tr10/256);
		tr10-=(tsen.RAIN.raintotal2*256);
		tsen.RAIN.raintotal3=(BYTE)(tr10);

		sDecodeRXMessage(this, (const unsigned char *)&tsen.RAIN);//decode message
	}
	//UV
	if (data._uv==0)
	{
		RBUF tsen;
		memset(&tsen,0,sizeof(RBUF));
		tsen.UV.packetlength=sizeof(tsen.UV)-1;
		tsen.UV.packettype=pTypeUV;
		tsen.UV.subtype=sTypeUV1;
		if (dev.batteryUV)
			tsen.UV.battery_level=9;
		else
			tsen.UV.battery_level=0;
		tsen.UV.rssi=12;
		tsen.UV.id1=0;
		tsen.UV.id2=1;

		tsen.UV.uv=(BYTE)round(data.uv*10);
		sDecodeRXMessage(this, (const unsigned char *)&tsen.UV);//decode message
	}
}
示例#13
0
void CForecastIO::GetMeterDetails()
{
	std::string sResult;
#ifdef DEBUG_ForecastIO
	sResult=readForecastIOTestFile("E:\\forecastio.json");
#else
	std::stringstream sURL;
	std::string szLoc = CURLEncode::URLEncode(m_Location);
	sURL << "https://api.forecast.io/forecast/" << m_APIKey << "/" << szLoc;
	try
	{
		bool bret;
		std::string szURL = sURL.str();
		bret = HTTPClient::GET(szURL, sResult);
		if (!bret)
		{
			_log.Log(LOG_ERROR, "ForecastIO: Error getting http data!");
			return;
		}
	}
	catch (...)
	{
		_log.Log(LOG_ERROR, "ForecastIO: Error getting http data!");
		return;
	}

#endif
	Json::Value root;

	Json::Reader jReader;
	bool ret=jReader.parse(sResult,root);
	if (!ret)
	{
		_log.Log(LOG_ERROR,"ForecastIO: Invalid data received!");
		return;
	}
	if (root["currently"].empty()==true)
	{
		_log.Log(LOG_ERROR,"ForecastIO: Invalid data received, or unknown location!");
		return;
	}
	/*
	std::string tmpstr2 = root.toStyledString();
	FILE *fOut = fopen("E:\\forecastio.json", "wb+");
	fwrite(tmpstr2.c_str(), 1, tmpstr2.size(), fOut);
	fclose(fOut);
	*/

	float temp;
	int humidity=0;
	int barometric=0;
	int barometric_forcast=baroForecastNoInfo;

	temp=root["currently"]["temperature"].asFloat();
	//Convert to celcius
	temp=float((temp-32)*(5.0/9.0));

	if (root["currently"]["humidity"].empty()==false)
	{
		humidity=round(root["currently"]["humidity"].asFloat()*100.0f);
	}
	if (root["currently"]["pressure"].empty()==false)
	{
		barometric=atoi(root["currently"]["pressure"].asString().c_str());
		if (barometric<1000)
			barometric_forcast=baroForecastRain;
		else if (barometric<1020)
			barometric_forcast=baroForecastCloudy;
		else if (barometric<1030)
			barometric_forcast=baroForecastPartlyCloudy;
		else
			barometric_forcast=baroForecastSunny;

		if (root["currently"]["icon"].empty()==false)
		{
			std::string forcasticon=root["currently"]["icon"].asString();
			if ((forcasticon=="partly-cloudy-day")||(forcasticon=="partly-cloudy-night"))
			{
				barometric_forcast=baroForecastPartlyCloudy;
			}
			else if (forcasticon=="cloudy")
			{
				barometric_forcast=baroForecastCloudy;
			}
			else if ((forcasticon=="clear-day")||(forcasticon=="clear-night"))
			{
				barometric_forcast=baroForecastSunny;
			}
			else if ((forcasticon=="rain")||(forcasticon=="snow"))
			{
				barometric_forcast=baroForecastRain;
			}
		}
	}

	if (barometric!=0)
	{
		//Add temp+hum+baro device
		RBUF tsen;
		memset(&tsen,0,sizeof(RBUF));
		tsen.TEMP_HUM_BARO.packetlength=sizeof(tsen.TEMP_HUM_BARO)-1;
		tsen.TEMP_HUM_BARO.packettype=pTypeTEMP_HUM_BARO;
		tsen.TEMP_HUM_BARO.subtype=sTypeTHB1;
		tsen.TEMP_HUM_BARO.battery_level=9;
		tsen.TEMP_HUM_BARO.rssi=12;
		tsen.TEMP_HUM_BARO.id1=0;
		tsen.TEMP_HUM_BARO.id2=1;

		tsen.TEMP_HUM_BARO.tempsign=(temp>=0)?0:1;
		int at10=round(abs(temp*10.0f));
		tsen.TEMP_HUM_BARO.temperatureh=(BYTE)(at10/256);
		at10-=(tsen.TEMP_HUM_BARO.temperatureh*256);
		tsen.TEMP_HUM_BARO.temperaturel=(BYTE)(at10);
		tsen.TEMP_HUM_BARO.humidity=(BYTE)humidity;
		tsen.TEMP_HUM_BARO.humidity_status=Get_Humidity_Level(tsen.TEMP_HUM.humidity);

		int ab10=round(barometric);
		tsen.TEMP_HUM_BARO.baroh=(BYTE)(ab10/256);
		ab10-=(tsen.TEMP_HUM_BARO.baroh*256);
		tsen.TEMP_HUM_BARO.barol=(BYTE)(ab10);
		
		tsen.TEMP_HUM_BARO.forecast=barometric_forcast;

		sDecodeRXMessage(this, (const unsigned char *)&tsen.TEMP_HUM_BARO, NULL);
	}
	else if (humidity!=0)
	{
		//add temp+hum device
		RBUF tsen;
		memset(&tsen,0,sizeof(RBUF));
		tsen.TEMP_HUM.packetlength=sizeof(tsen.TEMP_HUM)-1;
		tsen.TEMP_HUM.packettype=pTypeTEMP_HUM;
		tsen.TEMP_HUM.subtype=sTypeTH5;
		tsen.TEMP_HUM.battery_level=9;
		tsen.TEMP_HUM.rssi=12;
		tsen.TEMP_HUM.id1=0;
		tsen.TEMP_HUM.id2=1;

		tsen.TEMP_HUM.tempsign=(temp>=0)?0:1;
		int at10=round(abs(temp*10.0f));
		tsen.TEMP_HUM.temperatureh=(BYTE)(at10/256);
		at10-=(tsen.TEMP_HUM.temperatureh*256);
		tsen.TEMP_HUM.temperaturel=(BYTE)(at10);
		tsen.TEMP_HUM.humidity=(BYTE)humidity;
		tsen.TEMP_HUM.humidity_status=Get_Humidity_Level(tsen.TEMP_HUM.humidity);

		sDecodeRXMessage(this, (const unsigned char *)&tsen.TEMP_HUM, NULL);
	}
	else
	{
		//add temp device
		RBUF tsen;
		memset(&tsen,0,sizeof(RBUF));
		tsen.TEMP.packetlength=sizeof(tsen.TEMP)-1;
		tsen.TEMP.packettype=pTypeTEMP;
		tsen.TEMP.subtype=sTypeTEMP10;
		tsen.TEMP.battery_level=9;
		tsen.TEMP.rssi=12;
		tsen.TEMP.id1=0;
		tsen.TEMP.id2=1;

		tsen.TEMP.tempsign=(temp>=0)?0:1;
		int at10=round(abs(temp*10.0f));
		tsen.TEMP.temperatureh=(BYTE)(at10/256);
		at10-=(tsen.TEMP.temperatureh*256);
		tsen.TEMP.temperaturel=(BYTE)(at10);

		sDecodeRXMessage(this, (const unsigned char *)&tsen.TEMP, NULL);
	}

	//Wind
	int wind_degrees=-1;
	float wind_mph=-1;
	float wind_gust_mph=-1;
	float windspeed_ms=0;
	float windgust_ms=0;
	float wind_temp=temp;
	float wind_chill=temp;
	int windgust=1;
	float windchill=-1;

	if (root["currently"]["windBearing"].empty()==false)
	{
		wind_degrees=atoi(root["currently"]["windBearing"].asString().c_str());
	}
	if (root["currently"]["windSpeed"].empty()==false)
	{
		if ((root["currently"]["windSpeed"] != "N/A") && (root["currently"]["windSpeed"] != "--"))
		{
			float temp_wind_mph = static_cast<float>(atof(root["currently"]["windSpeed"].asString().c_str()));
			if (temp_wind_mph!=-9999.00f)
			{
				wind_mph=temp_wind_mph;
				//convert to m/s
				windspeed_ms=wind_mph*0.44704f;
			}
		}
	}
	if (root["currently"]["windGust"].empty()==false)
	{
		if ((root["currently"]["windGust"] != "N/A") && (root["currently"]["windGust"] != "--"))
		{
			float temp_wind_gust_mph = static_cast<float>(atof(root["currently"]["windGust"].asString().c_str()));
			if (temp_wind_gust_mph!=-9999.00f)
			{
				wind_gust_mph=temp_wind_gust_mph;
				//convert to m/s
				windgust_ms=wind_gust_mph*0.44704f;
			}
		}
	}
	if (root["currently"]["apparentTemperature"].empty()==false)
	{
		if ((root["currently"]["apparentTemperature"] != "N/A") && (root["currently"]["apparentTemperature"] != "--"))
		{
			wind_chill = static_cast<float>(atof(root["currently"]["apparentTemperature"].asString().c_str()));
			//Convert to celcius
			wind_chill=float((wind_chill-32)*(5.0/9.0));
		}
	}
	if (wind_degrees!=-1)
	{
		RBUF tsen;
		memset(&tsen,0,sizeof(RBUF));
		tsen.WIND.packetlength=sizeof(tsen.WIND)-1;
		tsen.WIND.packettype=pTypeWIND;
		tsen.WIND.subtype=sTypeWIND4;
		tsen.WIND.battery_level=9;
		tsen.WIND.rssi=12;
		tsen.WIND.id1=0;
		tsen.WIND.id2=1;

		float winddir=float(wind_degrees);
		int aw=round(winddir);
		tsen.WIND.directionh=(BYTE)(aw/256);
		aw-=(tsen.WIND.directionh*256);
		tsen.WIND.directionl=(BYTE)(aw);

		tsen.WIND.av_speedh=0;
		tsen.WIND.av_speedl=0;
		int sw=round(windspeed_ms*10.0f);
		tsen.WIND.av_speedh=(BYTE)(sw/256);
		sw-=(tsen.WIND.av_speedh*256);
		tsen.WIND.av_speedl=(BYTE)(sw);

		tsen.WIND.gusth=0;
		tsen.WIND.gustl=0;
		int gw=round(windgust_ms*10.0f);
		tsen.WIND.gusth=(BYTE)(gw/256);
		gw-=(tsen.WIND.gusth*256);
		tsen.WIND.gustl=(BYTE)(gw);

		//this is not correct, why no wind temperature? and only chill?
		tsen.WIND.chillh=0;
		tsen.WIND.chilll=0;
		tsen.WIND.temperatureh=0;
		tsen.WIND.temperaturel=0;

		tsen.WIND.tempsign=(wind_temp>=0)?0:1;
		int at10=round(abs(wind_temp*10.0f));
		tsen.WIND.temperatureh=(BYTE)(at10/256);
		at10-=(tsen.WIND.temperatureh*256);
		tsen.WIND.temperaturel=(BYTE)(at10);

		tsen.WIND.chillsign=(wind_temp>=0)?0:1;
		at10=round(abs(wind_chill*10.0f));
		tsen.WIND.chillh=(BYTE)(at10/256);
		at10-=(tsen.WIND.chillh*256);
		tsen.WIND.chilll=(BYTE)(at10);

		sDecodeRXMessage(this, (const unsigned char *)&tsen.WIND, NULL);
	}

	//UV
	if (root["currently"]["UV"].empty()==false)
	{
		if ((root["currently"]["UV"] != "N/A") && (root["currently"]["UV"] != "--"))
		{
			float UV = static_cast<float>(atof(root["currently"]["UV"].asString().c_str()));
			if ((UV<16)&&(UV>=0))
			{
				RBUF tsen;
				memset(&tsen,0,sizeof(RBUF));
				tsen.UV.packetlength=sizeof(tsen.UV)-1;
				tsen.UV.packettype=pTypeUV;
				tsen.UV.subtype=sTypeUV1;
				tsen.UV.battery_level=9;
				tsen.UV.rssi=12;
				tsen.UV.id1=0;
				tsen.UV.id2=1;

				tsen.UV.uv=(BYTE)round(UV*10);
				sDecodeRXMessage(this, (const unsigned char *)&tsen.UV, NULL);
			}
		}
	}

	//Rain
	if (root["currently"]["precipIntensity"].empty()==false)
	{
		if ((root["currently"]["precipIntensity"] != "N/A") && (root["currently"]["precipIntensity"] != "--"))
		{
			float RainCount = static_cast<float>(atof(root["currently"]["precipIntensity"].asString().c_str()))*25.4f; //inches to mm
			if ((RainCount!=-9999.00f)&&(RainCount>=0.00f))
			{
				RBUF tsen;
				memset(&tsen,0,sizeof(RBUF));
				tsen.RAIN.packetlength=sizeof(tsen.RAIN)-1;
				tsen.RAIN.packettype=pTypeRAIN;
				tsen.RAIN.subtype=sTypeRAINWU;
				tsen.RAIN.battery_level=9;
				tsen.RAIN.rssi=12;
				tsen.RAIN.id1=0;
				tsen.RAIN.id2=1;

				tsen.RAIN.rainrateh=0;
				tsen.RAIN.rainratel=0;

				if (root["currently"]["precip_1hr_metric"].empty()==false)
				{
					if ((root["currently"]["precip_1hr_metric"] != "N/A") && (root["currently"]["precip_1hr_metric"] != "--"))
					{
						float rainrateph = static_cast<float>(atof(root["currently"]["precip_1hr_metric"].asString().c_str()));
						if (rainrateph!=-9999.00f)
						{
							int at10=round(abs(rainrateph*10.0f));
							tsen.RAIN.rainrateh=(BYTE)(at10/256);
							at10-=(tsen.RAIN.rainrateh*256);
							tsen.RAIN.rainratel=(BYTE)(at10);
						}
					}
				}

				int tr10=int((float(RainCount)*10.0f));
				tsen.RAIN.raintotal1=0;
				tsen.RAIN.raintotal2=(BYTE)(tr10/256);
				tr10-=(tsen.RAIN.raintotal2*256);
				tsen.RAIN.raintotal3=(BYTE)(tr10);

				sDecodeRXMessage(this, (const unsigned char *)&tsen.RAIN, NULL);
			}
		}
	}

	//Visibility
	if (root["currently"]["visibility"].empty()==false)
	{
		if ((root["currently"]["visibility"] != "N/A") && (root["currently"]["visibility"] != "--"))
		{
			float visibility = static_cast<float>(atof(root["currently"]["visibility"].asString().c_str()))*1.60934f; //miles to km
			if (visibility>=0)
			{
				_tGeneralDevice gdevice;
				gdevice.subtype=sTypeVisibility;
				gdevice.floatval1=visibility;
				sDecodeRXMessage(this, (const unsigned char *)&gdevice, NULL);
			}
		}
	}
	//Solar Radiation
	if (root["currently"]["ozone"].empty()==false)
	{
		if ((root["currently"]["ozone"] != "N/A") && (root["currently"]["ozone"] != "--"))
		{
			float radiation = static_cast<float>(atof(root["currently"]["ozone"].asString().c_str()));	//this is in dobson units, need to convert to Watt/m2? (2.69×(10^20) ?
			if (radiation>=0.0f)
			{
				_tGeneralDevice gdevice;
				gdevice.subtype=sTypeSolarRadiation;
				gdevice.floatval1=radiation;
				sDecodeRXMessage(this, (const unsigned char *)&gdevice, NULL);
			}
		}
	}

}
示例#14
0
void ZWaveBase::SendDevice2Domoticz(const _tZWaveDevice *pDevice)
{
	unsigned char ID1=0;
	unsigned char ID2=0;
	unsigned char ID3=0;
	unsigned char ID4=0;

	//make device ID
	ID1=0;
	ID2=(unsigned char)((pDevice->nodeID&0xFF00)>>8);
	ID3=(unsigned char)pDevice->nodeID&0xFF;
	ID4=pDevice->instanceID;

	char szID[10];
	sprintf(szID,"%X%02X%02X%02X", ID1, ID2, ID3, ID4);


	if ((pDevice->devType==ZDTYPE_SWITCHNORMAL)||(pDevice->devType==ZDTYPE_SWITCHDIMMER))
	{
		//Send as Lighting 2
		tRBUF lcmd;
		memset(&lcmd,0,sizeof(RBUF));
		lcmd.LIGHTING2.packetlength=sizeof(lcmd.LIGHTING2)-1;
		lcmd.LIGHTING2.packettype=pTypeLighting2;
		lcmd.LIGHTING2.subtype=sTypeAC;
		lcmd.LIGHTING2.seqnbr=pDevice->sequence_number;
		lcmd.LIGHTING2.id1=ID1;
		lcmd.LIGHTING2.id2=ID2;
		lcmd.LIGHTING2.id3=ID3;
		lcmd.LIGHTING2.id4=ID4;
		lcmd.LIGHTING2.unitcode=1;
		int level=15;
		if (pDevice->devType==ZDTYPE_SWITCHNORMAL)
		{
			//simple on/off device
			if (pDevice->intvalue==0)
			{
				level=0;
				lcmd.LIGHTING2.cmnd=light2_sOff;
			}
			else
			{
				level=15;
				lcmd.LIGHTING2.cmnd=light2_sOn;
			}
		}
		else
		{
			//dimmer able device
			if (pDevice->intvalue==0)
				level=0;
			if (pDevice->intvalue==255)
				level=15;
			else
			{
				float flevel=(15.0f/100.0f)*float(pDevice->intvalue);
				level=round(flevel);
				if (level>15)
					level=15;
			}
			if (level==0)
				lcmd.LIGHTING2.cmnd=light2_sOff;
			else if (level==15)
				lcmd.LIGHTING2.cmnd=light2_sOn;
			else
				lcmd.LIGHTING2.cmnd=light2_sSetLevel;
		}
		lcmd.LIGHTING2.level=level;
		lcmd.LIGHTING2.filler=0;
		lcmd.LIGHTING2.rssi=12;
		sDecodeRXMessage(this, (const unsigned char *)&lcmd.LIGHTING2);//decode message
		return;
	}
	else if (pDevice->devType==ZDTYPE_SENSOR_POWER)
	{
		_tUsageMeter umeter;
		umeter.id1=ID1;
		umeter.id2=ID2;
		umeter.id3=ID3;
		umeter.id4=ID4;
		umeter.dunit=pDevice->scaleID;
		umeter.fusage=pDevice->floatValue;
		sDecodeRXMessage(this, (const unsigned char *)&umeter);//decode message
	}
	else if (pDevice->devType==ZDTYPE_SENSOR_VOLTAGE)
	{
		_tGeneralDevice gDevice;
		gDevice.subtype=sTypeVoltage;
		gDevice.id=ID4;
		gDevice.floatval1=pDevice->floatValue;
		gDevice.intval1=(int)(ID1<<24)|(ID2<<16)|(ID3<<8)|ID4;
		sDecodeRXMessage(this, (const unsigned char *)&gDevice);
	}
	else if (pDevice->devType==ZDTYPE_SENSOR_AMPERE)
	{
		RBUF tsen;
		memset(&tsen,0,sizeof(RBUF));
		tsen.CURRENT.packettype=pTypeCURRENT;
		tsen.CURRENT.subtype=sTypeELEC1;
		tsen.CURRENT.id1=ID3;
		tsen.CURRENT.id2=ID4;
		int amps=round(pDevice->floatValue*10.0f);
		tsen.CURRENT.ch1h=amps/256;
		amps-=(tsen.CURRENT.ch1h*256);
		tsen.CURRENT.ch1l=(BYTE)amps;
		tsen.CURRENT.battery_level=9;
		tsen.CURRENT.rssi=12;
		if (pDevice->hasBattery)
		{
			tsen.ENERGY.battery_level=Convert_Battery_To_PercInt(pDevice->batValue);
		}
		sDecodeRXMessage(this, (const unsigned char *)&tsen.CURRENT);
	}
	else if (pDevice->devType==ZDTYPE_SENSOR_POWERENERGYMETER)
	{
		RBUF tsen;
		memset(&tsen,0,sizeof(RBUF));

		const _tZWaveDevice *pPowerDevice=NULL;
		pPowerDevice=FindDevice(pDevice->nodeID,pDevice->instanceID,ZDTYPE_SENSOR_POWER);
		if (pPowerDevice==NULL)
			pPowerDevice=FindDevice(pDevice->nodeID,-1,ZDTYPE_SENSOR_POWER);
		if (pPowerDevice)
		{
			tsen.ENERGY.packettype=pTypeENERGY;
			tsen.ENERGY.subtype=sTypeELEC2;
			tsen.ENERGY.id1=ID3;
			tsen.ENERGY.id2=ID4;
			tsen.ENERGY.count=1;
			tsen.ENERGY.rssi=12;

			tsen.ENERGY.battery_level=9;
			if (pDevice->hasBattery)
			{
				tsen.ENERGY.battery_level=Convert_Battery_To_PercInt(pDevice->batValue);
			}

			unsigned long long instant=(unsigned long long)round(pPowerDevice->floatValue);
			tsen.ENERGY.instant1=(unsigned char)(instant/0x1000000);
			instant-=tsen.ENERGY.instant1*0x1000000;
			tsen.ENERGY.instant2=(unsigned char)(instant/0x10000);
			instant-=tsen.ENERGY.instant2*0x10000;
			tsen.ENERGY.instant3=(unsigned char)(instant/0x100);
			instant-=tsen.ENERGY.instant3*0x100;
			tsen.ENERGY.instant4=(unsigned char)(instant);

			double total=pDevice->floatValue*223.666;
			tsen.ENERGY.total1=(unsigned char)(total/0x10000000000ULL);
			total-=tsen.ENERGY.total1*0x10000000000ULL;
			tsen.ENERGY.total2=(unsigned char)(total/0x100000000ULL);
			total-=tsen.ENERGY.total2*0x100000000ULL;
			tsen.ENERGY.total3=(unsigned char)(total/0x1000000);
			total-=tsen.ENERGY.total3*0x1000000;
			tsen.ENERGY.total4=(unsigned char)(total/0x10000);
			total-=tsen.ENERGY.total4*0x10000;
			tsen.ENERGY.total5=(unsigned char)(total/0x100);
			total-=tsen.ENERGY.total5*0x100;
			tsen.ENERGY.total6=(unsigned char)(total);

			sDecodeRXMessage(this, (const unsigned char *)&tsen.ENERGY);//decode message
		}
		else
		{
			tsen.ENERGY.packettype=pTypeENERGY;
			tsen.ENERGY.subtype=sTypeELEC2;
			tsen.ENERGY.id1=ID3;
			tsen.ENERGY.id2=ID4;
			tsen.ENERGY.count=1;
			tsen.ENERGY.rssi=12;

			tsen.ENERGY.battery_level=9;
			if (pDevice->hasBattery)
			{
				tsen.ENERGY.battery_level=Convert_Battery_To_PercInt(pDevice->batValue);
			}

			unsigned long long instant=0;
			tsen.ENERGY.instant1=(unsigned char)(instant/0x1000000);
			instant-=tsen.ENERGY.instant1*0x1000000;
			tsen.ENERGY.instant2=(unsigned char)(instant/0x10000);
			instant-=tsen.ENERGY.instant2*0x10000;
			tsen.ENERGY.instant3=(unsigned char)(instant/0x100);
			instant-=tsen.ENERGY.instant3*0x100;
			tsen.ENERGY.instant4=(unsigned char)(instant);

			double total=pDevice->floatValue*223.666;
			tsen.ENERGY.total1=(unsigned char)(total/0x10000000000ULL);
			total-=tsen.ENERGY.total1*0x10000000000ULL;
			tsen.ENERGY.total2=(unsigned char)(total/0x100000000ULL);
			total-=tsen.ENERGY.total2*0x100000000ULL;
			tsen.ENERGY.total3=(unsigned char)(total/0x1000000);
			total-=tsen.ENERGY.total3*0x1000000;
			tsen.ENERGY.total4=(unsigned char)(total/0x10000);
			total-=tsen.ENERGY.total4*0x10000;
			tsen.ENERGY.total5=(unsigned char)(total/0x100);
			total-=tsen.ENERGY.total5*0x100;
			tsen.ENERGY.total6=(unsigned char)(total);

			sDecodeRXMessage(this, (const unsigned char *)&tsen.ENERGY);//decode message
		}
	}
	else if (pDevice->devType==ZDTYPE_SENSOR_TEMPERATURE)
	{
		if (!pDevice->bValidValue)
			return;
		RBUF tsen;
		memset(&tsen,0,sizeof(RBUF));

		const _tZWaveDevice *pHumDevice=FindDevice(pDevice->nodeID,-1,ZDTYPE_SENSOR_HUMIDITY);
		if (pHumDevice)
		{
			if (!pHumDevice->bValidValue)
				return;
			tsen.TEMP_HUM.packetlength=sizeof(tsen.TEMP_HUM)-1;
			tsen.TEMP_HUM.packettype=pTypeTEMP_HUM;
			tsen.TEMP_HUM.subtype=sTypeTH5;
			tsen.TEMP_HUM.rssi=12;
			tsen.TEMP_HUM.id1=ID3;
			tsen.TEMP_HUM.id2=ID4;

			tsen.TEMP_HUM.battery_level=9;
			if (pDevice->hasBattery)
			{
				tsen.TEMP_HUM.battery_level=Convert_Battery_To_PercInt(pDevice->batValue);
			}

			tsen.TEMP_HUM.tempsign=(pDevice->floatValue>=0)?0:1;
			int at10=round(abs(pDevice->floatValue*10.0f));
			tsen.TEMP_HUM.temperatureh=(BYTE)(at10/256);
			at10-=(tsen.TEMP_HUM.temperatureh*256);
			tsen.TEMP_HUM.temperaturel=(BYTE)(at10);
			tsen.TEMP_HUM.humidity=(BYTE)pHumDevice->intvalue;
			tsen.TEMP_HUM.humidity_status=Get_Humidity_Level(tsen.TEMP_HUM.humidity);
		}
		else
		{
			tsen.TEMP.packetlength=sizeof(tsen.TEMP)-1;
			tsen.TEMP.packettype=pTypeTEMP;
			tsen.TEMP.subtype=sTypeTEMP10;
			tsen.TEMP.rssi=12;
			tsen.TEMP.id1=ID3;
			tsen.TEMP.id2=ID4;

			tsen.TEMP.battery_level=9;
			if (pDevice->hasBattery)
			{
				tsen.TEMP.battery_level=Convert_Battery_To_PercInt(pDevice->batValue);
			}

			tsen.TEMP.tempsign=(pDevice->floatValue>=0)?0:1;
			int at10=round(abs(pDevice->floatValue*10.0f));
			tsen.TEMP.temperatureh=(BYTE)(at10/256);
			at10-=(tsen.TEMP.temperatureh*256);
			tsen.TEMP.temperaturel=(BYTE)(at10);
		}
		sDecodeRXMessage(this, (const unsigned char *)&tsen.TEMP);//decode message
	}
	else if (pDevice->devType==ZDTYPE_SENSOR_HUMIDITY)
	{
		if (!pDevice->bValidValue)
			return;
		RBUF tsen;
		memset(&tsen,0,sizeof(RBUF));

		const _tZWaveDevice *pTempDevice=FindDevice(pDevice->nodeID,-1,ZDTYPE_SENSOR_TEMPERATURE);
		if (pTempDevice)
		{
			if (!pTempDevice->bValidValue)
				return;

			tsen.TEMP_HUM.packetlength=sizeof(tsen.TEMP_HUM)-1;
			tsen.TEMP_HUM.packettype=pTypeTEMP_HUM;
			tsen.TEMP_HUM.subtype=sTypeTH5;
			tsen.TEMP_HUM.rssi=12;
			tsen.TEMP_HUM.id1=ID3;
			tsen.TEMP_HUM.id2=ID4;
			ID4=pTempDevice->instanceID;

			tsen.TEMP_HUM.battery_level=9;
			if (pDevice->hasBattery)
			{
				tsen.TEMP_HUM.battery_level=Convert_Battery_To_PercInt(pDevice->batValue);
			}

			tsen.TEMP_HUM.tempsign=(pTempDevice->floatValue>=0)?0:1;
			int at10=round(abs(pTempDevice->floatValue*10.0f));
			tsen.TEMP_HUM.temperatureh=(BYTE)(at10/256);
			at10-=(tsen.TEMP_HUM.temperatureh*256);
			tsen.TEMP_HUM.temperaturel=(BYTE)(at10);
			tsen.TEMP_HUM.humidity=(BYTE)pDevice->intvalue;
			tsen.TEMP_HUM.humidity_status=Get_Humidity_Level(tsen.TEMP_HUM.humidity);
		}
		else
		{
			memset(&tsen,0,sizeof(RBUF));
			tsen.HUM.packetlength=sizeof(tsen.HUM)-1;
			tsen.HUM.packettype=pTypeHUM;
			tsen.HUM.subtype=sTypeHUM2;
			tsen.HUM.rssi=12;
			tsen.HUM.id1=ID3;
			tsen.HUM.id2=ID4;
			tsen.HUM.battery_level=9;
			if (pDevice->hasBattery)
			{
				tsen.HUM.battery_level=Convert_Battery_To_PercInt(pDevice->batValue);
			}
			tsen.HUM.humidity=(BYTE)pDevice->intvalue;
			tsen.HUM.humidity_status=Get_Humidity_Level(tsen.HUM.humidity);
		}
		sDecodeRXMessage(this, (const unsigned char *)&tsen.TEMP);//decode message
	}
	else if (pDevice->devType==ZDTYPE_SENSOR_LIGHT)
	{
		_tLightMeter lmeter;
		lmeter.id1=ID1;
		lmeter.id2=ID2;
		lmeter.id3=ID3;
		lmeter.id4=ID4;
		lmeter.dunit=pDevice->scaleID;
		lmeter.fLux=pDevice->floatValue;
		if (pDevice->hasBattery)
			lmeter.battery_level=pDevice->batValue;
		sDecodeRXMessage(this, (const unsigned char *)&lmeter);
	}
	else if (pDevice->devType==ZDTYPE_SENSOR_SETPOINT)
	{
		_tThermostat tmeter;
		tmeter.subtype=sTypeThermSetpoint;
		tmeter.id1=ID1;
		tmeter.id2=ID2;
		tmeter.id3=ID3;
		tmeter.id4=ID4;
		tmeter.dunit=1;
		if (pDevice->hasBattery)
			tmeter.battery_level=pDevice->batValue;
		tmeter.temp=pDevice->floatValue;
		sDecodeRXMessage(this, (const unsigned char *)&tmeter);
	}
}
示例#15
0
bool CDavisLoggerSerial::HandleLoopData(const unsigned char *data, size_t len)
{
	const uint8_t *pData=data+1;

#ifndef DEBUG_DAVIS
	if (len!=100)
		return false;

	if (
		(data[1]!='L')||
		(data[2]!='O')||
		(data[3]!='O')||
		(data[96]!=0x0a)||
		(data[97]!=0x0d)
		)
		return false;
	bool bIsRevA = (data[4]=='P');
#else
//	FILE *fOut=fopen("davisrob.bin","wb+");
//	fwrite(data,1,len,fOut);
//	fclose(fOut);
	unsigned char szBuffer[200];
	FILE *fIn=fopen("E:\\davis2.bin","rb+");
	//FILE *fIn=fopen("davisrob.bin","rb+");
	fread(&szBuffer,1,100,fIn);
	fclose(fIn);
	pData=szBuffer+1;
	bool bIsRevA(szBuffer[4]=='P');
#endif

	RBUF tsen;
	memset(&tsen,0,sizeof(RBUF));


	unsigned char tempIdx=1;

	bool bBaroValid=false;
	float BaroMeter=0;
	bool bInsideTemperatureValid=false;
	float InsideTemperature=0;
	bool bInsideHumidityValid=false;
	int InsideHumidity=0;
	bool bOutsideTemperatureValid=false;
	float OutsideTemperature=0;
	bool bOutsideHumidityValid=false;
	int OutsideHumidity=0;

	bool bWindDirectionValid=false;
	int WindDirection=0;

	bool bWindSpeedValid=false;
	float WindSpeed=0;
	bool bWindSpeedAVR10Valid=false;
	float WindSpeedAVR10=0;

	bool bUVValid=false;
	float UV=0;

	//Barometer
	if ((pData[7]!=0xFF)&&(pData[8]!=0xFF))
	{
		bBaroValid=true;
		BaroMeter=((unsigned int)((pData[8] << 8) | pData[7])) / 29.53f; //in hPa
	}
	//Inside Temperature
	if ((pData[9]!=0xFF)||(pData[10]!=0x7F))
	{
		bInsideTemperatureValid=true;
		InsideTemperature=((unsigned int)((pData[10] << 8) | pData[9])) / 10.f;
		InsideTemperature = (InsideTemperature - 32.0f) * 5.0f / 9.0f;
	}
	//Inside Humidity
	if (pData[11]!=0xFF)
	{
		InsideHumidity=pData[11];
		if (InsideHumidity<101)
			bInsideHumidityValid=true;
	}

	if (bBaroValid&&bInsideTemperatureValid&&bInsideHumidityValid)
	{
		memset(&tsen,0,sizeof(RBUF));
		tsen.TEMP_HUM_BARO.packetlength=sizeof(tsen.TEMP_HUM_BARO)-1;
		tsen.TEMP_HUM_BARO.packettype=pTypeTEMP_HUM_BARO;
		tsen.TEMP_HUM_BARO.subtype=sTypeTHBFloat;
		tsen.TEMP_HUM_BARO.battery_level=9;
		tsen.TEMP_HUM_BARO.rssi=12;
		tsen.TEMP_HUM_BARO.id1=0;
		tsen.TEMP_HUM_BARO.id2=tempIdx++;

		tsen.TEMP_HUM_BARO.tempsign=(InsideTemperature>=0)?0:1;
		int at10=round(abs(InsideTemperature*10.0f));
		tsen.TEMP_HUM_BARO.temperatureh=(BYTE)(at10/256);
		at10-=(tsen.TEMP_HUM_BARO.temperatureh*256);
		tsen.TEMP_HUM_BARO.temperaturel=(BYTE)(at10);
		tsen.TEMP_HUM_BARO.humidity=(BYTE)InsideHumidity;
		tsen.TEMP_HUM_BARO.humidity_status=Get_Humidity_Level(tsen.TEMP_HUM.humidity);

		int ab10=round(BaroMeter*10.0f);
		tsen.TEMP_HUM_BARO.baroh=(BYTE)(ab10/256);
		ab10-=(tsen.TEMP_HUM_BARO.baroh*256);
		tsen.TEMP_HUM_BARO.barol=(BYTE)(ab10);

		uint8_t forecastitem=pData[89];
		int forecast=0;

		if ((forecastitem&0x01)==0x01)
			forecast=wsbaroforcast_rain;
		else if ((forecastitem&0x02)==0x02)
			forecast=wsbaroforcast_cloudy;
		else if ((forecastitem&0x04)==0x04)
			forecast=wsbaroforcast_some_clouds;
		else if ((forecastitem&0x08)==0x08)
			forecast=wsbaroforcast_sunny;
		else if ((forecastitem&0x10)==0x10)
			forecast=wsbaroforcast_snow;

		tsen.TEMP_HUM_BARO.forecast=forecast;

		sDecodeRXMessage(this, (const unsigned char *)&tsen.TEMP_HUM_BARO);//decode message
	}

	//Outside Temperature
	if ((pData[12]!=0xFF)||(pData[13]!=0x7F))
	{
		bOutsideTemperatureValid=true;
		OutsideTemperature=((unsigned int)((pData[13] << 8) | pData[12])) / 10.f;

		OutsideTemperature = (OutsideTemperature - 32.0f) * 5.0f / 9.0f;
	}
	//Outside Humidity
	if (pData[33]!=0xFF)
	{
		OutsideHumidity=pData[33];
		if (OutsideHumidity<101)
			bOutsideHumidityValid=true;
	}
	if (bOutsideTemperatureValid||bOutsideHumidityValid)
	{
		//add outside sensor
		memset(&tsen,0,sizeof(RBUF));

		if ((bOutsideTemperatureValid)&&(bOutsideHumidityValid))
		{
			//Temp+hum
			UpdateTempHumSensor(tempIdx++,OutsideTemperature,OutsideHumidity);
		}
		else if (bOutsideTemperatureValid)
		{
			//Temp
			UpdateTempSensor(tempIdx++,OutsideTemperature);
		}
		else if (bOutsideHumidityValid)
		{
			//hum
			UpdateHumSensor(tempIdx++,OutsideHumidity);
		}
	}

	tempIdx=10;
	//Add Extra Temp/Hum Sensors
	int iTmp;
	for (int iTmp=0; iTmp<7; iTmp++)
	{
		bool bTempValid=false;
		bool bHumValid=false;
		float temp=0;
		uint8_t hum=0;

		if (pData[18+iTmp]!=0xFF)
		{
			bTempValid=true;
			temp=pData[18+iTmp]-90.0f;
			temp = (temp - 32.0f) * 5.0f / 9.0f;
		}
		if (pData[34+iTmp]!=0xFF)
		{
			bHumValid=true;
			hum=pData[34+iTmp];
		}
		if ((bTempValid)&&(bHumValid))
		{
			//Temp+hum
			UpdateTempHumSensor(tempIdx++,temp,hum);
		}
		else if (bTempValid)
		{
			//Temp
			UpdateTempSensor(tempIdx++,temp);
		}
		else if (bHumValid)
		{
			//hum
			UpdateHumSensor(tempIdx++,hum);
		}
	}

	tempIdx=20;
	//Add Extra Soil Temp Sensors
	for (iTmp=0; iTmp<4; iTmp++)
	{
		bool bTempValid=false;
		float temp=0;

		if (pData[25+iTmp]!=0xFF)
		{
			bTempValid=true;
			temp=pData[25+iTmp]-90.0f;
			temp = (temp - 32.0f) * 5.0f / 9.0f;
		}
		if (bTempValid)
		{
			UpdateTempSensor(tempIdx++,temp);
		}
	}

	tempIdx=30;
	//Add Extra Leaf Temp Sensors
	for (iTmp=0; iTmp<4; iTmp++)
	{
		bool bTempValid=false;
		float temp=0;

		if (pData[29+iTmp]!=0xFF)
		{
			bTempValid=true;
			temp=pData[29+iTmp]-90.0f;
			temp = (temp - 32.0f) * 5.0f / 9.0f;
		}
		if (bTempValid)
		{
			UpdateTempSensor(tempIdx++,temp);
		}
	}

	//Wind Speed
	if (pData[14]!=0xFF)
	{
		bWindSpeedValid=true;
		WindSpeed=(pData[14])*(4.0f/9.0f);
	}
	//Wind Speed AVR 10 minutes
	if (pData[15]!=0xFF)
	{
		bWindSpeedAVR10Valid=true;
		WindSpeedAVR10=(pData[15])*(4.0f/9.0f);
	}
	//Wind Direction
	if ((pData[16]!=0xFF)&&(pData[17]!=0x7F))
	{
		bWindDirectionValid=true;
		WindDirection=((unsigned int)((pData[17] << 8) | pData[16]));
	}

	if ((bWindSpeedValid)&&(bWindDirectionValid))
	{
		memset(&tsen,0,sizeof(RBUF));
		tsen.WIND.packetlength=sizeof(tsen.WIND)-1;
		tsen.WIND.packettype=pTypeWIND;
		tsen.WIND.subtype=sTypeWINDNoTemp;
		tsen.WIND.battery_level=9;
		tsen.WIND.rssi=12;
		tsen.WIND.id1=0;
		tsen.WIND.id2=1;

		int aw=round(WindDirection);
		tsen.WIND.directionh=(BYTE)(aw/256);
		aw-=(tsen.WIND.directionh*256);
		tsen.WIND.directionl=(BYTE)(aw);

		tsen.WIND.av_speedh=0;
		tsen.WIND.av_speedl=0;
		int sw=round(WindSpeed*10.0f);
		tsen.WIND.av_speedh=(BYTE)(sw/256);
		sw-=(tsen.WIND.av_speedh*256);
		tsen.WIND.av_speedl=(BYTE)(sw);

		tsen.WIND.gusth=0;
		tsen.WIND.gustl=0;

		//this is not correct, why no wind temperature? and only chill?
		tsen.WIND.chillh=0;
		tsen.WIND.chilll=0;
		tsen.WIND.temperatureh=0;
		tsen.WIND.temperaturel=0;
		if (bOutsideTemperatureValid)
		{
			tsen.WIND.tempsign=(OutsideTemperature>=0)?0:1;
			tsen.WIND.chillsign=(OutsideTemperature>=0)?0:1;
			int at10=round(abs(OutsideTemperature*10.0f));
			tsen.WIND.temperatureh=(BYTE)(at10/256);
			tsen.WIND.chillh=(BYTE)(at10/256);
			at10-=(tsen.WIND.chillh*256);
			tsen.WIND.temperaturel=(BYTE)(at10);
			tsen.WIND.chilll=(BYTE)(at10);
		}

		sDecodeRXMessage(this, (const unsigned char *)&tsen.WIND);//decode message
	}

	//UV
	if (pData[43]!=0xFF)
	{
		UV=(pData[43])/10.0f;
		if (UV<100)
			bUVValid=true;
	}
	if (bUVValid)
	{
		RBUF tsen;
		memset(&tsen,0,sizeof(RBUF));
		tsen.UV.packetlength=sizeof(tsen.UV)-1;
		tsen.UV.packettype=pTypeUV;
		tsen.UV.subtype=sTypeUV1;
		tsen.UV.battery_level=9;
		tsen.UV.rssi=12;
		tsen.UV.id1=0;
		tsen.UV.id2=1;

		tsen.UV.uv=(BYTE)round(UV*10);
		sDecodeRXMessage(this, (const unsigned char *)&tsen.UV);//decode message
	}
	
	//Rain Rate
	if ((pData[41]!=0xFF)&&(pData[42]!=0xFF))
	{
		float rainRate=((unsigned int)((pData[42] << 8) | pData[41])) / 100.0f; //inches
		rainRate*=25.4f; //mm
	}
	//Rain Day
	if ((pData[50]!=0xFF)&&(pData[51]!=0xFF))
	{
		float rainDay=((unsigned int)((pData[51] << 8) | pData[50])) / 100.0f; //inches
		rainDay*=25.4f; //mm
	}
	//Rain Year
	if ((pData[54]!=0xFF)&&(pData[55]!=0xFF))
	{
		float rainYear=((unsigned int)((pData[55] << 8) | pData[54])) / 100.0f; //inches
		rainYear*=25.4f; //mm

		RBUF tsen;
		memset(&tsen,0,sizeof(RBUF));
		tsen.RAIN.packetlength=sizeof(tsen.RAIN)-1;
		tsen.RAIN.packettype=pTypeRAIN;
		tsen.RAIN.subtype=sTypeRAIN3;
		tsen.RAIN.battery_level=9;
		tsen.RAIN.rssi=12;
		tsen.RAIN.id1=0;
		tsen.RAIN.id2=1;

		tsen.RAIN.rainrateh=0;
		tsen.RAIN.rainratel=0;

		int tr10=int(float(rainYear)*10.0f);

		tsen.RAIN.raintotal1=0;
		tsen.RAIN.raintotal2=(BYTE)(tr10/256);
		tr10-=(tsen.RAIN.raintotal2*256);
		tsen.RAIN.raintotal3=(BYTE)(tr10);

		sDecodeRXMessage(this, (const unsigned char *)&tsen.RAIN);//decode message
	}

	//Solar Radiation
	if ((pData[44]!=0xFF)&&(pData[45]!=0x7F))
	{
		unsigned int solarRadiation=((unsigned int)((pData[45] << 8) | pData[44]));//Watt/M2
		_tGeneralDevice gdevice;
		gdevice.subtype=sTypeSolarRadiation;
		gdevice.floatval1=float(solarRadiation);
		sDecodeRXMessage(this, (const unsigned char *)&gdevice);

	}

	//Soil Moistures
	for (int iMoister=0; iMoister<4; iMoister++)
	{
		if (pData[62+iMoister]!=0xFF)
		{
			int moister=pData[62+iMoister];
			SendMoistureSensor(1 + iMoister, 255, moister, "Moisture");
		}
	}

	//Leaf Wetness
	for (int iLeaf=0; iLeaf<4; iLeaf++)
	{
		if (pData[66+iLeaf]!=0xFF)
		{
			int leaf_wetness=pData[66+iLeaf];

			_tGeneralDevice gdevice;
			gdevice.subtype=sTypeLeafWetness;
			gdevice.intval1=leaf_wetness;
			gdevice.id=1+iLeaf;
			sDecodeRXMessage(this, (const unsigned char *)&gdevice);
		}
	}

	return true;
}