Reading and sending real soil moisture works!
This commit is contained in:
parent
01bb9da2a4
commit
676b525bd9
7 changed files with 69 additions and 39 deletions
|
|
@ -12,6 +12,7 @@ include_directories(src)
|
||||||
|
|
||||||
target_sources(app PRIVATE
|
target_sources(app PRIVATE
|
||||||
src/main.c
|
src/main.c
|
||||||
|
src/prst_zb_soil_moisture_defs.c
|
||||||
)
|
)
|
||||||
|
|
||||||
add_subdirectory(../../prstlib prstlib)
|
add_subdirectory(../../prstlib prstlib)
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,20 @@
|
||||||
|
|
||||||
CONFIG_NCS_SAMPLES_DEFAULTS=y
|
CONFIG_NCS_SAMPLES_DEFAULTS=y
|
||||||
|
|
||||||
|
CONFIG_CBPRINTF_FP_SUPPORT=y
|
||||||
|
CONFIG_PWM=y
|
||||||
|
CONFIG_I2C=y
|
||||||
|
CONFIG_ADC=y
|
||||||
|
CONFIG_GPIO=y
|
||||||
|
|
||||||
|
CONFIG_PM=y
|
||||||
|
CONFIG_PM_DEVICE=y
|
||||||
|
|
||||||
|
CONFIG_NEWLIB_LIBC=y
|
||||||
|
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
|
||||||
|
|
||||||
CONFIG_UART_INTERRUPT_DRIVEN=y
|
CONFIG_UART_INTERRUPT_DRIVEN=y
|
||||||
CONFIG_SERIAL=y
|
CONFIG_SERIAL=y
|
||||||
CONFIG_GPIO=y
|
|
||||||
|
|
||||||
# Make sure printk is not printing to the UART console
|
# Make sure printk is not printing to the UART console
|
||||||
CONFIG_CONSOLE=y
|
CONFIG_CONSOLE=y
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,10 @@
|
||||||
|
|
||||||
#include <dk_buttons_and_leds.h>
|
#include <dk_buttons_and_leds.h>
|
||||||
#include <prstlib/adc.h>
|
#include <prstlib/adc.h>
|
||||||
|
#include <prstlib/button.h>
|
||||||
|
#include <prstlib/led.h>
|
||||||
|
#include <prstlib/macros.h>
|
||||||
|
#include <prstlib/sensors.h>
|
||||||
#include <prstlib/shtc3.h>
|
#include <prstlib/shtc3.h>
|
||||||
#include <zb_nrf_platform.h>
|
#include <zb_nrf_platform.h>
|
||||||
#include <zboss_api.h>
|
#include <zboss_api.h>
|
||||||
|
|
@ -25,27 +29,15 @@
|
||||||
#include "prst_zb_endpoint_defs.h"
|
#include "prst_zb_endpoint_defs.h"
|
||||||
#include "prst_zb_soil_moisture_defs.h"
|
#include "prst_zb_soil_moisture_defs.h"
|
||||||
|
|
||||||
#define PRST_ZIGBEE_ENDPOINT 10
|
|
||||||
#define IDENTIFY_MODE_BUTTON DK_BTN4_MSK
|
#define IDENTIFY_MODE_BUTTON DK_BTN4_MSK
|
||||||
#define FACTORY_RESET_BUTTON IDENTIFY_MODE_BUTTON
|
#define FACTORY_RESET_BUTTON IDENTIFY_MODE_BUTTON
|
||||||
#define PRST_BASIC_MANUF_NAME "b-parasite"
|
|
||||||
#define PRST_BASIC_MODEL_ID "b-parasite"
|
|
||||||
|
|
||||||
LOG_MODULE_REGISTER(app, LOG_LEVEL_INF);
|
LOG_MODULE_REGISTER(app, LOG_LEVEL_INF);
|
||||||
|
|
||||||
struct zb_device_ctx {
|
|
||||||
zb_zcl_basic_attrs_ext_t basic_attr;
|
|
||||||
zb_zcl_identify_attrs_t identify_attr;
|
|
||||||
// In units of 0.01 C.
|
|
||||||
zb_zcl_temp_measurement_attrs_t temp_measure_attrs;
|
|
||||||
prst_rel_humidity_attrs_t rel_humidity_attrs;
|
|
||||||
// In units of 100 mV.
|
|
||||||
prst_batt_attrs_t batt_attrs;
|
|
||||||
prst_soil_moisture_attrs_t soil_moisture_attrs;
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct zb_device_ctx dev_ctx;
|
static struct zb_device_ctx dev_ctx;
|
||||||
|
|
||||||
|
static prst_sensors_t sensors;
|
||||||
|
|
||||||
ZB_ZCL_DECLARE_IDENTIFY_ATTRIB_LIST(
|
ZB_ZCL_DECLARE_IDENTIFY_ATTRIB_LIST(
|
||||||
identify_attr_list,
|
identify_attr_list,
|
||||||
&dev_ctx.identify_attr.identify_time);
|
&dev_ctx.identify_attr.identify_time);
|
||||||
|
|
@ -100,18 +92,6 @@ PRST_ZB_ZCL_DECLARE_SOIL_MOISTURE_ATTRIB_LIST(
|
||||||
soil_moisture_attr_list,
|
soil_moisture_attr_list,
|
||||||
&dev_ctx.soil_moisture_attrs.percentage);
|
&dev_ctx.soil_moisture_attrs.percentage);
|
||||||
|
|
||||||
void prst_zcl_soil_moisture_init_server(void) {
|
|
||||||
zb_zcl_add_cluster_handlers(PRST_ZB_ZCL_ATTR_SOIL_MOISTURE_CLUSTER_ID,
|
|
||||||
ZB_ZCL_CLUSTER_SERVER_ROLE,
|
|
||||||
/*cluster_check_value=*/NULL,
|
|
||||||
/*cluster_write_attr_hook=*/NULL,
|
|
||||||
/*cluster_handler=*/NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void prst_zcl_soil_moisture_init_client(void) {
|
|
||||||
// Nothing.
|
|
||||||
}
|
|
||||||
|
|
||||||
ZB_DECLARE_RANGE_EXTENDER_CLUSTER_LIST(
|
ZB_DECLARE_RANGE_EXTENDER_CLUSTER_LIST(
|
||||||
app_template_clusters,
|
app_template_clusters,
|
||||||
basic_attr_list,
|
basic_attr_list,
|
||||||
|
|
@ -213,6 +193,11 @@ void zboss_signal_handler(zb_bufid_t bufid) {
|
||||||
void update_sensors_cb(zb_uint8_t arg) {
|
void update_sensors_cb(zb_uint8_t arg) {
|
||||||
LOG_INF("Updating sensors");
|
LOG_INF("Updating sensors");
|
||||||
|
|
||||||
|
if (prst_sensors_read_all(&sensors)) {
|
||||||
|
LOG_ERR("Unable to read sensors");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
static zb_uint8_t batt = 10;
|
static zb_uint8_t batt = 10;
|
||||||
batt += 1;
|
batt += 1;
|
||||||
zb_zcl_set_attr_val(PRST_ZIGBEE_ENDPOINT, ZB_ZCL_CLUSTER_ID_POWER_CONFIG,
|
zb_zcl_set_attr_val(PRST_ZIGBEE_ENDPOINT, ZB_ZCL_CLUSTER_ID_POWER_CONFIG,
|
||||||
|
|
@ -237,8 +222,7 @@ void update_sensors_cb(zb_uint8_t arg) {
|
||||||
ZB_ZCL_CLUSTER_SERVER_ROLE, ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_VALUE_ID,
|
ZB_ZCL_CLUSTER_SERVER_ROLE, ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_VALUE_ID,
|
||||||
(zb_uint8_t*)&rel_humi, ZB_FALSE);
|
(zb_uint8_t*)&rel_humi, ZB_FALSE);
|
||||||
|
|
||||||
static zb_int16_t soil_moisture = 69;
|
zb_int16_t soil_moisture = 100 * 100 * sensors.soil.percentage;
|
||||||
soil_moisture += 1;
|
|
||||||
zb_zcl_set_attr_val(PRST_ZIGBEE_ENDPOINT, PRST_ZB_ZCL_ATTR_SOIL_MOISTURE_CLUSTER_ID,
|
zb_zcl_set_attr_val(PRST_ZIGBEE_ENDPOINT, PRST_ZB_ZCL_ATTR_SOIL_MOISTURE_CLUSTER_ID,
|
||||||
ZB_ZCL_CLUSTER_SERVER_ROLE, PRST_ZB_ZCL_ATTR_SOIL_MOISTURE_VALUE_ID,
|
ZB_ZCL_CLUSTER_SERVER_ROLE, PRST_ZB_ZCL_ATTR_SOIL_MOISTURE_VALUE_ID,
|
||||||
(zb_uint8_t*)&soil_moisture, ZB_FALSE);
|
(zb_uint8_t*)&soil_moisture, ZB_FALSE);
|
||||||
|
|
@ -246,7 +230,11 @@ void update_sensors_cb(zb_uint8_t arg) {
|
||||||
ZB_SCHEDULE_APP_ALARM(update_sensors_cb, NULL, ZB_TIME_ONE_SECOND * 1);
|
ZB_SCHEDULE_APP_ALARM(update_sensors_cb, NULL, ZB_TIME_ONE_SECOND * 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main(void) {
|
int main(void) {
|
||||||
|
RET_IF_ERR(prst_adc_init());
|
||||||
|
RET_IF_ERR(prst_led_init());
|
||||||
|
RET_IF_ERR(prst_button_init());
|
||||||
|
|
||||||
register_factory_reset_button(FACTORY_RESET_BUTTON);
|
register_factory_reset_button(FACTORY_RESET_BUTTON);
|
||||||
|
|
||||||
app_clusters_attr_init();
|
app_clusters_attr_init();
|
||||||
|
|
@ -257,11 +245,13 @@ void main(void) {
|
||||||
|
|
||||||
update_sensors_cb(/*arg=*/0);
|
update_sensors_cb(/*arg=*/0);
|
||||||
|
|
||||||
// zb_bdb_set_legacy_device_support(1);
|
|
||||||
zigbee_enable();
|
|
||||||
// zb_bdb_set_legacy_device_support(1);
|
|
||||||
|
|
||||||
// zigbee_configure_sleepy_behavior(/*enable=*/true);
|
// zigbee_configure_sleepy_behavior(/*enable=*/true);
|
||||||
|
|
||||||
|
RET_IF_ERR(prst_led_flash(2));
|
||||||
|
|
||||||
|
zigbee_enable();
|
||||||
|
|
||||||
LOG_INF("Zigbee application template started");
|
LOG_INF("Zigbee application template started");
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,16 +19,23 @@ typedef struct {
|
||||||
zb_uint8_t voltage;
|
zb_uint8_t voltage;
|
||||||
// Units of 0.5%. 0x00 (0%) - 0xc8 (100%) (optional, reportable).
|
// Units of 0.5%. 0x00 (0%) - 0xc8 (100%) (optional, reportable).
|
||||||
zb_uint8_t percentage;
|
zb_uint8_t percentage;
|
||||||
// zb_uint8_t quantity;
|
|
||||||
// zb_uint8_t size;
|
|
||||||
// zb_uint8_t rated_voltage;
|
|
||||||
// zb_uint8_t voltage_min_thres;
|
|
||||||
// zb_uint8_t percentage_min_thres;
|
|
||||||
} prst_batt_attrs_t;
|
} prst_batt_attrs_t;
|
||||||
|
|
||||||
// Soil moisture cluster.
|
// Soil moisture cluster.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
// 0-100, units of 0.01?
|
||||||
zb_uint16_t percentage;
|
zb_uint16_t percentage;
|
||||||
} prst_soil_moisture_attrs_t;
|
} prst_soil_moisture_attrs_t;
|
||||||
|
|
||||||
|
struct zb_device_ctx {
|
||||||
|
zb_zcl_basic_attrs_ext_t basic_attr;
|
||||||
|
zb_zcl_identify_attrs_t identify_attr;
|
||||||
|
// In units of 0.01 C.
|
||||||
|
zb_zcl_temp_measurement_attrs_t temp_measure_attrs;
|
||||||
|
prst_rel_humidity_attrs_t rel_humidity_attrs;
|
||||||
|
// In units of 100 mV.
|
||||||
|
prst_batt_attrs_t batt_attrs;
|
||||||
|
prst_soil_moisture_attrs_t soil_moisture_attrs;
|
||||||
|
};
|
||||||
|
|
||||||
#endif // _PRST_ZB_ATTRS_H_
|
#endif // _PRST_ZB_ATTRS_H_
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,10 @@
|
||||||
|
|
||||||
#include "prst_zb_soil_moisture_defs.h"
|
#include "prst_zb_soil_moisture_defs.h"
|
||||||
|
|
||||||
|
#define PRST_ZIGBEE_ENDPOINT 10
|
||||||
|
#define PRST_BASIC_MANUF_NAME "b-parasite"
|
||||||
|
#define PRST_BASIC_MODEL_ID "b-parasite"
|
||||||
|
|
||||||
#define PRST_ZB_DEVICE_ID 0x0008
|
#define PRST_ZB_DEVICE_ID 0x0008
|
||||||
#define PRST_ZB_DEVICE_VERSION 0
|
#define PRST_ZB_DEVICE_VERSION 0
|
||||||
#define PRST_ZB_IN_CLUSTER_NUM 6
|
#define PRST_ZB_IN_CLUSTER_NUM 6
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
#include "prst_zb_soil_moisture_defs.h"
|
||||||
|
|
||||||
|
#include <zboss_api.h>
|
||||||
|
|
||||||
|
void prst_zcl_soil_moisture_init_server(void) {
|
||||||
|
zb_zcl_add_cluster_handlers(PRST_ZB_ZCL_ATTR_SOIL_MOISTURE_CLUSTER_ID,
|
||||||
|
ZB_ZCL_CLUSTER_SERVER_ROLE,
|
||||||
|
/*cluster_check_value=*/NULL,
|
||||||
|
/*cluster_write_attr_hook=*/NULL,
|
||||||
|
/*cluster_handler=*/NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void prst_zcl_soil_moisture_init_client(void) {
|
||||||
|
// Nothing.
|
||||||
|
}
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
#ifndef _PRST_ZB_SOIL_MOISTURE_DEFS_
|
#ifndef _PRST_ZB_SOIL_MOISTURE_DEFS_
|
||||||
#define _PRST_ZB_SOIL_MOISTURE_DEFS_
|
#define _PRST_ZB_SOIL_MOISTURE_DEFS_
|
||||||
|
|
||||||
|
#include <zboss_api.h>
|
||||||
#include <zcl/zb_zcl_common.h>
|
#include <zcl/zb_zcl_common.h>
|
||||||
|
|
||||||
// Most defines in this file are updated from the ZB_ZCL_DECLARE_TEMP_MEASUREMENT_ATTRIB_LIST,
|
// Most defines in this file are updated from the ZB_ZCL_DECLARE_TEMP_MEASUREMENT_ATTRIB_LIST,
|
||||||
// adapting attributes and IDs to match the mSoilMoisture cluster spec.
|
// adapting attributes and IDs to match the mSoilMoisture cluster spec.
|
||||||
// Values from https://github.com/Koenkk/zigbee-herdsman/blob/master/src/zcl/definition/cluster.ts#L2570
|
// Values from https://github.com/Koenkk/zigbee-herdsman/blob/master/src/zcl/definition/cluster.ts#L2570
|
||||||
// (msSoilMoisture).
|
// (msSoilMoisture).
|
||||||
|
// Cluster attributes definitions in https://www.st.com/resource/en/user_manual/um2977-stm32wb-series-zigbee-cluster-library-api-stmicroelectronics.pdf.
|
||||||
|
|
||||||
#define PRST_ZB_ZCL_ATTR_SOIL_MOISTURE_CLUSTER_ID 1032
|
#define PRST_ZB_ZCL_ATTR_SOIL_MOISTURE_CLUSTER_ID 1032
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue