Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions components/esp_rainmaker/include/esp_rmaker_standard_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extern "C"
#define ESP_RMAKER_DEF_DIRECTION_NAME "Direction"
#define ESP_RMAKER_DEF_SPEED_NAME "Speed"
#define ESP_RMAKER_DEF_TEMPERATURE_NAME "Temperature"
#define ESP_RMAKER_DEF_HUMIDITY_NAME "Humidity"
#define ESP_RMAKER_DEF_OTA_STATUS_NAME "Status"
#define ESP_RMAKER_DEF_OTA_INFO_NAME "Info"
#define ESP_RMAKER_DEF_OTA_URL_NAME "URL"
Expand Down Expand Up @@ -186,6 +187,7 @@ esp_rmaker_param_t *esp_rmaker_speed_param_create(const char *param_name, int va
* @return NULL in case of failures.
*/
esp_rmaker_param_t *esp_rmaker_temperature_param_create(const char *param_name, float val);
esp_rmaker_param_t *esp_rmaker_humidity_param_create(const char *param_name, float val);

/**
* Create standard OTA Status param
Expand Down
3 changes: 2 additions & 1 deletion components/esp_rainmaker/include/esp_rmaker_standard_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ extern "C"
#define ESP_RMAKER_PARAM_SPEED "esp.param.speed"
#define ESP_RMAKER_PARAM_DIRECTION "esp.param.direction"
#define ESP_RMAKER_PARAM_TEMPERATURE "esp.param.temperature"
#define ESP_RMAKER_PARAM_HUMIDITY "esp.param.humidity"
#define ESP_RMAKER_PARAM_OTA_STATUS "esp.param.ota_status"
#define ESP_RMAKER_PARAM_OTA_INFO "esp.param.ota_info"
#define ESP_RMAKER_PARAM_OTA_URL "esp.param.ota_url"
Expand All @@ -62,13 +63,13 @@ extern "C"
#define ESP_RMAKER_PARAM_LIGHT_MODE "esp.param.light-mode"
#define ESP_RMAKER_PARAM_AC_MODE "esp.param.ac-mode"


/********** STANDARD DEVICE TYPES **********/

#define ESP_RMAKER_DEVICE_SWITCH "esp.device.switch"
#define ESP_RMAKER_DEVICE_LIGHTBULB "esp.device.lightbulb"
#define ESP_RMAKER_DEVICE_FAN "esp.device.fan"
#define ESP_RMAKER_DEVICE_TEMP_SENSOR "esp.device.temperature-sensor"
#define ESP_RMAKER_DEVICE_HUMD_SENSOR "esp.device.humidity-sensor"
#define ESP_RMAKER_DEVICE_LIGHT "esp.device.light"
#define ESP_RMAKER_DEVICE_OUTLET "esp.device.outlet"
#define ESP_RMAKER_DEVICE_PLUG "esp.device.plug"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,16 @@ esp_rmaker_device_t *esp_rmaker_temp_sensor_device_create(const char *dev_name,
}
return device;
}

esp_rmaker_device_t *esp_rmaker_humd_sensor_device_create(const char *dev_name,
void *priv_data, float humidity)
{
esp_rmaker_device_t *device = esp_rmaker_device_create(dev_name, ESP_RMAKER_DEVICE_HUMD_SENSOR, priv_data);
if (device) {
esp_rmaker_device_add_param(device, esp_rmaker_name_param_create(ESP_RMAKER_DEF_NAME_PARAM, dev_name));
esp_rmaker_param_t *primary = esp_rmaker_humidity_param_create(ESP_RMAKER_DEF_HUMIDITY_NAME, humidity);
esp_rmaker_device_add_param(device, primary);
esp_rmaker_device_assign_primary_param(device, primary);
}
return device;
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ esp_rmaker_param_t *esp_rmaker_temperature_param_create(const char *param_name,
return param;
}

esp_rmaker_param_t *esp_rmaker_humidity_param_create(const char *param_name, float val)
{
esp_rmaker_param_t *param = esp_rmaker_param_create(param_name, ESP_RMAKER_PARAM_HUMIDITY,
esp_rmaker_float(val), PROP_FLAG_READ);
return param;
}

esp_rmaker_param_t *esp_rmaker_ota_status_param_create(const char *param_name)
{
esp_rmaker_param_t *param = esp_rmaker_param_create(param_name, ESP_RMAKER_PARAM_OTA_STATUS,
Expand Down
10 changes: 10 additions & 0 deletions examples/temperature_sensor/main/app_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ static uint16_t g_hue;
static uint16_t g_saturation = DEFAULT_SATURATION;
static uint16_t g_value = DEFAULT_BRIGHTNESS;
static float g_temperature;
static float g_humidity;

static void app_sensor_update(TimerHandle_t handle)
{
static float delta = 0.5;
g_temperature += delta;
g_humidity += delta;
if (g_temperature > 99) {
delta = -0.5;
} else if (g_temperature < 1) {
Expand All @@ -51,12 +53,19 @@ static void app_sensor_update(TimerHandle_t handle)
esp_rmaker_param_update_and_report(
esp_rmaker_device_get_param_by_type(temp_sensor_device, ESP_RMAKER_PARAM_TEMPERATURE),
esp_rmaker_float(g_temperature));
esp_rmaker_param_update_and_report(
esp_rmaker_device_get_param_by_type(temp_sensor_device, ESP_RMAKER_PARAM_HUMIDITY),
esp_rmaker_float(g_humidity));
}

float app_get_current_temperature()
{
return g_temperature;
}
float app_get_current_humidity()
{
return g_humidity;
}

esp_err_t app_sensor_init(void)
{
Expand All @@ -66,6 +75,7 @@ esp_err_t app_sensor_init(void)
}

g_temperature = DEFAULT_TEMPERATURE;
g_humidity = DEFAULT_HUMIDITY;
sensor_timer = xTimerCreate("app_sensor_update_tm", (REPORTING_PERIOD * 1000) / portTICK_PERIOD_MS,
pdTRUE, NULL, app_sensor_update);
if (sensor_timer) {
Expand Down
1 change: 1 addition & 0 deletions examples/temperature_sensor/main/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void app_main()

/* Create a device and add the relevant parameters to it */
temp_sensor_device = esp_rmaker_temp_sensor_device_create("Temperature Sensor", NULL, app_get_current_temperature());
esp_rmaker_device_add_param(temp_sensor_device, esp_rmaker_humidity_param_create(ESP_RMAKER_DEF_HUMIDITY_NAME, app_get_current_humidity()));
esp_rmaker_node_add_device(node, temp_sensor_device);

/* Enable OTA */
Expand Down
2 changes: 2 additions & 0 deletions examples/temperature_sensor/main/app_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
#include <stdbool.h>

#define DEFAULT_TEMPERATURE 25.0
#define DEFAULT_HUMIDITY 50.0
#define REPORTING_PERIOD 60 /* Seconds */

extern esp_rmaker_device_t *temp_sensor_device;

void app_driver_init(void);
float app_get_current_temperature();
float app_get_current_humidity();