Skip to content

Commit ddeba16

Browse files
committed
Merge branch 'feature/device_scheduling' into 'master'
Scheduling support See merge request app-frameworks/esp-rainmaker!125
2 parents e352dfd + a9c4e5b commit ddeba16

27 files changed

+2154
-4
lines changed

components/esp_rainmaker/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ set(core_srcs "src/core/esp_rmaker_core.c"
1010
"src/core/esp_rmaker_storage.c"
1111
"src/core/esp_rmaker_user_mapping.pb-c.c"
1212
"src/core/esp_rmaker_utils.c"
13-
"src/core/esp_rmaker_user_mapping.c")
13+
"src/core/esp_rmaker_user_mapping.c"
14+
"src/core/esp_rmaker_schedule.c")
1415

1516

1617
if(CONFIG_ESP_RMAKER_ASSISTED_CLAIM)
@@ -48,7 +49,7 @@ idf_component_register(SRCS ${core_srcs} ${mqtt_srcs} ${ota_srcs} ${standard_typ
4849
INCLUDE_DIRS "include"
4950
PRIV_INCLUDE_DIRS ${core_priv_includes} ${ota_priv_includes} ${console_priv_includes}
5051
REQUIRES
51-
PRIV_REQUIRES protobuf-c json_parser json_generator wifi_provisioning nvs_flash esp_http_client app_update esp-tls mqtt esp_https_ota console)
52+
PRIV_REQUIRES protobuf-c json_parser json_generator wifi_provisioning nvs_flash esp_http_client app_update esp-tls mqtt esp_https_ota console esp_schedule)
5253

5354
target_add_binary_data(${COMPONENT_TARGET} "server_certs/mqtt_server.crt" TEXT)
5455
target_add_binary_data(${COMPONENT_TARGET} "server_certs/claim_service_server.crt" TEXT)

components/esp_rainmaker/Kconfig.projbuild

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,15 @@ menu "ESP RainMaker Config"
178178

179179
endmenu
180180

181+
menu "ESP RainMaker Scheduling"
182+
183+
config ESP_RMAKER_SCHEDULING_MAX_SCHEDULES
184+
int "Maximum schedules"
185+
default 5
186+
range 1 20
187+
help
188+
Maximum Number of schedules allowed. The json size for report params increases as the number of schedules increases.
189+
190+
endmenu
191+
181192
endmenu

components/esp_rainmaker/include/esp_rmaker_core.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ typedef enum {
136136
ESP_RMAKER_REQ_SRC_INIT,
137137
/** Request received from cloud */
138138
ESP_RMAKER_REQ_SRC_CLOUD,
139+
/** Request received when a schedule has triggered */
140+
ESP_RMAKER_REQ_SRC_SCHEDULE,
139141
} esp_rmaker_req_src_t;
140142

141143
/** Write request Context */
@@ -622,6 +624,20 @@ esp_err_t esp_rmaker_param_add_bounds(const esp_rmaker_param_t *param,
622624
*/
623625
esp_err_t esp_rmaker_param_add_valid_str_list(const esp_rmaker_param_t *param, const char *strs[], uint8_t count);
624626

627+
/** Add max count for an array parameter
628+
*
629+
* This can be used to put a limit on the maximum number of elements in an array.
630+
*
631+
* @note The RainMaker core does not check the values. It is upto the application to handle it.
632+
*
633+
* @param[in] param Parameter handle.
634+
* @param[in] count Max number of elements allowed in the array.
635+
*
636+
* @return ESP_OK on success.
637+
* return error in case of failure.
638+
*/
639+
esp_err_t esp_rmaker_param_add_array_max_count(const esp_rmaker_param_t *param, int count);
640+
625641
/** Update and report a parameter
626642
*
627643
* Calling this API will update the parameter and report it to ESP RainMaker cloud.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2020 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+
/** Enable Schedules
23+
*
24+
* This API enables the scheduling service for the node. For more information,
25+
* check [here](https://rainmaker.espressif.com/docs/scheduling.html)
26+
*
27+
* It is recommended to set the timezone while using schedules. Check [here](https://rainmaker.espressif.com/docs/time-service.html#time-zone) for more information on timezones
28+
*
29+
* @return ESP_OK on success.
30+
* @return error in case of failure.
31+
*/
32+
esp_err_t esp_rmaker_schedule_enable(void);
33+
34+
#ifdef __cplusplus
35+
}
36+
#endif

components/esp_rainmaker/include/esp_rmaker_standard_params.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ extern "C"
4444
#define ESP_RMAKER_DEF_OTA_URL_NAME "URL"
4545
#define ESP_RMAKER_DEF_TIMEZONE_NAME "TZ"
4646
#define ESP_RMAKER_DEF_TIMEZONE_POSIX_NAME "TZ-POSIX"
47+
#define ESP_RMAKER_DEF_SCHEDULE_NAME "Schedules"
4748

4849
/**
4950
* Create standard name param
@@ -244,6 +245,21 @@ esp_rmaker_param_t *esp_rmaker_timezone_param_create(const char *param_name, con
244245
* @return NULL in case of failures.
245246
*/
246247
esp_rmaker_param_t *esp_rmaker_timezone_posix_param_create(const char *param_name, const char *val);
248+
249+
/**
250+
* Create standard schedules param
251+
*
252+
* This will create the standard schedules parameter. Default value
253+
* is set internally.
254+
*
255+
* @param[in] param_name Name of the parameter
256+
* @param[in] max_schedules Maximum number of schedules allowed
257+
*
258+
* @return Parameter handle on success.
259+
* @return NULL in case of failures.
260+
*/
261+
esp_rmaker_param_t *esp_rmaker_schedules_param_create(const char *param_name, int max_schedules);
262+
247263
#ifdef __cplusplus
248264
}
249265
#endif

components/esp_rainmaker/include/esp_rmaker_standard_services.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@ esp_rmaker_device_t *esp_rmaker_ota_service_create(const char *serv_name, void *
5454
esp_rmaker_device_t *esp_rmaker_time_service_create(const char *serv_name, const char *timezone,
5555
const char *timezone_posix, void *priv_data);
5656

57+
/** Create a standard Schedule service
58+
*
59+
* This creates a Schedule service with the mandatory parameters. The default parameter names will be used.
60+
* Refer \ref esp_rmaker_standard_params.h for default names.
61+
*
62+
* @param[in] serv_name The unique service name
63+
* @param[in] write_cb Write callback.
64+
* @param[in] read_cb Read callback.
65+
* @param[in] max_schedules Maximum number of schedules supported.
66+
* @param[in] priv_data (Optional) Private data associated with the service. This should stay
67+
* allocated throughout the lifetime of the service.
68+
*
69+
* @return service_handle on success.
70+
* @return NULL in case of any error.
71+
*/
72+
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);
73+
5774
#ifdef __cplusplus
5875
}
5976
#endif

components/esp_rainmaker/include/esp_rmaker_standard_types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ extern "C"
4343
#define ESP_RMAKER_PARAM_OTA_URL "esp.param.ota_url"
4444
#define ESP_RMAKER_PARAM_TIMEZONE "esp.param.tz"
4545
#define ESP_RMAKER_PARAM_TIMEZONE_POSIX "esp.param.tz_posix"
46+
#define ESP_RMAKER_PARAM_SCHEDULES "esp.param.schedules"
47+
4648

4749
/********** STANDARD DEVICE TYPES **********/
4850

@@ -51,9 +53,11 @@ extern "C"
5153
#define ESP_RMAKER_DEVICE_FAN "esp.device.fan"
5254
#define ESP_RMAKER_DEVICE_TEMP_SENSOR "esp.device.temperature-sensor"
5355

56+
5457
/********** STANDARD SERVICE TYPES **********/
5558
#define ESP_RMAKER_SERVICE_OTA "esp.service.ota"
5659
#define ESP_RMAKER_SERVICE_TIME "esp.service.time"
60+
#define ESP_RMAKER_SERVICE_SCHEDULE "esp.service.schedule"
5761

5862
#ifdef __cplusplus
5963
}

components/esp_rainmaker/src/core/esp_rmaker_param.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,30 @@ esp_err_t esp_rmaker_param_add_valid_str_list(const esp_rmaker_param_t *param, c
488488
return ESP_OK;
489489
}
490490

491+
esp_err_t esp_rmaker_param_add_array_max_count(const esp_rmaker_param_t *param, int count)
492+
{
493+
if (!param) {
494+
ESP_LOGE(TAG, "Param handle cannot be NULL.");
495+
return ESP_ERR_INVALID_ARG;
496+
}
497+
_esp_rmaker_param_t *_param = (_esp_rmaker_param_t *)param;
498+
if (_param->val.type != RMAKER_VAL_TYPE_ARRAY) {
499+
ESP_LOGE(TAG, "Only array params can have max count.");
500+
return ESP_ERR_INVALID_ARG;
501+
}
502+
esp_rmaker_param_bounds_t *bounds = calloc(1, sizeof(esp_rmaker_param_bounds_t));
503+
if (!bounds) {
504+
ESP_LOGE(TAG, "Failed to allocate memory for parameter bounds.");
505+
return ESP_ERR_NO_MEM;
506+
}
507+
bounds->max = esp_rmaker_int(count);
508+
if (_param->bounds) {
509+
free(_param->bounds);
510+
}
511+
_param->bounds = bounds;
512+
return ESP_OK;
513+
}
514+
491515
esp_err_t esp_rmaker_param_add_ui_type(const esp_rmaker_param_t *param, const char *ui_type)
492516
{
493517
if (!param || !ui_type) {

0 commit comments

Comments
 (0)