Skip to content

Commit

Permalink
Refacotor to zcl compaint co2 attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
nurikk committed Sep 27, 2020
1 parent 6801b49 commit b5c453c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Source/zcl_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ static void zclApp_ReadSensors(void) {
bdb_RepChangedAttrValue(zclApp_FirstEP.EndPoint, TEMP, ATTRID_MS_TEMPERATURE_MEASURED_VALUE);
bdb_RepChangedAttrValue(zclApp_FirstEP.EndPoint, PRESSURE, ATTRID_MS_PRESSURE_MEASUREMENT_MEASURED_VALUE);
bdb_RepChangedAttrValue(zclApp_FirstEP.EndPoint, HUMIDITY, ATTRID_MS_RELATIVE_HUMIDITY_MEASURED_VALUE);

bdb_RepChangedAttrValue(zclApp_FirstEP.EndPoint, CO2, ATTRID_CO2_MEASURED_VALUE);
currentSensorsReadingPhase = 0;
zclApp_LedFeedback();
break;
Expand Down
12 changes: 8 additions & 4 deletions Source/zcl_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ extern "C" {
#define HUMIDITY ZCL_CLUSTER_ID_MS_RELATIVE_HUMIDITY
#define PRESSURE ZCL_CLUSTER_ID_MS_PRESSURE_MEASUREMENT

//Carbon Dioxide (CO2)
#define CO2 0x040d


// Carbon Dioxide (CO2)
#define ATTRID_MS_TEMPERATURE_MEASUREMENT_CO2_LEVEL_MEASURED_VALUE 0x0200
#define ATTRID_CO2_TOLERANCE 0x0201
#define ATTRID_CO2_MEASURED_VALUE 0x0000
#define ATTRID_CO2_TOLERANCE 0x0003
#define ATTRID_ENABLE_ABC 0x0202
#define ATTRID_LED_FEEDBACK 0x0203
#define ATTRID_THRESHOLD1_PPM 0x0204
Expand All @@ -58,15 +62,15 @@ extern "C" {
*/

typedef struct {
uint16 SensorTolerance;
float SensorTolerance;
uint8 LedFeedback;
uint8 EnableABC;
uint16 Threshold1_PPM;
uint16 Threshold2_PPM;
} application_config_t;

typedef struct {
uint16 CO2_PPM;
float CO2_PPM;
int16 Temperature;
int16 BME280_Temperature_Sensor_MeasuredValue;
int16 BME280_PressureSensor_MeasuredValue;
Expand Down
12 changes: 6 additions & 6 deletions Source/zcl_app_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ CONST zclAttrRec_t zclApp_AttrsFirstEP[] = {
{PRESSURE, {ATTRID_MS_PRESSURE_MEASUREMENT_MEASURED_VALUE_HPA, ZCL_UINT32, RR, (void *)&zclApp_Sensors.BME280_PressureSensor_MeasuredValueHPA}},
{HUMIDITY, {ATTRID_MS_RELATIVE_HUMIDITY_MEASURED_VALUE, ZCL_UINT16, RR, (void *)&zclApp_Sensors.BME280_HumiditySensor_MeasuredValue}},

{TEMP, {ATTRID_MS_TEMPERATURE_MEASUREMENT_CO2_LEVEL_MEASURED_VALUE, ZCL_UINT16, RR, (void *)&zclApp_Sensors.CO2_PPM}},
{TEMP, {ATTRID_CO2_TOLERANCE, ZCL_UINT8, RW, (void *)&zclApp_Config.SensorTolerance}},
{TEMP, {ATTRID_ENABLE_ABC, ZCL_DATATYPE_BOOLEAN, RW, (void *)&zclApp_Config.EnableABC}},
{TEMP, {ATTRID_LED_FEEDBACK, ZCL_DATATYPE_BOOLEAN, RW, (void *)&zclApp_Config.LedFeedback}},
{TEMP, {ATTRID_THRESHOLD1_PPM, ZCL_UINT16, RW, (void *)&zclApp_Config.Threshold1_PPM}},
{TEMP, {ATTRID_THRESHOLD2_PPM, ZCL_UINT16, RW, (void *)&zclApp_Config.Threshold2_PPM}}
{CO2, {ATTRID_CO2_MEASURED_VALUE, ZCL_SINGLE, RR, (void *)&zclApp_Sensors.CO2_PPM}},
{CO2, {ATTRID_CO2_TOLERANCE, ZCL_SINGLE, RW, (void *)&zclApp_Config.SensorTolerance}},
{CO2, {ATTRID_ENABLE_ABC, ZCL_DATATYPE_BOOLEAN, RW, (void *)&zclApp_Config.EnableABC}},
{CO2, {ATTRID_LED_FEEDBACK, ZCL_DATATYPE_BOOLEAN, RW, (void *)&zclApp_Config.LedFeedback}},
{CO2, {ATTRID_THRESHOLD1_PPM, ZCL_UINT16, RW, (void *)&zclApp_Config.Threshold1_PPM}},
{CO2, {ATTRID_THRESHOLD2_PPM, ZCL_UINT16, RW, (void *)&zclApp_Config.Threshold2_PPM}}
};


Expand Down
36 changes: 8 additions & 28 deletions converters/DIYRuZ_AirSense.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@ const {
} = require('zigbee-herdsman-converters');

const ATTRID_MS_PRESSURE_MEASUREMENT_MEASURED_VALUE_HPA = 0x0200; // non standart attribute, max precision
const ATTRID_MS_TEMPERATURE_MEASUREMENT_CO2_LEVEL_MEASURED_VALUE = 0x0200; //custom attribute for co2 readings
const ZCL_DATATYPE_UINT16 = 0x21;
const ZCL_DATATYPE_UINT32 = 0x23;




const CO2_LEVEL_KEY = ATTRID_MS_TEMPERATURE_MEASUREMENT_CO2_LEVEL_MEASURED_VALUE.toString();
const EXT_PRESSURE_KEY = ATTRID_MS_PRESSURE_MEASUREMENT_MEASURED_VALUE_HPA.toString();

const bind = async (endpoint, target, clusters) => {
Expand All @@ -22,14 +15,12 @@ const bind = async (endpoint, target, clusters) => {

const fz = {
co2: {
cluster: 'msTemperatureMeasurement',
cluster: 'msCO2',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
if (msg.data[CO2_LEVEL_KEY]) {
return {
co2: msg.data[CO2_LEVEL_KEY]
};
}
return {
co2: msg.data.measuredValue
};
},
},
extended_pressure: {
Expand Down Expand Up @@ -113,7 +104,8 @@ const device = {
await bind(firstEndpoint, coordinatorEndpoint, [
'msTemperatureMeasurement',
'msRelativeHumidity',
'msPressureMeasurement'
'msPressureMeasurement',
'msCO2'
]);

const msBindPayload = [{
Expand All @@ -123,20 +115,8 @@ const device = {
reportableChange: 0,
}];

const co2ReportingPayload = [
...msBindPayload,
{
attribute: {
ID: ATTRID_MS_TEMPERATURE_MEASUREMENT_CO2_LEVEL_MEASURED_VALUE,
type: ZCL_DATATYPE_UINT16,
},
minimumReportInterval: 0,
maximumReportInterval: 3600,
reportableChange: 0,
},
];
await firstEndpoint.configureReporting('msTemperatureMeasurement', co2ReportingPayload);

await firstEndpoint.configureReporting('msCO2', msBindPayload);
await firstEndpoint.configureReporting('msTemperatureMeasurement', msBindPayload);
await firstEndpoint.configureReporting('msRelativeHumidity', msBindPayload);

const pressureBindPayload = [
Expand Down

0 comments on commit b5c453c

Please sign in to comment.