Skip to content

Commit 764db8d

Browse files
committed
esp_rmaker_scenes: Add scenes support.
This adds a new standard service and its standard params. The implementation is similar to the schedule structure but without triggers.
1 parent f1028ae commit 764db8d

16 files changed

+683
-5
lines changed

Diff for: components/esp_rainmaker/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ set(core_srcs "src/core/esp_rmaker_core.c"
99
"src/core/esp_rmaker_system_service.c"
1010
"src/core/esp_rmaker_user_mapping.pb-c.c"
1111
"src/core/esp_rmaker_user_mapping.c"
12-
"src/core/esp_rmaker_schedule.c")
12+
"src/core/esp_rmaker_schedule.c"
13+
"src/core/esp_rmaker_scenes.c")
1314

1415
set(priv_req protobuf-c json_parser json_generator wifi_provisioning nvs_flash esp_http_client app_update esp-tls mbedtls esp_https_ota console esp_local_ctrl esp_https_server mdns esp_schedule)
1516

Diff for: components/esp_rainmaker/Kconfig.projbuild

+20
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,24 @@ menu "ESP RainMaker Config"
175175

176176
endmenu
177177

178+
menu "ESP RainMaker Scenes"
179+
180+
config ESP_RMAKER_SCENES_MAX_SCENES
181+
int "Maximum scenes"
182+
default 10
183+
range 1 50
184+
help
185+
Maximum Number of scenes allowed. The json size for report params increases as the number of scenes increases.
186+
187+
config ESP_RMAKER_SCENES_DEACTIVATE_SUPPORT
188+
bool "Enable Deactivate support"
189+
default n
190+
help
191+
This enables the deactivate callback support. The application callback will be invoked with the source
192+
set to ESP_RMAKER_REQ_SRC_SCENE_DEACTIVATE when the deactivate operation is received. However, the
193+
param values would be the same as those for activate, since the RainMaker core does not know what the
194+
expected values are for scene deactivation.
195+
196+
endmenu
197+
178198
endmenu

Diff for: components/esp_rainmaker/include/esp_rmaker_core.h

+4
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ typedef enum {
152152
ESP_RMAKER_REQ_SRC_CLOUD,
153153
/** Request received when a schedule has triggered */
154154
ESP_RMAKER_REQ_SRC_SCHEDULE,
155+
/** Request received when a scene has been activated */
156+
ESP_RMAKER_REQ_SRC_SCENE_ACTIVATE,
157+
/** Request received when a scene has been deactivated */
158+
ESP_RMAKER_REQ_SRC_SCENE_DEACTIVATE,
155159
/** Request received from a local controller */
156160
ESP_RMAKER_REQ_SRC_LOCAL,
157161
/** This will always be the last value. Any value equal to or

Diff for: components/esp_rainmaker/include/esp_rmaker_scenes.h

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2022 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#ifdef __cplusplus
18+
extern "C"
19+
{
20+
#endif
21+
22+
#include <esp_err.h>
23+
24+
/** Enable Scenes
25+
*
26+
* This API enables the scenes service for the node. For more information,
27+
* check [here](https://rainmaker.espressif.com/docs/scenes.html)
28+
*
29+
* @note This API should be called after esp_rmaker_node_init() but before esp_rmaker_start().
30+
*
31+
* @return ESP_OK on success.
32+
* @return error in case of failure.
33+
*/
34+
esp_err_t esp_rmaker_scenes_enable(void);
35+
36+
#ifdef __cplusplus
37+
}
38+
#endif

Diff for: components/esp_rainmaker/include/esp_rmaker_standard_params.h

