Skip to content

Commit

Permalink
Implement msPressure ScaledValue
Browse files Browse the repository at this point in the history
  • Loading branch information
nurikk committed Oct 6, 2020
1 parent bc156fc commit e3d494d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Source/zcl_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ static void zclApp_ReadBME280(struct bme280_dev *dev) {
if (rslt == BME280_OK) {
LREP("ReadBME280 t=%ld, p=%ld, h=%ld\r\n", bme_results.temperature, bme_results.pressure, bme_results.humidity);
zclApp_Sensors.BME280_Temperature_Sensor_MeasuredValue = (int16)bme_results.temperature + zclApp_Config.TemperatureOffset;
zclApp_Sensors.BME280_PressureSensor_MeasuredValueHPA = bme_results.pressure + zclApp_Config.PressureOffset;
zclApp_Sensors.BME280_PressureSensor_ScaledValue = (int16) (pow(10.0, (double) zclApp_Sensors.BME280_PressureSensor_Scale) * (double) bme_results.pressure);
zclApp_Sensors.BME280_PressureSensor_MeasuredValue = bme_results.pressure / 100 + zclApp_Config.PressureOffset / 100;
zclApp_Sensors.BME280_HumiditySensor_MeasuredValue = (uint16)(bme_results.humidity * 100 / 1024) + zclApp_Config.HumidityOffset;
zclApp_Sensors.Temperature = (int16)bme_results.temperature + zclApp_Config.TemperatureOffset;
Expand Down
4 changes: 3 additions & 1 deletion Source/zcl_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ extern "C" {
#define ZCL_UINT8 ZCL_DATATYPE_UINT8
#define ZCL_UINT16 ZCL_DATATYPE_UINT16
#define ZCL_INT16 ZCL_DATATYPE_INT16
#define ZCL_INT8 ZCL_DATATYPE_INT8
#define ZCL_INT32 ZCL_DATATYPE_INT32
#define ZCL_UINT32 ZCL_DATATYPE_UINT32
#define ZCL_SINGLE ZCL_DATATYPE_SINGLE_PREC
Expand All @@ -85,7 +86,8 @@ typedef struct {
int16 Temperature;
int16 BME280_Temperature_Sensor_MeasuredValue;
int16 BME280_PressureSensor_MeasuredValue;
uint32 BME280_PressureSensor_MeasuredValueHPA;
int16 BME280_PressureSensor_ScaledValue;
int8 BME280_PressureSensor_Scale;
uint16 BME280_HumiditySensor_MeasuredValue;
} sensors_state_t;

Expand Down
6 changes: 4 additions & 2 deletions Source/zcl_app_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ sensors_state_t zclApp_Sensors = {
.Temperature = 0,
.BME280_Temperature_Sensor_MeasuredValue = 0,
.BME280_PressureSensor_MeasuredValue = 0,
.BME280_PressureSensor_MeasuredValueHPA= 0,
.BME280_PressureSensor_ScaledValue = 0,
.BME280_PressureSensor_Scale = -1,
.BME280_HumiditySensor_MeasuredValue = 0
};

Expand All @@ -105,7 +106,8 @@ CONST zclAttrRec_t zclApp_AttrsFirstEP[] = {


{PRESSURE, {ATTRID_MS_PRESSURE_MEASUREMENT_MEASURED_VALUE, ZCL_INT16, RR, (void *)&zclApp_Sensors.BME280_PressureSensor_MeasuredValue}},
{PRESSURE, {ATTRID_MS_PRESSURE_MEASUREMENT_MEASURED_VALUE_HPA, ZCL_UINT32, RR, (void *)&zclApp_Sensors.BME280_PressureSensor_MeasuredValueHPA}},
{PRESSURE, {ATTRID_MS_PRESSURE_MEASUREMENT_SCALED_VALUE, ZCL_INT16, RR, (void *)&zclApp_Sensors.BME280_PressureSensor_ScaledValue}},
{PRESSURE, {ATTRID_MS_PRESSURE_MEASUREMENT_SCALE, ZCL_INT8, RR, (void *)&zclApp_Sensors.BME280_PressureSensor_Scale}},
{PRESSURE, {ATTRID_PressureOffset, ZCL_INT32, RW, (void *)&zclApp_Config.PressureOffset}},

{HUMIDITY, {ATTRID_MS_RELATIVE_HUMIDITY_MEASURED_VALUE, ZCL_UINT16, RR, (void *)&zclApp_Sensors.BME280_HumiditySensor_MeasuredValue}},
Expand Down
29 changes: 3 additions & 26 deletions converters/DIYRuZ_AirSense.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,13 @@ const {
toZigbeeConverters,
} = require('zigbee-herdsman-converters');

const ATTRID_MS_PRESSURE_MEASUREMENT_MEASURED_VALUE_HPA = 0x0200; // non standart attribute, max precision
const ZCL_DATATYPE_UINT32 = 0x23;
const EXT_PRESSURE_KEY = ATTRID_MS_PRESSURE_MEASUREMENT_MEASURED_VALUE_HPA.toString();

const bind = async (endpoint, target, clusters) => {
for (const cluster of clusters) {
await endpoint.bind(cluster, target);
}
};

const fz = {
extended_pressure: {
cluster: 'msPressureMeasurement',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
let pressure = 0;
if (msg.data[EXT_PRESSURE_KEY]) {
pressure = msg.data[EXT_PRESSURE_KEY] / 100.0;
} else {
pressure = msg.data.measuredValue;
}
return {
pressure,
};
},
},
};

const hass = {
Expand Down Expand Up @@ -81,7 +62,7 @@ const device = {
fromZigbeeConverters.temperature,
fromZigbeeConverters.humidity,
fromZigbeeConverters.co2,
fz.extended_pressure,
fromZigbeeConverters.pressure,
],
toZigbee: [
toZigbeeConverters.factory_reset,
Expand Down Expand Up @@ -111,16 +92,12 @@ const device = {
await firstEndpoint.configureReporting('msRelativeHumidity', msBindPayload);

const pressureBindPayload = [
...msBindPayload,
{
attribute: {
ID: ATTRID_MS_PRESSURE_MEASUREMENT_MEASURED_VALUE_HPA,
type: ZCL_DATATYPE_UINT32,
},
attribute: 'scaledValue',
minimumReportInterval: 0,
maximumReportInterval: 3600,
reportableChange: 0,
},
}
];
await firstEndpoint.configureReporting('msPressureMeasurement', pressureBindPayload);
},
Expand Down

0 comments on commit e3d494d

Please sign in to comment.