[fineoffsetweatherstation] Implement new Measurand free-heap-size (#16461)

Signed-off-by: Andreas Berger <andreas@berger-freelancer.com>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
Andreas Berger 2024-02-27 10:57:56 +01:00 committed by Ciprian Pascu
parent cb8b3fb125
commit bd30f718d9
7 changed files with 40 additions and 4 deletions

View File

@ -19,7 +19,7 @@ Here is a product picture of how this Weather Station looks like:
![WH2650](doc/WH2650.png)
This binding works offline by [implementing the wire protocol](https://osswww.ecowitt.net/uploads/20220407/WN1900%20GW1000,1100%20WH2680,2650%20telenet%20v1.6.4.pdf) of the WiFi gateway device.
This binding works offline by [implementing the wire protocol](https://community.openhab.org/uploads/short-url/cuV8oOaCYHZhdm0hVJUN7hxMMfe.pdf) of the WiFi gateway device.
## Discussion
@ -27,7 +27,7 @@ If you have any issues or feedback, please feel free to [get in touch via the co
## Supported Things
- `weatherstation`: A Fine Offset gateway device with the ThingTypeUID `fineoffsetweatherstation:weatherstation` which supports the [wire protocol](https://osswww.ecowitt.net/uploads/20220407/WN1900%20GW1000,1100%20WH2680,2650%20telenet%20v1.6.4.pdf) e.g.:
- `weatherstation`: A Fine Offset gateway device with the ThingTypeUID `fineoffsetweatherstation:weatherstation` which supports the [wire protocol](https://community.openhab.org/uploads/short-url/cuV8oOaCYHZhdm0hVJUN7hxMMfe.pdf) e.g.:
- HP2550
- HP3500
- GW1000
@ -280,6 +280,7 @@ Valid sensors:
| piezo-rain-week | Number:Length | R | Piezo - Rainfall this Week |
| piezo-rain-month | Number:Length | R | Piezo - Rainfall this Month |
| piezo-rain-year | Number:Length | R | Piezo - Rainfall this Year |
| free-heap-size | Number:DataAmount | R | Free Heap Size |
NOTE: Not every gateway provides all available data, even if they are displayed in the WS-View app.
Especially the channels `temperature-dew-point` or `temperature-wind-chill` are derived from other measured values.

View File

@ -54,6 +54,8 @@ public class FineOffsetWeatherStationBindingConstants {
public static final ChannelTypeUID CHANNEL_TYPE_LIGHTNING_DISTANCE = new ChannelTypeUID(BINDING_ID,
"lightning-distance");
public static final ChannelTypeUID CHANNEL_TYPE_FREE_HEAP_SIZE = new ChannelTypeUID(BINDING_ID, "free-heap-size");
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_GATEWAY, THING_TYPE_SENSOR);
public static final String SENSOR_CHANNEL_SIGNAL = "signal";

View File

@ -12,6 +12,7 @@
*/
package org.openhab.binding.fineoffsetweatherstation.internal.domain;
import static org.openhab.binding.fineoffsetweatherstation.internal.FineOffsetWeatherStationBindingConstants.CHANNEL_TYPE_FREE_HEAP_SIZE;
import static org.openhab.binding.fineoffsetweatherstation.internal.FineOffsetWeatherStationBindingConstants.CHANNEL_TYPE_MAX_WIND_SPEED;
import static org.openhab.binding.fineoffsetweatherstation.internal.FineOffsetWeatherStationBindingConstants.CHANNEL_TYPE_MOISTURE;
import static org.openhab.binding.fineoffsetweatherstation.internal.FineOffsetWeatherStationBindingConstants.CHANNEL_TYPE_UV_INDEX;
@ -131,9 +132,9 @@ public enum Measurand {
LEAK_CHX("water-leak-channel", new int[] { 0x58, 0x59, 0x5A, 0x5B }, "Leak", MeasureType.WATER_LEAK_DETECTION),
// `LIGHTNING` is the name in the spec, so we keep it here as it
LIGHTNING("lightning-distance", 0x60, "lightning distance 1~40KM", MeasureType.LIGHTNING_DISTANCE),
LIGHTNING("lightning-distance", 0x60, "Lightning distance 1~40KM", MeasureType.LIGHTNING_DISTANCE),
LIGHTNING_TIME("lightning-time", 0x61, "lightning happened time", MeasureType.LIGHTNING_TIME),
LIGHTNING_TIME("lightning-time", 0x61, "Lightning happened time", MeasureType.LIGHTNING_TIME),
// `LIGHTNING_POWER` is the name in the spec, so we keep it here as it
LIGHTNING_POWER("lightning-counter", 0x62, "lightning counter for the day", MeasureType.LIGHTNING_COUNTER),
@ -143,6 +144,9 @@ public enum Measurand {
// skip battery-level, since it is read via Command.CMD_READ_SENSOR_ID_NEW
new Skip(1)),
// This is for heap : the available stack top. If it is reducing, it means the stack is using up.
ITEM_HEAP_FREE("free-heap-size", 0x6c, "Free Heap Size", MeasureType.MEMORY, CHANNEL_TYPE_FREE_HEAP_SIZE),
ITEM_SENSOR_CO2(0x70,
new MeasurandParser("sensor-co2-temperature", "Temperature (CO₂-Sensor)", MeasureType.TEMPERATURE),
new MeasurandParser("sensor-co2-humidity", "Humidity (CO₂-Sensor)", MeasureType.PERCENTAGE),

View File

@ -122,6 +122,7 @@ public enum MeasureType {
(data, offset) -> Utils.toUInt16(data, offset) / 10.),
BYTE(1, null, (data, offset, context) -> new DecimalType(toUInt8(data[offset]))),
MEMORY(Units.BYTE, 4, null, Utils::toUInt32),
DATE_TIME2(6, null, (data, offset, context) -> new DateTimeType(
ZonedDateTime.ofInstant(Instant.ofEpochSecond(toUInt32(data, offset)), context.getZoneId())));

View File

@ -30,6 +30,8 @@ channel-type.fineoffsetweatherstation.battery-voltage.label = Battery Voltage
channel-type.fineoffsetweatherstation.battery-voltage.description = The voltage of the battery
channel-type.fineoffsetweatherstation.co2.label = CO₂
channel-type.fineoffsetweatherstation.co2.description = Air Quality Indicator
channel-type.fineoffsetweatherstation.free-heap-size.description = The available heap size. If it is reducing, it means the heap is using up.
channel-type.fineoffsetweatherstation.free-heap-size.label = Free Heap Size
channel-type.fineoffsetweatherstation.humidity.label = Humidity
channel-type.fineoffsetweatherstation.illumination.label = Illumination
channel-type.fineoffsetweatherstation.lightning-counter.label = Lightning Counter
@ -136,3 +138,4 @@ gateway.dynamic-channel.piezo-rain-day.label = Rain Day
gateway.dynamic-channel.piezo-rain-week.label = Rain Week
gateway.dynamic-channel.piezo-rain-month.label = Rain Month
gateway.dynamic-channel.piezo-rain-year.label = Rain Year
gateway.dynamic-channel.free-heap-size.label = Free Stack Size

View File

@ -180,4 +180,11 @@
<label>Lightning Distance</label>
<state pattern="%.0f %unit%" readOnly="true"/>
</channel-type>
<channel-type id="free-heap-size" advanced="true">
<item-type>Number:DataAmount</item-type>
<label>Free Heap Size</label>
<description>The available heap size. If it is reducing, it means the heap is using up.</description>
<state pattern="%.0f %unit%" readOnly="true"/>
</channel-type>
</thing:thing-descriptions>

View File

@ -123,6 +123,24 @@ class FineOffsetDataParserTest {
new Tuple("sensor-co2-co2-24-hour-average", "891 ppm"));
}
@Test
void testLiveDataWithHeapFreeMeasurand() {
byte[] bytes = HexUtils.hexToBytes(
"FFFF27002F01010B062A0826C10926C1020011074D0A004C0B000C0C000D15000226C816006317011900136C0001FED864");
DebugDetails debugDetails = new DebugDetails(bytes, Command.CMD_GW1000_LIVEDATA, Protocol.DEFAULT);
List<MeasuredValue> data = new FineOffsetDataParser(Protocol.DEFAULT).getMeasuredValues(bytes,
new ConversionContext(ZoneOffset.UTC), debugDetails);
Assertions.assertThat(data)
.extracting(MeasuredValue::getChannelId, measuredValue -> measuredValue.getState().toString())
.containsExactly(new Tuple("temperature-indoor", "26.7 °C"), new Tuple("humidity-indoor", "42 %"),
new Tuple("pressure-absolute", "992.1 hPa"), new Tuple("pressure-relative", "992.1 hPa"),
new Tuple("temperature-outdoor", "1.7 °C"), new Tuple("humidity-outdoor", "77 %"),
new Tuple("direction-wind", "76 °"), new Tuple("speed-wind", "1.2 m/s"),
new Tuple("speed-gust", "1.3 m/s"), new Tuple("illumination", "14100 lx"),
new Tuple("irradiation-uv", "9.9 mW/m²"), new Tuple("uv-index", "1"),
new Tuple("wind-max-day", "1.9 m/s"), new Tuple("free-heap-size", "130776 B"));
}
@Test
void testLiveDataELV() {
byte[] data = HexUtils.hexToBytes(