Skip to content

Commit

Permalink
Hopefully stopped bad 25C reading from getting into a packet
Browse files Browse the repository at this point in the history
  • Loading branch information
retrodaredevil committed Apr 19, 2021
1 parent d988ef6 commit 186e683
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ public AddStatusParameters getStatus(long dayStartTimeMillis, List<FragmentedPac
IdentifierFragment identifierFragment = IdentifierFragment.create(fragmentId, temperaturePacket.getIdentifier());
if (temperatureIdentifierFragmentMatcher.matches(identifierFragment)) {
float temperatureCelsius = temperaturePacket.getTemperatureCelsius();
addStatusParametersBuilder.setTemperatureCelsius(temperatureCelsius);
if (!TemperaturePacket.POSSIBLE_BAD_VALUES.contains(temperatureCelsius)) {
addStatusParametersBuilder.setTemperatureCelsius(temperatureCelsius);
} else {
System.out.println("Not setting temperature: " + temperatureCelsius + " because it could be a bad reading");
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@
import me.retrodaredevil.solarthing.annotations.NotNull;
import me.retrodaredevil.solarthing.misc.common.SourcedData;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

@JsonDeserialize(as = CelsiusTemperaturePacket.class)
@JsonExplicit
@JsonTypeName("TEMPERATURE")
public interface TemperaturePacket extends WeatherPacket, SourcedData {
/**
* Represents temperature celsius values that might indicate a bad reading
*/
Set<Float> POSSIBLE_BAD_VALUES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(0.0f, 25.0f)));

@DefaultFinal
@Override
default @NotNull WeatherPacketType getPacketType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public void receive(List<Packet> packets, InstantType instantType) {
if (line1.contains("crc=00")) {
LOGGER.debug("CRC start with 0! Maybe bad? line1: " + line1 + " raw temp: " + temperatureRaw);
}
if ((temperatureRaw == 0 || temperatureRaw == 25000) && line1.contains("crc=00")) { // when it's a bad reading, the crc is 0
if (temperatureRaw == 0 && line1.contains("crc=00")
|| temperatureRaw == 25000 && (line1.contains("crc=4e") || line1.contains("crc=b4"))) { // If 0C and crc=0, then bad reading. Also bad reading if 25C and crc=4e or crc=b4
LOGGER.debug("crc=00! name=" + name + " line1: " + line1 + " line2: " + line2); // debug since this is so common
return;
}
Expand Down

0 comments on commit 186e683

Please sign in to comment.