Fix for SHT21 HTU21 humidity value was wrong

This commit is contained in:
norbert-walter 2022-04-13 18:50:06 +02:00
parent 0196ff8ecd
commit 52246b287a
2 changed files with 43 additions and 3 deletions

View File

@ -460,7 +460,7 @@ FormatedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
else if (value->getFormat() == "formatXdr:C:K"){
double temperature = 0;
if(usesimudata == false) {
temperature = value->value;
temperature = value->value - 273.15; // Convert K to C
}
else{
temperature = 21.8 + float(random(0, 50)) / 10.0;
@ -474,7 +474,47 @@ FormatedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
if(temperature >= 100){
snprintf(buffer,bsize,"%3.0f",temperature);
}
result.unit = "K";
result.unit = "Deg C";
}
//########################################################
else if (value->getFormat() == "formatXdr:C:C"){
double temperature = 0;
if(usesimudata == false) {
temperature = value->value; // Value in C
}
else{
temperature = 21.8 + float(random(0, 50)) / 10.0;
}
if(temperature < 10){
snprintf(buffer,bsize,"%3.2f",temperature);
}
if(temperature >= 10 && temperature < 100){
snprintf(buffer,bsize,"%3.1f",temperature);
}
if(temperature >= 100){
snprintf(buffer,bsize,"%3.0f",temperature);
}
result.unit = "Deg C";
}
//########################################################
else if (value->getFormat() == "formatXdr:H:P"){
double humidity = 0;
if(usesimudata == false) {
humidity = value->value; // Value in %
}
else{
humidity = 41.3 + float(random(0, 50)) / 10.0;
}
if(humidity < 10){
snprintf(buffer,bsize,"%3.2f",humidity);
}
if(humidity >= 10 && humidity < 100){
snprintf(buffer,bsize,"%3.1f",humidity);
}
if(humidity >= 100){
snprintf(buffer,bsize,"%3.0f",humidity);
}
result.unit = "%";
}
//########################################################
else if (value->getFormat() == "formatXdr:A:D"){

View File

@ -348,7 +348,7 @@ void sensorTask(void *param){
}
else if((envsensor == "SHT21" || envsensor == "HTU21") && SHT21_ready == true){
sensors.airHumidity = sht21.readCompensatedHumidity();
sensors.airHumidity = sht21.readTemperature();
sensors.airTemperature = sht21.readTemperature();
// Send to NMEA200 bus
if(!isnan(sensors.airTemperature)){
SetN2kPGN130312(N2kMsg, 0, 0,(tN2kTempSource) TempSource, CToKelvin(sensors.airTemperature), N2kDoubleNA);