+15
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ extern "C"
4545
#define ESP_RMAKER_DEF_TIMEZONE_NAME "TZ"
4646
#define ESP_RMAKER_DEF_TIMEZONE_POSIX_NAME "TZ-POSIX"
4747
#define ESP_RMAKER_DEF_SCHEDULE_NAME "Schedules"
48+
#define ESP_RMAKER_DEF_SCENES_NAME "Scenes"
4849
#define ESP_RMAKER_DEF_REBOOT_NAME "Reboot"
4950
#define ESP_RMAKER_DEF_FACTORY_RESET_NAME "Factory-Reset"
5051
#define ESP_RMAKER_DEF_WIFI_RESET_NAME "Wi-Fi-Reset"
@@ -265,6 +266,20 @@ esp_rmaker_param_t *esp_rmaker_timezone_posix_param_create(const char *param_nam
265266
*/
266267
esp_rmaker_param_t *esp_rmaker_schedules_param_create(const char *param_name, int max_schedules);
267268

269+
/**
270+
* Create standard Scenes param
271+
*
272+
* This will create the standard scenes parameter. Default value
273+
* is set internally.
274+
*
275+
* @param[in] param_name Name of the parameter
276+
* @param[in] max_scenes Maximum number of scenes allowed
277+
*
278+
* @return Parameter handle on success.
279+
* @return NULL in case of failures.
280+
*/
281+
esp_rmaker_param_t *esp_rmaker_scenes_param_create(const char *param_name, int max_scenes);
282+
268283
/**
269284
* Create standard Reboot param
270285
*

Diff for: components/esp_rainmaker/include/esp_rmaker_standard_services.h

+18
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,24 @@ esp_rmaker_device_t *esp_rmaker_time_service_create(const char *serv_name, const
7171
*/
7272
esp_rmaker_device_t *esp_rmaker_create_schedule_service(const char *serv_name, esp_rmaker_device_write_cb_t write_cb, esp_rmaker_device_read_cb_t read_cb, int max_schedules, void *priv_data);
7373

74+
/** Create a standard Scenes service
75+
*
76+
* This creates a Scenes service with the mandatory parameters. The default parameter names will be used.
77+
* Refer \ref esp_rmaker_standard_params.h for default names.
78+
*
79+
* @param[in] serv_name The unique service name
80+
* @param[in] write_cb Write callback.
81+
* @param[in] read_cb Read callback.
82+
* @param[in] max_scenes Maximum number of scenes supported.
83+
* @param[in] deactivation_support Deactivation callback support.
84+
* @param[in] priv_data (Optional) Private data associated with the service. This should stay
85+
* allocated throughout the lifetime of the service.
86+
*
87+
* @return service_handle on success.
88+
* @return NULL in case of any error.
89+
*/
90+
esp_rmaker_device_t *esp_rmaker_create_scenes_service(const char *serv_name, esp_rmaker_device_write_cb_t write_cb, esp_rmaker_device_read_cb_t read_cb, int max_scenes, bool deactivation_support, void *priv_data);
91+
7492
/** Create a standard System service
7593
*
7694
* This creates an empty System service. Appropriate parameters should be added by the caller.

Diff for: components/esp_rainmaker/include/esp_rmaker_standard_types.h

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ extern "C"
4444
#define ESP_RMAKER_PARAM_TIMEZONE "esp.param.tz"
4545
#define ESP_RMAKER_PARAM_TIMEZONE_POSIX "esp.param.tz_posix"
4646
#define ESP_RMAKER_PARAM_SCHEDULES "esp.param.schedules"
47+
#define ESP_RMAKER_PARAM_SCENES "esp.param.scenes"
4748
#define ESP_RMAKER_PARAM_REBOOT "esp.param.reboot"
4849
#define ESP_RMAKER_PARAM_FACTORY_RESET "esp.param.factory-reset"
4950
#define ESP_RMAKER_PARAM_WIFI_RESET "esp.param.wifi-reset"
@@ -63,6 +64,7 @@ extern "C"
6364
#define ESP_RMAKER_SERVICE_OTA "esp.service.ota"
6465
#define ESP_RMAKER_SERVICE_TIME "esp.service.time"
6566
#define ESP_RMAKER_SERVICE_SCHEDULE "esp.service.schedule"
67+
#define ESP_RMAKER_SERVICE_SCENES "esp.service.scenes"
6668
#define ESP_RMAKER_SERVICE_SYSTEM "esp.service.system"
6769
#define ESP_RMAKER_SERVICE_LOCAL_CONTROL "esp.service.local_control"
6870

Diff for: components/esp_rainmaker/src/core/esp_rmaker_device.c

-4
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,6 @@ esp_err_t esp_rmaker_device_add_attribute(const esp_rmaker_device_t *device, con
170170
return ESP_ERR_INVALID_ARG;
171171
}
172172
_esp_rmaker_device_t *_device = ( _esp_rmaker_device_t *)device;
173-
if (_device->is_service) {
174-
ESP_LOGE(TAG, "Cannot add attribute to a service");
175-
return ESP_ERR_INVALID_ARG;
176-
}
177173
esp_rmaker_attr_t *attr = _device->attributes;
178174
while(attr) {
179175
if (strcmp(attr_name, attr->name) == 0) {

Diff for: components/esp_rainmaker/src/core/esp_rmaker_param.c

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ static const char *cb_srcs[ESP_RMAKER_REQ_SRC_MAX] = {
5252
[ESP_RMAKER_REQ_SRC_INIT] = "Init",
5353
[ESP_RMAKER_REQ_SRC_CLOUD] = "Cloud",
5454
[ESP_RMAKER_REQ_SRC_SCHEDULE] = "Schedule",
55+
[ESP_RMAKER_REQ_SRC_SCENE_ACTIVATE] = "Scene Activate",
56+
[ESP_RMAKER_REQ_SRC_SCENE_DEACTIVATE] = "Scene Deactivate",
5557
[ESP_RMAKER_REQ_SRC_LOCAL] = "Local",
5658
};
5759

0 commit comments

Comments
 (0)