Skip to content

Commit

Permalink
Rename item HUMI to HUMIDITY and TEMP to TEMPERATURE.
Browse files Browse the repository at this point in the history
  • Loading branch information
bertrik committed Dec 7, 2023
1 parent b6ecfd5 commit 9b93ce2
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 34 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ ttn:
- path: "/pm2p5"
item: "PM2_5"
- path: "/rh"
item: "HUMI"
item: "HUMIDITY"
- path: "/temp"
item: "TEMP"
item: "TEMPERATURE"
- name: "ttn-soundkit"
key: "secret"
decoder:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ SensorData decodeTtnMessage(DecoderConfig config, TtnUplinkMessage uplink) throw
TtnUlmMessage ulmMessage = TtnUlmMessage.parse(uplink.getRawPayload());
sensorData.addValue(ESensorItem.PM10, ulmMessage.getPm10());
sensorData.addValue(ESensorItem.PM2_5, ulmMessage.getPm2_5());
sensorData.addValue(ESensorItem.HUMI, ulmMessage.getRhPerc());
sensorData.addValue(ESensorItem.TEMP, ulmMessage.getTempC());
sensorData.addValue(ESensorItem.HUMIDITY, ulmMessage.getRhPerc());
sensorData.addValue(ESensorItem.TEMPERATURE, ulmMessage.getTempC());
break;
case CAYENNE:
TtnCayenneMessage cayenne = TtnCayenneMessage.parse(uplink.getRawPayload());
Expand All @@ -176,10 +176,10 @@ SensorData decodeTtnMessage(DecoderConfig config, TtnUplinkMessage uplink) throw
sensorData.addValue(ESensorItem.PM1_0, cayenne.getPm1_0());
}
if (cayenne.hasRhPerc()) {
sensorData.addValue(ESensorItem.HUMI, cayenne.getRhPerc());
sensorData.addValue(ESensorItem.HUMIDITY, cayenne.getRhPerc());
}
if (cayenne.hasTempC()) {
sensorData.addValue(ESensorItem.TEMP, cayenne.getTempC());
sensorData.addValue(ESensorItem.TEMPERATURE, cayenne.getTempC());
}
if (cayenne.hasPressureMillibar()) {
sensorData.addValue(ESensorItem.PRESSURE, 100.0 * cayenne.getPressureMillibar());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ public void scheduleUpload(AppDeviceId appDeviceId, SensorData data) {

// humidity/temperature/pressure
String meteoPrefix = getMeteoPrefix(data);
if (data.hasValue(ESensorItem.HUMI)) {
message.addItem(meteoPrefix + "humidity", data.getValue(ESensorItem.HUMI));
if (data.hasValue(ESensorItem.HUMIDITY)) {
message.addItem(meteoPrefix + "humidity", data.getValue(ESensorItem.HUMIDITY));
}
if (data.hasValue(ESensorItem.TEMP)) {
message.addItem(meteoPrefix + "temperature", data.getValue(ESensorItem.TEMP));
if (data.hasValue(ESensorItem.TEMPERATURE)) {
message.addItem(meteoPrefix + "temperature", data.getValue(ESensorItem.TEMPERATURE));
}
if (data.hasValue(ESensorItem.PRESSURE)) {
message.addItem(meteoPrefix + "pressure", data.getValue(ESensorItem.PRESSURE));
Expand All @@ -103,7 +103,8 @@ public void scheduleUpload(AppDeviceId appDeviceId, SensorData data) {
}

private String getMeteoPrefix(SensorData data) {
if (data.hasValue(ESensorItem.HUMI) && data.hasValue(ESensorItem.TEMP) && data.hasValue(ESensorItem.PRESSURE)) {
if (data.hasValue(ESensorItem.HUMIDITY) && data.hasValue(ESensorItem.TEMPERATURE)
&& data.hasValue(ESensorItem.PRESSURE)) {
return "BME280_";
}
return "";
Expand All @@ -128,8 +129,8 @@ private void uploadMeasurement(String boxId, String sensComId, SensComMessage me
String result = response.body();
LOG.info("Upload for {} to opensense box {} success: {}", sensComId, boxId, result);
} else {
LOG.warn("Upload for {} to opensense box {} failure: {} - {}", sensComId, boxId,
response.code(), response.errorBody().string());
LOG.warn("Upload for {} to opensense box {} failure: {} - {}", sensComId, boxId, response.code(),
response.errorBody().string());
}
} catch (IOException e) {
LOG.warn("Caught IOException: {}", e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public enum ESensorItem {

PM_TPS("Typical particle size, in um"),

HUMI("Relative humidity, in percent", 0, 100),
TEMP("Temperature, in degrees Celcius", -100, 100),
HUMIDITY("Relative humidity, in percent", 0, 100),
TEMPERATURE("Temperature, in degrees Celcius", -100, 100),
PRESSURE("Atmospheric pressure, in Pa", 0, 1E6),

POS_LAT("Latitude in degrees", -90, 90),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,20 @@ private void performUpload(AppDeviceId appDeviceId, SensorData data) {
}

// pin 3: temperature & pressure, but no humidity
if (data.hasValue(ESensorItem.TEMP) && data.hasValue(ESensorItem.PRESSURE)
&& !data.hasValue(ESensorItem.HUMI)) {
if (data.hasValue(ESensorItem.TEMPERATURE) && data.hasValue(ESensorItem.PRESSURE)
&& !data.hasValue(ESensorItem.HUMIDITY)) {
SensComMessage p3Message = new SensComMessage(softwareVersion);
p3Message.addItem("temperature", data.getValue(ESensorItem.TEMP));
p3Message.addItem("temperature", data.getValue(ESensorItem.TEMPERATURE));
p3Message.addItem("pressure", data.getValue(ESensorItem.PRESSURE));
uploadMeasurement(ESensComPin.TEMPERATURE_PRESSURE, sensorId, p3Message);
}

// pin 7: temperature & humidity, but no pressure
if (data.hasValue(ESensorItem.TEMP) && data.hasValue(ESensorItem.HUMI)
if (data.hasValue(ESensorItem.TEMPERATURE) && data.hasValue(ESensorItem.HUMIDITY)
&& !data.hasValue(ESensorItem.PRESSURE)) {
SensComMessage p7Message = new SensComMessage(softwareVersion);
p7Message.addItem("temperature", data.getValue(ESensorItem.TEMP));
p7Message.addItem("humidity", data.getValue(ESensorItem.HUMI));
p7Message.addItem("temperature", data.getValue(ESensorItem.TEMPERATURE));
p7Message.addItem("humidity", data.getValue(ESensorItem.HUMIDITY));
uploadMeasurement(ESensComPin.TEMPERATURE_HUMIDITY, sensorId, p7Message);
}

Expand All @@ -149,19 +149,20 @@ private void performUpload(AppDeviceId appDeviceId, SensorData data) {
}

// pin 11: temperature & humidity & pressure
if (data.hasValue(ESensorItem.TEMP) && data.hasValue(ESensorItem.HUMI) && data.hasValue(ESensorItem.PRESSURE)) {
if (data.hasValue(ESensorItem.TEMPERATURE) && data.hasValue(ESensorItem.HUMIDITY)
&& data.hasValue(ESensorItem.PRESSURE)) {
SensComMessage p11Message = new SensComMessage(softwareVersion);
p11Message.addItem("temperature", data.getValue(ESensorItem.TEMP));
p11Message.addItem("humidity", data.getValue(ESensorItem.HUMI));
p11Message.addItem("temperature", data.getValue(ESensorItem.TEMPERATURE));
p11Message.addItem("humidity", data.getValue(ESensorItem.HUMIDITY));
p11Message.addItem("pressure", data.getValue(ESensorItem.PRESSURE));
uploadMeasurement(ESensComPin.TEMPERATURE_HUMIDITY_PRESSURE, sensorId, p11Message);
}

// pin 13: only temperature
if (data.hasValue(ESensorItem.TEMP) && !data.hasValue(ESensorItem.HUMI)
if (data.hasValue(ESensorItem.TEMPERATURE) && !data.hasValue(ESensorItem.HUMIDITY)
&& !data.hasValue(ESensorItem.PRESSURE)) {
SensComMessage p13Message = new SensComMessage(softwareVersion);
p13Message.addItem("temperature", data.getValue(ESensorItem.TEMP));
p13Message.addItem("temperature", data.getValue(ESensorItem.TEMPERATURE));
uploadMeasurement(ESensComPin.TEMPERATURE, sensorId, p13Message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ private DecoderConfig createApeldoornDecoder() {
JsonDecoderConfig jsonConfig = new JsonDecoderConfig();
jsonConfig.add(new JsonDecoderItem("/pm10", ESensorItem.PM10));
jsonConfig.add(new JsonDecoderItem("/pm2p5", ESensorItem.PM2_5));
jsonConfig.add(new JsonDecoderItem("/rh", ESensorItem.HUMI));
jsonConfig.add(new JsonDecoderItem("/temp", ESensorItem.TEMP));
jsonConfig.add(new JsonDecoderItem("/rh", ESensorItem.HUMIDITY));
jsonConfig.add(new JsonDecoderItem("/temp", ESensorItem.TEMPERATURE));
return new DecoderConfig(EPayloadEncoding.JSON, new POJONode(jsonConfig));
}

Expand All @@ -66,8 +66,8 @@ private DecoderConfig createSoundkitDecoder() {

private DecoderConfig createMjsDecoder() {
JsonDecoderConfig jsonConfig = new JsonDecoderConfig();
jsonConfig.add(new JsonDecoderItem("/temperature", ESensorItem.TEMP));
jsonConfig.add(new JsonDecoderItem("/humidity", ESensorItem.HUMI));
jsonConfig.add(new JsonDecoderItem("/temperature", ESensorItem.TEMPERATURE));
jsonConfig.add(new JsonDecoderItem("/humidity", ESensorItem.HUMIDITY));
jsonConfig.add(new JsonDecoderItem("/pm10", ESensorItem.PM10));
jsonConfig.add(new JsonDecoderItem("/pm2_5", ESensorItem.PM2_5));
return new DecoderConfig(EPayloadEncoding.JSON, new POJONode(jsonConfig));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public void testInRange() {
SensorData sensorData = new SensorData();

// value in range
Assert.assertTrue(sensorData.addValue(ESensorItem.HUMI, 100.0));
Assert.assertTrue(sensorData.hasValue(ESensorItem.HUMI));
Assert.assertEquals(100.0, sensorData.getValue(ESensorItem.HUMI), 0.1);
Assert.assertTrue(sensorData.addValue(ESensorItem.HUMIDITY, 100.0));
Assert.assertTrue(sensorData.hasValue(ESensorItem.HUMIDITY));
Assert.assertEquals(100.0, sensorData.getValue(ESensorItem.HUMIDITY), 0.1);

// value out of range
Assert.assertFalse(sensorData.addValue(ESensorItem.PM10, -1.0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private void run() {
uploader.scheduleProcessAttributes(attributes);

SensorData sensorData = new SensorData();
sensorData.addValue(ESensorItem.TEMP, 12.34);
sensorData.addValue(ESensorItem.TEMPERATURE, 12.34);
uploader.scheduleUpload(id, sensorData);
}

Expand Down

0 comments on commit 9b93ce2

Please sign in to comment.