diff --git a/apps/dht/CMakeLists.txt b/apps/dht/CMakeLists.txt new file mode 100644 index 0000000..bf154d4 --- /dev/null +++ b/apps/dht/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.8.2) + +if (NOT DEFINED ENV{KNOT_BASE}) + message(FATAL_ERROR "Source the KNoT shell initialize script!") +endif() + +include($ENV{KNOT_BASE}/core/CMakeLists.txt) +project(KNoT_DHT) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) + +include($ENV{ZEPHYR_BASE}/samples/net/common/common.cmake) diff --git a/apps/dht/prj.conf b/apps/dht/prj.conf new file mode 100644 index 0000000..d8f47dc --- /dev/null +++ b/apps/dht/prj.conf @@ -0,0 +1,20 @@ +# KNoT +CONFIG_KNOT_NAME="KNoT DHT" +CONFIG_KNOT_THING_DATA_MAX=2 + +# Logging +CONFIG_LOG=y +CONFIG_LOG_IMMEDIATE=n +CONFIG_LOG_PRINTK=y +CONFIG_KNOT_LOG=y +CONFIG_KNOT_LOG_LEVEL_DEBUG=y + +# Sensor +CONFIG_SENSOR=y +CONFIG_DHT=y +CONFIG_DHT_GPIO_PIN_NUM=47 +# If using DHT22, comment DHT11 lines and uncomment DHT22 ones +CONFIG_DHT_NAME="DHT11" +#CONFIG_DHT_NAME="DHT22" +CONFIG_DHT_CHIP_DHT11=y +#CONFIG_DHT_CHIP_DHT22=y diff --git a/apps/dht/setup.conf b/apps/dht/setup.conf new file mode 100644 index 0000000..363728c --- /dev/null +++ b/apps/dht/setup.conf @@ -0,0 +1 @@ +CONFIG_BT_DEVICE_NAME="KNoT DHT" diff --git a/apps/dht/src/dht.c b/apps/dht/src/dht.c new file mode 100644 index 0000000..924654a --- /dev/null +++ b/apps/dht/src/dht.c @@ -0,0 +1,78 @@ +/* dht.c - KNoT Application Client */ + +/* + * Copyright (c) 2019, CESAR. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * This example uses a DHT sensor to monitor ambient temperature and relative + * humidity. + */ + +#include +#include +#include +#include +#include + +#include "knot.h" +#include +#include + +LOG_MODULE_REGISTER(dht, LOG_LEVEL_DBG); + +struct device *dev; +int temperature, relative_humidity; + +/* Get temperature values from DHT sensor*/ +int on_get_temperature(int id) +{ + struct sensor_value temp; + + sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temp); + temperature = temp.val1; + LOG_INF("Temperature value: %d \n", temperature); + + return KNOT_CALLBACK_SUCCESS; +} + +/* Get relative humidity values from DHT sensor*/ +int on_get_humidity(int id) +{ + struct sensor_value humidity; + + sensor_channel_get(dev, SENSOR_CHAN_HUMIDITY, &humidity); + relative_humidity = humidity.val1; + LOG_INF("Relative humidity value: %d \n", relative_humidity); + + return KNOT_CALLBACK_SUCCESS; +} + +void setup(void) +{ + /* Peripherals control */ + dev = device_get_binding(CONFIG_DHT_NAME); + if (dev == NULL) { + LOG_ERR("Could not get DHT device\n"); + } + /* KNoT config */ + knot_data_register(0, "TEMPERATURE", KNOT_TYPE_ID_TEMPERATURE, + KNOT_VALUE_TYPE_INT, KNOT_UNIT_TEMPERATURE_C, + &temperature, sizeof(temperature), + NULL, on_get_temperature); + knot_data_config(0, KNOT_EVT_FLAG_TIME, 10, NULL); + knot_data_register(1, "RELATIVE HUMIDITY", + KNOT_TYPE_ID_RELATIVE_HUMIDITY, + KNOT_VALUE_TYPE_INT, + KNOT_UNIT_RELATIVE_HUMIDITY, + &relative_humidity, + sizeof(relative_humidity), + NULL, on_get_humidity); + knot_data_config(1, KNOT_EVT_FLAG_TIME, 10, NULL); +} + +void loop(void) +{ +}