forked from espressif/arduino-esp32
v2.0.0 Add support for ESP32S2 and update ESP-IDF to 4.4 (#4996)
This is very much still work in progress and much more will change before the final 2.0.0 Some APIs have changed. New libraries have been added. LittleFS included. Co-authored-by: Seon Rozenblum <seonr@3sprockets.com> Co-authored-by: Me No Dev <me-no-dev@users.noreply.github.com> Co-authored-by: geeksville <kevinh@geeksville.com> Co-authored-by: Mike Dunston <m_dunston@comcast.net> Co-authored-by: Unexpected Maker <seon@unexpectedmaker.com> Co-authored-by: Seon Rozenblum <seonr@3sprockets.com> Co-authored-by: microDev <70126934+microDev1@users.noreply.github.com> Co-authored-by: tobozo <tobozo@users.noreply.github.com> Co-authored-by: bobobo1618 <bobobo1618@users.noreply.github.com> Co-authored-by: lorol <lorolouis@gmail.com> Co-authored-by: geeksville <kevinh@geeksville.com> Co-authored-by: Limor "Ladyada" Fried <limor@ladyada.net> Co-authored-by: Sweety <switi.mhaiske@espressif.com> Co-authored-by: Loick MAHIEUX <loick111@gmail.com> Co-authored-by: Larry Bernstone <lbernstone@gmail.com> Co-authored-by: Valerii Koval <valeros@users.noreply.github.com> Co-authored-by: 快乐的我531 <2302004040@qq.com> Co-authored-by: chegewara <imperiaonline4@gmail.com> Co-authored-by: Clemens Kirchgatterer <clemens@1541.org> Co-authored-by: Aron Rubin <aronrubin@gmail.com> Co-authored-by: Pete Lewis <601236+lewispg228@users.noreply.github.com>
This commit is contained in:
@ -0,0 +1,52 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/** Initialize console
|
||||
*
|
||||
* Initializes serial console and adds basic commands.
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error in case of failures.
|
||||
*/
|
||||
esp_err_t esp_rmaker_console_init(void);
|
||||
|
||||
/* Reference for adding custom console commands:
|
||||
#include <esp_console.h>
|
||||
|
||||
static int command_console_handler(int argc, char *argv[])
|
||||
{
|
||||
// Command code here
|
||||
}
|
||||
|
||||
static void register_console_command()
|
||||
{
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = "<command_name>",
|
||||
.help = "<help_details>",
|
||||
.func = &command_console_handler,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
|
||||
}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
706
tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_core.h
Normal file
706
tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_core.h
Normal file
@ -0,0 +1,706 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <esp_err.h>
|
||||
#include <esp_event.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define ESP_RMAKER_CONFIG_VERSION "2020-03-20"
|
||||
|
||||
#define MAX_VERSION_STRING_LEN 16
|
||||
|
||||
/** ESP RainMaker Event Base */
|
||||
ESP_EVENT_DECLARE_BASE(RMAKER_EVENT);
|
||||
|
||||
/** ESP RainMaker Events */
|
||||
typedef enum {
|
||||
/** RainMaker Core Initialisation Done */
|
||||
RMAKER_EVENT_INIT_DONE = 1,
|
||||
/** Self Claiming Started */
|
||||
RMAKER_EVENT_CLAIM_STARTED,
|
||||
/** Self Claiming was Successful */
|
||||
RMAKER_EVENT_CLAIM_SUCCESSFUL,
|
||||
/** Self Claiming Failed */
|
||||
RMAKER_EVENT_CLAIM_FAILED,
|
||||
/** Node reboot has been triggered. The associated event data is the time in seconds
|
||||
* (type: uint8_t) after which the node will reboot. Note that this time may not be
|
||||
* accurate as the events are received asynchronously.*/
|
||||
RMAKER_EVENT_REBOOT,
|
||||
/** Wi-Fi credentials reset. Triggered after calling esp_rmaker_wifi_reset() */
|
||||
RMAKER_EVENT_WIFI_RESET,
|
||||
/** Node reset to factory defaults. Triggered after calling esp_rmaker_factory_reset() */
|
||||
RMAKER_EVENT_FACTORY_RESET
|
||||
} esp_rmaker_event_t;
|
||||
|
||||
/** ESP RainMaker Node information */
|
||||
typedef struct {
|
||||
/** Name of the Node */
|
||||
char *name;
|
||||
/** Type of the Node */
|
||||
char *type;
|
||||
/** Firmware Version (Optional). If not set, PROJECT_VER is used as default (recommended)*/
|
||||
char *fw_version;
|
||||
/** Model (Optional). If not set, PROJECT_NAME is used as default (recommended)*/
|
||||
char *model;
|
||||
} esp_rmaker_node_info_t;
|
||||
|
||||
/** ESP RainMaker Configuration */
|
||||
typedef struct {
|
||||
/** Enable Time Sync
|
||||
* Setting this true will enable SNTP and fetch the current time before
|
||||
* attempting to connect to the ESP RainMaker service
|
||||
*/
|
||||
bool enable_time_sync;
|
||||
} esp_rmaker_config_t;
|
||||
|
||||
/** ESP RainMaker Parameter Value type */
|
||||
typedef enum {
|
||||
/** Invalid */
|
||||
RMAKER_VAL_TYPE_INVALID = 0,
|
||||
/** Boolean */
|
||||
RMAKER_VAL_TYPE_BOOLEAN,
|
||||
/** Integer. Mapped to a 32 bit signed integer */
|
||||
RMAKER_VAL_TYPE_INTEGER,
|
||||
/** Floating point number */
|
||||
RMAKER_VAL_TYPE_FLOAT,
|
||||
/** NULL terminated string */
|
||||
RMAKER_VAL_TYPE_STRING,
|
||||
/** NULL terminated JSON Object string Eg. {"name":"value"} */
|
||||
RMAKER_VAL_TYPE_OBJECT,
|
||||
/** NULL terminated JSON Array string Eg. [1,2,3] */
|
||||
RMAKER_VAL_TYPE_ARRAY,
|
||||
} esp_rmaker_val_type_t;
|
||||
|
||||
/** ESP RainMaker Value */
|
||||
typedef union {
|
||||
/** Boolean */
|
||||
bool b;
|
||||
/** Integer */
|
||||
int i;
|
||||
/** Float */
|
||||
float f;
|
||||
/** NULL terminated string */
|
||||
char *s;
|
||||
} esp_rmaker_val_t;
|
||||
|
||||
/** ESP RainMaker Parameter Value */
|
||||
typedef struct {
|
||||
/** Type of Value */
|
||||
esp_rmaker_val_type_t type;
|
||||
/** Actual value. Depends on the type */
|
||||
esp_rmaker_val_t val;
|
||||
} esp_rmaker_param_val_t;
|
||||
|
||||
/** Param property flags */
|
||||
typedef enum {
|
||||
PROP_FLAG_WRITE = (1 << 0),
|
||||
PROP_FLAG_READ = (1 << 1),
|
||||
PROP_FLAG_TIME_SERIES = (1 << 2),
|
||||
PROP_FLAG_PERSIST = (1 << 3)
|
||||
} esp_param_property_flags_t;
|
||||
|
||||
/** Generic ESP RainMaker handle */
|
||||
typedef size_t esp_rmaker_handle_t;
|
||||
|
||||
/** ESP RainMaker Node Handle */
|
||||
typedef esp_rmaker_handle_t esp_rmaker_node_t;
|
||||
|
||||
/** ESP RainMaker Device Handle */
|
||||
typedef esp_rmaker_handle_t esp_rmaker_device_t;
|
||||
|
||||
/** ESP RainMaker Parameter Handle */
|
||||
typedef esp_rmaker_handle_t esp_rmaker_param_t;
|
||||
|
||||
/** Parameter read/write request source */
|
||||
typedef enum {
|
||||
/** Request triggered in the init sequence i.e. when a value is found
|
||||
* in persistent memory for parameters with PROP_FLAG_PERSIST.
|
||||
*/
|
||||
ESP_RMAKER_REQ_SRC_INIT,
|
||||
/** Request received from cloud */
|
||||
ESP_RMAKER_REQ_SRC_CLOUD,
|
||||
/** Request received when a schedule has triggered */
|
||||
ESP_RMAKER_REQ_SRC_SCHEDULE,
|
||||
} esp_rmaker_req_src_t;
|
||||
|
||||
/** Write request Context */
|
||||
typedef struct {
|
||||
/** Source of request */
|
||||
esp_rmaker_req_src_t src;
|
||||
} esp_rmaker_write_ctx_t;
|
||||
|
||||
/** Read request context */
|
||||
typedef struct {
|
||||
/** Source of request */
|
||||
esp_rmaker_req_src_t src;
|
||||
} esp_rmaker_read_ctx_t;
|
||||
|
||||
/** Callback for parameter value write requests.
|
||||
*
|
||||
* The callback should call the esp_rmaker_param_update_and_report() API if the new value is to be set
|
||||
* and reported back.
|
||||
*
|
||||
* @param[in] device Device handle.
|
||||
* @param[in] param Parameter handle.
|
||||
* @param[in] param Pointer to \ref esp_rmaker_param_val_t. Use appropriate elements as per the value type.
|
||||
* @param[in] priv_data Pointer to the private data paassed while creating the device.
|
||||
* @param[in] ctx Context associated with the request.
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error in case of failure.
|
||||
*/
|
||||
typedef esp_err_t (*esp_rmaker_device_write_cb_t)(const esp_rmaker_device_t *device, const esp_rmaker_param_t *param,
|
||||
const esp_rmaker_param_val_t val, void *priv_data, esp_rmaker_write_ctx_t *ctx);
|
||||
|
||||
/** Callback for parameter value changes
|
||||
*
|
||||
* The callback should call the esp_rmaker_param_update_and_report() API if the new value is to be set
|
||||
* and reported back.
|
||||
*
|
||||
* @note Currently, the read callback never gets invoked as the communication between clients (mobile phones, CLI, etc.)
|
||||
* and node is asynchronous. So, the read request does not reach the node. This callback will however be used in future.
|
||||
*
|
||||
* @param[in] device Device handle.
|
||||
* @param[in] param Parameter handle.
|
||||
* @param[in] priv_data Pointer to the private data passed while creating the device.
|
||||
* @param[in] ctx Context associated with the request.
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error in case of failure.
|
||||
*/
|
||||
typedef esp_err_t (*esp_rmaker_device_read_cb_t)(const esp_rmaker_device_t *device, const esp_rmaker_param_t *param,
|
||||
void *priv_data, esp_rmaker_read_ctx_t *ctx);
|
||||
|
||||
/**
|
||||
* Initialise a Boolean value
|
||||
*
|
||||
* @param[in] bval Initialising value.
|
||||
*
|
||||
* @return Value structure.
|
||||
*/
|
||||
esp_rmaker_param_val_t esp_rmaker_bool(bool bval);
|
||||
|
||||
/**
|
||||
* Initialise an Integer value
|
||||
*
|
||||
* @param[in] ival Initialising value.
|
||||
*
|
||||
* @return Value structure.
|
||||
*/
|
||||
esp_rmaker_param_val_t esp_rmaker_int(int ival);
|
||||
|
||||
/**
|
||||
* Initialise a Float value
|
||||
*
|
||||
* @param[in] fval Initialising value.
|
||||
*
|
||||
* @return Value structure.
|
||||
*/
|
||||
esp_rmaker_param_val_t esp_rmaker_float(float fval);
|
||||
|
||||
/**
|
||||
* Initialise a String value
|
||||
*
|
||||
* @param[in] sval Initialising value.
|
||||
*
|
||||
* @return Value structure.
|
||||
*/
|
||||
esp_rmaker_param_val_t esp_rmaker_str(const char *sval);
|
||||
|
||||
/**
|
||||
* Initialise a json object value
|
||||
*
|
||||
* @note the object will not be validated internally. it is the application's
|
||||
* responsibility to ensure that the object is a valid json object.
|
||||
* eg. esp_rmaker_obj("{\"name\":\"value\"}");
|
||||
*
|
||||
* param[in] val initialising value
|
||||
*
|
||||
* return value structure
|
||||
*/
|
||||
esp_rmaker_param_val_t esp_rmaker_obj(const char *val);
|
||||
|
||||
/**
|
||||
* Initialise a json array value
|
||||
*
|
||||
* @note the array will not be validated internally. it is the application's
|
||||
* responsibility to ensure that the array is a valid json array.
|
||||
* eg. esp_rmaker_array("[1,2,3]");
|
||||
*
|
||||
* param[in] val initialising value
|
||||
*
|
||||
* return value structure
|
||||
*/
|
||||
esp_rmaker_param_val_t esp_rmaker_array(const char *val);
|
||||
|
||||
|
||||
/** Initialize ESP RainMaker Node
|
||||
*
|
||||
* This initializes the ESP RainMaker agent and creates the node.
|
||||
* The model and firmware version for the node are set internally as per
|
||||
* the project name and version. These can be overridden (but not recommended) using the
|
||||
* esp_rmaker_node_add_fw_version() and esp_rmaker_node_add_model() APIs.
|
||||
*
|
||||
* @note This should be the first call before using any other ESP RainMaker API.
|
||||
*
|
||||
* @param[in] config Configuration to be used by the ESP RainMaker.
|
||||
* @param[in] name Name of the node.
|
||||
* @param[in] type Type of the node.
|
||||
*
|
||||
* @return Node handle on success.
|
||||
* @return NULL in case of failure.
|
||||
*/
|
||||
esp_rmaker_node_t *esp_rmaker_node_init(const esp_rmaker_config_t *config, const char *name, const char *type);
|
||||
|
||||
/** Start ESP RainMaker Agent
|
||||
*
|
||||
* This call starts the actual ESP RainMaker thread. This should preferably be called after a
|
||||
* successful Wi-Fi connection in order to avoid unnecessary failures.
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error in case of failure.
|
||||
*/
|
||||
esp_err_t esp_rmaker_start(void);
|
||||
|
||||
/** Stop ESP RainMaker Agent
|
||||
*
|
||||
* This call stops the ESP RainMaker Agent instance started earlier by esp_rmaker_start().
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error in case of failure.
|
||||
*/
|
||||
esp_err_t esp_rmaker_stop(void);
|
||||
|
||||
/** Deinitialize ESP RainMaker Node
|
||||
*
|
||||
* This API deinitializes the ESP RainMaker agent and the node created using esp_rmaker_node_init().
|
||||
*
|
||||
* @note This should be called after rainmaker has stopped.
|
||||
*
|
||||
* @param[in] node Node Handle returned by esp_rmaker_node_init().
|
||||
*
|
||||
* @retur ESP_OK on success.
|
||||
* @return error in case of failure.
|
||||
*/
|
||||
esp_err_t esp_rmaker_node_deinit(const esp_rmaker_node_t *node);
|
||||
|
||||
/** Get a handle to the Node
|
||||
*
|
||||
* This API returns handle to a node created using esp_rmaker_node_init().
|
||||
*
|
||||
* @return Node handle on success.
|
||||
* @return NULL in case of failure.
|
||||
*/
|
||||
const esp_rmaker_node_t *esp_rmaker_get_node(void);
|
||||
|
||||
/** Get Node Id
|
||||
*
|
||||
* Returns pointer to the NULL terminated Node ID string.
|
||||
*
|
||||
* @return Pointer to a NULL terminated Node ID string.
|
||||
*/
|
||||
char *esp_rmaker_get_node_id(void);
|
||||
|
||||
/** Get Node Info
|
||||
*
|
||||
* Returns pointer to the node info as configured during initialisation.
|
||||
*
|
||||
* @param node Node handle.
|
||||
*
|
||||
* @return Pointer to the node info on success.
|
||||
* @return NULL in case of failure.
|
||||
*/
|
||||
esp_rmaker_node_info_t *esp_rmaker_node_get_info(const esp_rmaker_node_t *node);
|
||||
|
||||
/** Add Node attribute
|
||||
*
|
||||
* Adds a new attribute as the metadata for the node. For the sake of simplicity,
|
||||
* only string values are allowed.
|
||||
*
|
||||
* @param node Node handle.
|
||||
* @param[in] attr_name Name of the attribute.
|
||||
* @param[in] val Value for the attribute.
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error in case of failure.
|
||||
*/
|
||||
esp_err_t esp_rmaker_node_add_attribute(const esp_rmaker_node_t *node, const char *attr_name, const char *val);
|
||||
|
||||
/** Add FW version for a node (Not recommended)
|
||||
*
|
||||
* FW version is set internally to the project version. This API can be used to
|
||||
* override that version.
|
||||
*
|
||||
* @param node Node handle.
|
||||
* @param[in] fw_version New firmware version.
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error in case of failure.
|
||||
*/
|
||||
esp_err_t esp_rmaker_node_add_fw_version(const esp_rmaker_node_t *node, const char *fw_version);
|
||||
|
||||
/** Add model for a node (Not recommended)
|
||||
*
|
||||
* Model is set internally to the project name. This API can be used to
|
||||
* override that name.
|
||||
*
|
||||
* @param node Node handle.
|
||||
* @param[in] model New model string.
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error in case of failure.
|
||||
*/
|
||||
esp_err_t esp_rmaker_node_add_model(const esp_rmaker_node_t *node, const char *model);
|
||||
|
||||
/**
|
||||
* Create a Device
|
||||
*
|
||||
* This API will create a virtual "Device".
|
||||
* This could be something like a Switch, Lightbulb, etc.
|
||||
*
|
||||
* @note The device created needs to be added to a node using esp_rmaker_node_add_device().
|
||||
*
|
||||
* @param[in] dev_name The unique device name.
|
||||
* @param[in] type Optional device type. Can be kept NULL.
|
||||
* @param[in] priv_data (Optional) Private data associated with the device. This will be passed to callbacks.
|
||||
* It should stay allocated throughout the lifetime of the device.
|
||||
*
|
||||
* @return Device handle on success.
|
||||
* @return NULL in case of any error.
|
||||
*/
|
||||
esp_rmaker_device_t *esp_rmaker_device_create(const char *dev_name, const char *type, void *priv_data);
|
||||
|
||||
/**
|
||||
* Create a Service
|
||||
*
|
||||
* This API will create a "Service". It is exactly same like a device in terms of structure and so, all
|
||||
* APIs for device are also valid for a service.
|
||||
* A service could be something like OTA, diagnostics, etc.
|
||||
*
|
||||
* @note Name of a service should not clash with name of a device.
|
||||
* @note The service created needs to be added to a node using esp_rmaker_node_add_device().
|
||||
*
|
||||
* @param[in] serv_name The unique service name.
|
||||
* @param[in] type Optional service type. Can be kept NULL.
|
||||
* @param[in] priv_data (Optional) Private data associated with the service. This will be passed to callbacks.
|
||||
* It should stay allocated throughout the lifetime of the device.
|
||||
*
|
||||
* @return Device handle on success.
|
||||
* @return NULL in case of any error.
|
||||
*/
|
||||
esp_rmaker_device_t *esp_rmaker_service_create(const char *serv_name, const char *type, void *priv_data);
|
||||
|
||||
/**
|
||||
* Delete a Device/Service
|
||||
*
|
||||
* This API will delete a device created using esp_rmaker_device_create().
|
||||
*
|
||||
* @note The device should first be removed from the node using esp_rmaker_node_remove_device() before deleting.
|
||||
*
|
||||
* @param[in] device Device handle.
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error in case of failure.
|
||||
*/
|
||||
esp_err_t esp_rmaker_device_delete(const esp_rmaker_device_t *device);
|
||||
|
||||
/**
|
||||
* Add callbacks for a device/service
|
||||
*
|
||||
* Add read/write callbacks for a device that will be invoked as per requests received from the cloud (or other paths
|
||||
* as may be added in future).
|
||||
*
|
||||
* @param[in] device Device handle.
|
||||
* @param[in] write_cb Write callback.
|
||||
* @param[in] read_cb Read callback.
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error in case of failure.
|
||||
*/
|
||||
esp_err_t esp_rmaker_device_add_cb(const esp_rmaker_device_t *device, esp_rmaker_device_write_cb_t write_cb, esp_rmaker_device_read_cb_t read_cb);
|
||||
|
||||
/**
|
||||
* Add a device to a node
|
||||
*
|
||||
* @param[in] node Node handle.
|
||||
* @param[in] device Device handle.
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error in case of failure.
|
||||
*/
|
||||
esp_err_t esp_rmaker_node_add_device(const esp_rmaker_node_t *node, const esp_rmaker_device_t *device);
|
||||
|
||||
/**
|
||||
* Remove a device from a node
|
||||
*
|
||||
* @param[in] node Node handle.
|
||||
* @param[in] device Device handle.
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error in case of failure.
|
||||
*/
|
||||
esp_err_t esp_rmaker_node_remove_device(const esp_rmaker_node_t *node, const esp_rmaker_device_t *device);
|
||||
|
||||
/** Add a Device attribute
|
||||
*
|
||||
* @note Device attributes are reported only once after a boot-up as part of the node
|
||||
* configuration.
|
||||
* Eg. Serial Number
|
||||
*
|
||||
* @param[in] device Device handle.
|
||||
* @param[in] attr_name Name of the attribute.
|
||||
* @param[in] val Value of the attribute.
|
||||
*
|
||||
* @return ESP_OK if the attribute was added successfully.
|
||||
* @return error in case of failure.
|
||||
*/
|
||||
esp_err_t esp_rmaker_device_add_attribute(const esp_rmaker_device_t *device, const char *attr_name, const char *val);
|
||||
|
||||
/** Get device name from handle
|
||||
*
|
||||
* @param[in] device Device handle.
|
||||
*
|
||||
* @return NULL terminated device name string on success.
|
||||
* @return NULL in case of failure.
|
||||
*/
|
||||
char *esp_rmaker_device_get_name(const esp_rmaker_device_t *device);
|
||||
|
||||
/** Get device type from handle
|
||||
*
|
||||
* @param[in] device Device handle.
|
||||
*
|
||||
* @return NULL terminated device type string on success.
|
||||
* @return NULL in case of failure, or if the type wasn't provided while creating the device.
|
||||
*/
|
||||
char *esp_rmaker_device_get_name(const esp_rmaker_device_t *device);
|
||||
|
||||
/**
|
||||
* Add a parameter to a device/service
|
||||
*
|
||||
* @param[in] device Device handle.
|
||||
* @param[in] param Parameter handle.
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error in case of failure.
|
||||
*/
|
||||
esp_err_t esp_rmaker_device_add_param(const esp_rmaker_device_t *device, const esp_rmaker_param_t *param);
|
||||
|
||||
|
||||
/** Get parameter by type
|
||||
*
|
||||
* Get handle for a parameter based on the type.
|
||||
*
|
||||
* @note If there are multiple parameters with the same type, this will return the first one. The API
|
||||
* esp_rmaker_device_get_param_by_name() can be used to get a specific parameter, because the parameter
|
||||
* names in a device are unique.
|
||||
*
|
||||
* @param[in] device Device handle.
|
||||
* @param[in] param_type Parameter type to search.
|
||||
*
|
||||
* @return Parameter handle on success.
|
||||
* @return NULL in case of failure.
|
||||
*/
|
||||
esp_rmaker_param_t *esp_rmaker_device_get_param_by_type(const esp_rmaker_device_t *device, const char *param_type);
|
||||
|
||||
/** Get parameter by name
|
||||
*
|
||||
* Get handle for a parameter based on the name.
|
||||
*
|
||||
* @param[in] device Device handle.
|
||||
* @param[in] param_name Parameter name to search.
|
||||
*
|
||||
* @return Parameter handle on success.
|
||||
* @return NULL in case of failure.
|
||||
*/
|
||||
esp_rmaker_param_t *esp_rmaker_device_get_param_by_name(const esp_rmaker_device_t *device, const char *param_name);
|
||||
|
||||
/** Assign a primary parameter
|
||||
*
|
||||
* Assign a parameter (already added using esp_rmaker_device_add_param()) as a primary parameter,
|
||||
* which can be used by clients (phone apps specifically) to give prominence to it.
|
||||
*
|
||||
* @param[in] device Device handle.
|
||||
* @param[in] param Parameter handle.
|
||||
*
|
||||
* @return ESP_OK if the parameter was assigned as the primary successfully.
|
||||
* @return error in case of failure.
|
||||
*/
|
||||
esp_err_t esp_rmaker_device_assign_primary_param(const esp_rmaker_device_t *device, const esp_rmaker_param_t *param);
|
||||
|
||||
/**
|
||||
* Create a Parameter
|
||||
*
|
||||
* Parameter can be something like Temperature, Outlet state, Lightbulb brightness, etc.
|
||||
*
|
||||
* Any changes should be reported using the esp_rmaker_param_update_and_report() API.
|
||||
* Any remote changes will be reported to the application via the device callback, if registered.
|
||||
*
|
||||
* @note The parameter created needs to be added to a device using esp_rmaker_device_add_param().
|
||||
* Parameter name should be unique in a given device.
|
||||
*
|
||||
* @param[in] param_name Name of the parameter.
|
||||
a* @param[in] type Optional parameter type. Can be kept NULL.
|
||||
* @param[in] val Value of the parameter. This also specifies the type that will be assigned
|
||||
* to this parameter. You can use esp_rmaker_bool(), esp_rmaker_int(), esp_rmaker_float()
|
||||
* or esp_rmaker_str() functions as the argument here. Eg, esp_rmaker_bool(true).
|
||||
* @param[in] properties Properties of the parameter, which will be a logical OR of flags in
|
||||
* \ref esp_param_property_flags_t.
|
||||
*
|
||||
* @return Parameter handle on success.
|
||||
* @return NULL in case of failure.
|
||||
*/
|
||||
esp_rmaker_param_t *esp_rmaker_param_create(const char *param_name, const char *type,
|
||||
esp_rmaker_param_val_t val, uint8_t properties);
|
||||
|
||||
/**
|
||||
* Add a UI Type to a parameter
|
||||
*
|
||||
* This will be used by the Phone apps (or other clients) to render appropriate UI for the given
|
||||
* parameter. Please refer the RainMaker documetation for supported UI Types.
|
||||
*
|
||||
* @param[in] param Parameter handle.
|
||||
* @param[in] ui_type String describing the UI Type.
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error in case of failure.
|
||||
*/
|
||||
esp_err_t esp_rmaker_param_add_ui_type(const esp_rmaker_param_t *param, const char *ui_type);
|
||||
|
||||
/**
|
||||
* Add bounds for an integer/float parameter
|
||||
*
|
||||
* This can be used to add bounds (min/max values) for a given integer parameter. Eg. brightness
|
||||
* will have bounds as 0 and 100 if it is a percentage.
|
||||
* Eg. esp_rmaker_param_add_bounds(brightness_param, esp_rmaker_int(0), esp_rmaker_int(100), esp_rmaker_int(5));
|
||||
*
|
||||
* @note The RainMaker core does not check the bounds. It is upto the application to handle it.
|
||||
*
|
||||
* @param[in] param Parameter handle.
|
||||
* @param[in] min Minimum allowed value.
|
||||
* @param[in] max Maximum allowed value.
|
||||
* @param[in] step Minimum stepping (set to 0 if no specific value is desired).
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* return error in case of failure.
|
||||
*/
|
||||
esp_err_t esp_rmaker_param_add_bounds(const esp_rmaker_param_t *param,
|
||||
esp_rmaker_param_val_t min, esp_rmaker_param_val_t max, esp_rmaker_param_val_t step);
|
||||
|
||||
/**
|
||||
* Add a list of valid strings for a string parameter
|
||||
*
|
||||
* This can be used to add a list of valid strings for a given string parameter.
|
||||
*
|
||||
* Eg.
|
||||
* static const char *valid_strs[] = {"None","Yes","No","Can't Say"};
|
||||
* esp_rmaker_param_add_valid_str_list(param, valid_strs, 4);
|
||||
*
|
||||
* @note The RainMaker core does not check the values. It is upto the application to handle it.
|
||||
*
|
||||
* @param[in] param Parameter handle.
|
||||
* @param[in] strs Pointer to an array of strings. Note that this memory should stay allocated
|
||||
* throughout the lifetime of this parameter.
|
||||
* @param[in] count Number of strings in the above array.
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* return error in case of failure.
|
||||
*/
|
||||
esp_err_t esp_rmaker_param_add_valid_str_list(const esp_rmaker_param_t *param, const char *strs[], uint8_t count);
|
||||
|
||||
/** Add max count for an array parameter
|
||||
*
|
||||
* This can be used to put a limit on the maximum number of elements in an array.
|
||||
*
|
||||
* @note The RainMaker core does not check the values. It is upto the application to handle it.
|
||||
*
|
||||
* @param[in] param Parameter handle.
|
||||
* @param[in] count Max number of elements allowed in the array.
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* return error in case of failure.
|
||||
*/
|
||||
esp_err_t esp_rmaker_param_add_array_max_count(const esp_rmaker_param_t *param, int count);
|
||||
|
||||
/** Update and report a parameter
|
||||
*
|
||||
* Calling this API will update the parameter and report it to ESP RainMaker cloud.
|
||||
* This should be used whenever there is any local change.
|
||||
*
|
||||
* @param[in] param Parameter handle.
|
||||
* @param[in] val New value of the parameter.
|
||||
*
|
||||
* @return ESP_OK if the parameter was updated successfully.
|
||||
* @return error in case of failure.
|
||||
*/
|
||||
esp_err_t esp_rmaker_param_update_and_report(const esp_rmaker_param_t *param, esp_rmaker_param_val_t val);
|
||||
|
||||
/** Get parameter name from handle
|
||||
*
|
||||
* @param[in] param Parameter handle.
|
||||
*
|
||||
* @return NULL terminated parameter name string on success.
|
||||
* @return NULL in case of failure.
|
||||
*/
|
||||
char *esp_rmaker_param_get_name(const esp_rmaker_param_t *param);
|
||||
|
||||
/** Get parameter type from handle
|
||||
*
|
||||
* @param[in] param Parameter handle.
|
||||
*
|
||||
* @return NULL terminated parameter type string on success.
|
||||
* @return NULL in case of failure, or if the type wasn't provided while creating the parameter.
|
||||
*/
|
||||
char *esp_rmaker_param_get_type(const esp_rmaker_param_t *param);
|
||||
|
||||
/** Prototype for ESP RainMaker Work Queue Function
|
||||
*
|
||||
* @param[in] priv_data The private data associated with the work function.
|
||||
*/
|
||||
typedef void (*esp_rmaker_work_fn_t)(void *priv_data);
|
||||
|
||||
/** Report the node details to the cloud
|
||||
*
|
||||
* This API reports node details i.e. the node configuration and values of all the parameters to the ESP RainMaker cloud.
|
||||
* Eg. If a new device is created (with some parameters and attributes), then this API should be called after that
|
||||
* to send the node details to the cloud again and the changes to be reflected in the clients (like phone apps).
|
||||
*
|
||||
* @note Please use this API only if you need to create or delete devices after esp_rmaker_start() has already
|
||||
* been called, for use cases like bridges or hubs.
|
||||
*
|
||||
* @return ESP_OK if the node details are successfully queued to be published.
|
||||
* @return error in case of failure.
|
||||
*/
|
||||
esp_err_t esp_rmaker_report_node_details(void);
|
||||
|
||||
/** Queue execution of a function in ESP RainMaker's context
|
||||
*
|
||||
* This API queues a work function for execution in the ESP RainMaker Task's context.
|
||||
*
|
||||
* @param[in] work_fn The Work function to be queued.
|
||||
* @param[in] priv_data Private data to be passed to the work function.
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error in case of failure.
|
||||
*/
|
||||
esp_err_t esp_rmaker_queue_work(esp_rmaker_work_fn_t work_fn, void *priv_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
108
tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_mqtt.h
Normal file
108
tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_mqtt.h
Normal file
@ -0,0 +1,108 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <esp_err.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/** ESP RainMaker MQTT Configuration */
|
||||
typedef struct {
|
||||
/** MQTT Host */
|
||||
char *mqtt_host;
|
||||
/** Client ID */
|
||||
char *client_id;
|
||||
/** Client Certificate in NULL terminate PEM format */
|
||||
char *client_cert;
|
||||
/** Client Key in NULL terminate PEM format */
|
||||
char *client_key;
|
||||
/** Server Certificate in NULL terminate PEM format */
|
||||
char *server_cert;
|
||||
} esp_rmaker_mqtt_config_t;
|
||||
|
||||
/** ESP RainMaker MQTT Subscribe callback prototype
|
||||
*
|
||||
* @param[in] topic Topic on which the message was received
|
||||
* @param[in] payload Data received in the message
|
||||
* @param[in] payload_len Length of the data
|
||||
* @param[in] priv_data The private data passed during subscription
|
||||
*/
|
||||
typedef void (*esp_rmaker_mqtt_subscribe_cb_t) (const char *topic, void *payload, size_t payload_len, void *priv_data);
|
||||
|
||||
/** Initialize ESP RainMaker MQTT
|
||||
*
|
||||
* @param[in] config The MQTT configuration data
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error in case of any error.
|
||||
*/
|
||||
esp_err_t esp_rmaker_mqtt_init(esp_rmaker_mqtt_config_t *config);
|
||||
|
||||
/** MQTT Connect
|
||||
*
|
||||
* Starts the connection attempts to the MQTT broker as per the configuration
|
||||
* provided during initializing.
|
||||
* This should ideally be called after successful network connection.
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error in case of any error.
|
||||
*/
|
||||
esp_err_t esp_rmaker_mqtt_connect(void);
|
||||
|
||||
/** MQTT Disconnect
|
||||
*
|
||||
* Disconnects from the MQTT broker.
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error in case of any error.
|
||||
*/
|
||||
esp_err_t esp_rmaker_mqtt_disconnect(void);
|
||||
|
||||
/** Publish MQTT Message
|
||||
*
|
||||
* @param[in] topic The MQTT topic on which the message should be published.
|
||||
* @param[in] data Data to be published
|
||||
* @param[in] data_len Length of the data
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error in case of any error.
|
||||
*/
|
||||
esp_err_t esp_rmaker_mqtt_publish(const char *topic, void *data, size_t data_len);
|
||||
|
||||
/** Subscribe to MQTT topic
|
||||
*
|
||||
* @param[in] topic The topic to be subscribed to.
|
||||
* @param[in] cb The callback to be invoked when a message is received on the given topic.
|
||||
* @param[in] priv_data Optional private data to be passed to the callback
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error in case of any error.
|
||||
*/
|
||||
esp_err_t esp_rmaker_mqtt_subscribe(const char *topic, esp_rmaker_mqtt_subscribe_cb_t cb, void *priv_data);
|
||||
|
||||
/** Unsubscribe from MQTT topic
|
||||
*
|
||||
* @param[in] topic Topic from which to unsubscribe.
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error in case of any error.
|
||||
*/
|
||||
esp_err_t esp_rmaker_mqtt_unsubscribe(const char *topic);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
150
tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_ota.h
Normal file
150
tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_ota.h
Normal file
@ -0,0 +1,150 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <esp_err.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/** Default ESP RainMaker OTA Server Certificate */
|
||||
extern const char *ESP_RMAKER_OTA_DEFAULT_SERVER_CERT;
|
||||
|
||||
/** OTA Status to be reported to ESP RainMaker Cloud */
|
||||
typedef enum {
|
||||
/** OTA is in Progress. This can be reported multiple times as the OTA progresses. */
|
||||
OTA_STATUS_IN_PROGRESS = 1,
|
||||
/** OTA Succeeded. This should be reported only once, at the end of OTA. */
|
||||
OTA_STATUS_SUCCESS,
|
||||
/** OTA Failed. This should be reported only once, at the end of OTA. */
|
||||
OTA_STATUS_FAILED,
|
||||
/** OTA was delayed by the application */
|
||||
OTA_STATUS_DELAYED,
|
||||
} ota_status_t;
|
||||
|
||||
/** OTA Workflow type */
|
||||
typedef enum {
|
||||
/** OTA will be performed using services and parameters. */
|
||||
OTA_USING_PARAMS = 1,
|
||||
/** OTA will be performed using pre-defined MQTT topics. */
|
||||
OTA_USING_TOPICS
|
||||
} esp_rmaker_ota_type_t;
|
||||
|
||||
/** The OTA Handle to be used by the OTA callback */
|
||||
typedef void *esp_rmaker_ota_handle_t;
|
||||
|
||||
/** OTA Data */
|
||||
typedef struct {
|
||||
/** The OTA URL received from ESP RainMaker Cloud */
|
||||
char *url;
|
||||
/** Size of the OTA File. Can be 0 if the file size isn't received from
|
||||
* the ESP RainMaker Cloud */
|
||||
int filesize;
|
||||
/** The server certificate passed in esp_rmaker_enable_ota() */
|
||||
const char *server_cert;
|
||||
/** The private data passed in esp_rmaker_enable_ota() */
|
||||
char *priv;
|
||||
} esp_rmaker_ota_data_t;
|
||||
|
||||
/** Function prototype for OTA Callback
|
||||
*
|
||||
* This function will be invoked by the ESP RainMaker core whenever an OTA is available.
|
||||
* The esp_rmaker_report_ota_status() API should be used to indicate the progress and
|
||||
* success/fail status.
|
||||
*
|
||||
* @param[in] handle An OTA handle assigned by the ESP RainMaker Core
|
||||
* @param[in] ota_data The data to be used for the OTA
|
||||
*
|
||||
* @return ESP_OK if the OTA was successful
|
||||
* @return ESP_FAIL if the OTA failed.
|
||||
*/
|
||||
typedef esp_err_t (*esp_rmaker_ota_cb_t) (esp_rmaker_ota_handle_t handle,
|
||||
esp_rmaker_ota_data_t *ota_data);
|
||||
|
||||
/** Function Prototype for Post OTA Diagnostics
|
||||
*
|
||||
* If the Application rollback feature is enabled, this callback will be invoked
|
||||
* as soon as you call esp_rmaker_ota_enable(), if it is the first
|
||||
* boot after an OTA. You may perform some application specific diagnostics and
|
||||
* report the status which will decide whether to roll back or not.
|
||||
*
|
||||
* @return true if diagnostics are successful, meaning that the new firmware is fine.
|
||||
* @return false if diagnostics fail and a roolback to previous firmware is required.
|
||||
*/
|
||||
typedef bool (*esp_rmaker_post_ota_diag_t)(void);
|
||||
|
||||
/** ESP RainMaker OTA Configuration */
|
||||
typedef struct {
|
||||
/** OTA Callback.
|
||||
* The callback to be invoked when an OTA Job is available.
|
||||
* If kept NULL, the internal default callback will be used (Recommended).
|
||||
*/
|
||||
esp_rmaker_ota_cb_t ota_cb;
|
||||
/** OTA Diagnostics Callback.
|
||||
* A post OTA diagnostic handler to be invoked if app rollback feature is enabled.
|
||||
* If kept NULL, the new firmware will be assumed to be fine,
|
||||
* and no rollback will be performed.
|
||||
*/
|
||||
esp_rmaker_post_ota_diag_t ota_diag;
|
||||
/** Server Certificate.
|
||||
* The certificate to be passed to the OTA callback for server authentication.
|
||||
* This is mandatory, unless you have disabled it in ESP HTTPS OTA config option.
|
||||
* If you are using the ESP RainMaker OTA Service, you can just set this to
|
||||
* `ESP_RMAKER_DEFAULT_OTA_SERVER_CERT`.
|
||||
*/
|
||||
const char *server_cert;
|
||||
/** Private Data.
|
||||
* Optional private data to be passed to the OTA callback.
|
||||
*/
|
||||
void *priv;
|
||||
} esp_rmaker_ota_config_t;
|
||||
|
||||
/** Enable OTA
|
||||
*
|
||||
* Calling this API enables OTA as per the ESP RainMaker specification.
|
||||
* Please check the various ESP RainMaker configuration options to
|
||||
* use the different variants of OTA. Refer the documentation for
|
||||
* additional details.
|
||||
*
|
||||
* @param[in] ota_config Pointer to an OTA configuration structure
|
||||
* @param[in] type The OTA workflow type
|
||||
*
|
||||
* @return ESP_OK on success
|
||||
* @return error on failure
|
||||
*/
|
||||
esp_err_t esp_rmaker_ota_enable(esp_rmaker_ota_config_t *ota_config, esp_rmaker_ota_type_t type);
|
||||
|
||||
/** Report OTA Status
|
||||
*
|
||||
* This API must be called from the OTA Callback to indicate the status of the OTA. The OTA_STATUS_IN_PROGRESS
|
||||
* can be reported multiple times with appropriate additional information. The final success/failure should
|
||||
* be reported only once, at the end.
|
||||
*
|
||||
* This can be ignored if you are using the default internal OTA callback.
|
||||
*
|
||||
* @param[in] ota_handle The OTA handle received by the callback
|
||||
* @param[in] status Status to be reported
|
||||
* @param[in] additional_info NULL terminated string indicating additional information for the status
|
||||
*
|
||||
* @return ESP_OK on success
|
||||
* @return error on failure
|
||||
*/
|
||||
esp_err_t esp_rmaker_ota_report_status(esp_rmaker_ota_handle_t ota_handle, ota_status_t status, char *additional_info);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,36 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/** Enable Schedules
|
||||
*
|
||||
* This API enables the scheduling service for the node. For more information,
|
||||
* check [here](https://rainmaker.espressif.com/docs/scheduling.html)
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error in case of failure.
|
||||
*/
|
||||
esp_err_t esp_rmaker_schedule_enable(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,96 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <esp_err.h>
|
||||
#include <esp_rmaker_core.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/** Create a standard Switch device
|
||||
*
|
||||
* This creates a Switch device with the mandatory parameters and also assigns
|
||||
* the primary parameter. The default parameter names will be used.
|
||||
* Refer \ref esp_rmaker_standard_params.h for default names.
|
||||
*
|
||||
* @param[in] dev_name The unique device name
|
||||
* @param[in] priv_data (Optional) Private data associated with the device. This should stay
|
||||
* allocated throughout the lifetime of the device
|
||||
* #@param[in] power Default value of the mandatory parameter "power"
|
||||
*
|
||||
* @return Device handle on success.
|
||||
* @return NULL in case of failures.
|
||||
*/
|
||||
esp_rmaker_device_t *esp_rmaker_switch_device_create(const char *dev_name,
|
||||
void *priv_data, bool power);
|
||||
|
||||
/** Create a standard Lightbulb device
|
||||
*
|
||||
* This creates a Lightbulb device with the mandatory parameters and also assigns
|
||||
* the primary parameter. The default parameter names will be used.
|
||||
* Refer \ref esp_rmaker_standard_params.h for default names.
|
||||
*
|
||||
* @param[in] dev_name The unique device name
|
||||
* @param[in] priv_data (Optional) Private data associated with the device. This should stay
|
||||
* allocated throughout the lifetime of the device
|
||||
* @param[in] power Default value of the mandatory parameter "power"
|
||||
*
|
||||
* @return Device handle on success.
|
||||
* @return NULL in case of failures.
|
||||
*/
|
||||
esp_rmaker_device_t *esp_rmaker_lightbulb_device_create(const char *dev_name,
|
||||
void *priv_data, bool power);
|
||||
|
||||
/** Create a standard Fan device
|
||||
*
|
||||
* This creates a Fan device with the mandatory parameters and also assigns
|
||||
* the primary parameter. The default parameter names will be used.
|
||||
* Refer \ref esp_rmaker_standard_params.h for default names.
|
||||
*
|
||||
* @param[in] dev_name The unique device name
|
||||
* @param[in] priv_data (Optional) Private data associated with the device. This should stay
|
||||
* allocated throughout the lifetime of the device
|
||||
* @param[in] power Default value of the mandatory parameter "power"
|
||||
*
|
||||
* @return Device handle on success.
|
||||
* @return NULL in case of failures.
|
||||
*/
|
||||
esp_rmaker_device_t *esp_rmaker_fan_device_create(const char *dev_name,
|
||||
void *priv_data, bool power);
|
||||
|
||||
/** Create a standard Temperature Sensor device
|
||||
*
|
||||
* This creates a Temperature Sensor device with the mandatory parameters and also assigns
|
||||
* the primary parameter. The default parameter names will be used.
|
||||
* Refer \ref esp_rmaker_standard_params.h for default names.
|
||||
*
|
||||
* @param[in] dev_name The unique device name
|
||||
* @param[in] priv_data (Optional) Private data associated with the device. This should stay
|
||||
* allocated throughout the lifetime of the device
|
||||
* @param[in] temperature Default value of the mandatory parameter "temperature"
|
||||
*
|
||||
* @return Device handle on success.
|
||||
* @return NULL in case of failures.
|
||||
*/
|
||||
esp_rmaker_device_t *esp_rmaker_temp_sensor_device_create(const char *dev_name,
|
||||
void *priv_data, float temperature);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,265 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <esp_err.h>
|
||||
#include <esp_rmaker_core.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* Suggested default names for the parameters.
|
||||
* These will also be used by default if you use any standard device helper APIs.
|
||||
*
|
||||
* @note These names are not mandatory. You can use the ESP RainMaker Core APIs
|
||||
* to create your own parameters with custom names, if required.
|
||||
*/
|
||||
|
||||
#define ESP_RMAKER_DEF_NAME_PARAM "Name"
|
||||
#define ESP_RMAKER_DEF_POWER_NAME "Power"
|
||||
#define ESP_RMAKER_DEF_BRIGHTNESS_NAME "Brightness"
|
||||
#define ESP_RMAKER_DEF_HUE_NAME "Hue"
|
||||
#define ESP_RMAKER_DEF_SATURATION_NAME "Saturation"
|
||||
#define ESP_RMAKER_DEF_INTENSITY_NAME "Intensity"
|
||||
#define ESP_RMAKER_DEF_CCT_NAME "CCT"
|
||||
#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_OTA_STATUS_NAME "Status"
|
||||
#define ESP_RMAKER_DEF_OTA_INFO_NAME "Info"
|
||||
#define ESP_RMAKER_DEF_OTA_URL_NAME "URL"
|
||||
#define ESP_RMAKER_DEF_TIMEZONE_NAME "TZ"
|
||||
#define ESP_RMAKER_DEF_TIMEZONE_POSIX_NAME "TZ-POSIX"
|
||||
#define ESP_RMAKER_DEF_SCHEDULE_NAME "Schedules"
|
||||
|
||||
/**
|
||||
* Create standard name param
|
||||
*
|
||||
* This will create the standard name parameter.
|
||||
* This should be added to all devices for which you want a user customisable name.
|
||||
* The value should be same as the device name.
|
||||
*
|
||||
* All standard device creation APIs will add this internally.
|
||||
* No application registered callback will be called for this parameter,
|
||||
* and changes will be managed internally.
|
||||
*
|
||||
* @param[in] param_name Name of the parameter
|
||||
*
|
||||
* @return Parameter handle on success.
|
||||
* @return NULL in case of failures.
|
||||
*/
|
||||
esp_rmaker_param_t *esp_rmaker_name_param_create(const char *param_name, const char *val);
|
||||
|
||||
/**
|
||||
* Create standard Power param
|
||||
*
|
||||
* This will create the standard power parameter.
|
||||
*
|
||||
* @param[in] param_name Name of the parameter
|
||||
* @param[in] val Default Value of the parameter
|
||||
*
|
||||
* @return Parameter handle on success.
|
||||
* @return NULL in case of failures.
|
||||
*/
|
||||
esp_rmaker_param_t *esp_rmaker_power_param_create(const char *param_name, bool val);
|
||||
|
||||
/**
|
||||
* Create standard Brightness param
|
||||
*
|
||||
* This will create the standard brightness parameter.
|
||||
*
|
||||
* @param[in] param_name Name of the parameter
|
||||
* @param[in] val Default Value of the parameter
|
||||
*
|
||||
* @return Parameter handle on success.
|
||||
* @return NULL in case of failures.
|
||||
*/
|
||||
esp_rmaker_param_t *esp_rmaker_brightness_param_create(const char *param_name, int val);
|
||||
|
||||
/**
|
||||
* Create standard Hue param
|
||||
*
|
||||
* This will create the standard hue parameter.
|
||||
*
|
||||
* @param[in] param_name Name of the parameter
|
||||
* @param[in] val Default Value of the parameter
|
||||
*
|
||||
* @return Parameter handle on success.
|
||||
* @return NULL in case of failures.
|
||||
*/
|
||||
esp_rmaker_param_t *esp_rmaker_hue_param_create(const char *param_name, int val);
|
||||
|
||||
/**
|
||||
* Create standard Saturation param
|
||||
*
|
||||
* This will create the standard saturation parameter.
|
||||
*
|
||||
* @param[in] param_name Name of the parameter
|
||||
* @param[in] val Default Value of the parameter
|
||||
*
|
||||
* @return Parameter handle on success.
|
||||
* @return NULL in case of failures.
|
||||
*/
|
||||
esp_rmaker_param_t *esp_rmaker_saturation_param_create(const char *param_name, int val);
|
||||
|
||||
/**
|
||||
* Create standard Intensity param
|
||||
*
|
||||
* This will create the standard intensity parameter.
|
||||
*
|
||||
* @param[in] param_name Name of the parameter
|
||||
* @param[in] val Default Value of the parameter
|
||||
*
|
||||
* @return Parameter handle on success.
|
||||
* @return NULL in case of failures.
|
||||
*/
|
||||
esp_rmaker_param_t *esp_rmaker_intensity_param_create(const char *param_name, int val);
|
||||
|
||||
/**
|
||||
* Create standard CCT param
|
||||
*
|
||||
* This will create the standard cct parameter.
|
||||
*
|
||||
* @param[in] param_name Name of the parameter
|
||||
* @param[in] val Default Value of the parameter
|
||||
*
|
||||
* @return Parameter handle on success.
|
||||
* @return NULL in case of failures.
|
||||
*/
|
||||
esp_rmaker_param_t *esp_rmaker_cct_param_create(const char *param_name, int val);
|
||||
|
||||
/**
|
||||
* Create standard Direction param
|
||||
*
|
||||
* This will create the standard direction parameter.
|
||||
*
|
||||
* @param[in] param_name Name of the parameter
|
||||
* @param[in] val Default Value of the parameter
|
||||
*
|
||||
* @return Parameter handle on success.
|
||||
* @return NULL in case of failures.
|
||||
*/
|
||||
esp_rmaker_param_t *esp_rmaker_direction_param_create(const char *param_name, int val);
|
||||
|
||||
/**
|
||||
* Create standard Speed param
|
||||
*
|
||||
* This will create the standard speed parameter.
|
||||
*
|
||||
* @param[in] param_name Name of the parameter
|
||||
* @param[in] val Default Value of the parameter
|
||||
*
|
||||
* @return Parameter handle on success.
|
||||
* @return NULL in case of failures.
|
||||
*/
|
||||
esp_rmaker_param_t *esp_rmaker_speed_param_create(const char *param_name, int val);
|
||||
|
||||
/**
|
||||
* Create standard Temperature param
|
||||
*
|
||||
* This will create the standard temperature parameter.
|
||||
*
|
||||
* @param[in] param_name Name of the parameter
|
||||
* @param[in] val Default Value of the parameter
|
||||
*
|
||||
* @return Parameter handle on success.
|
||||
* @return NULL in case of failures.
|
||||
*/
|
||||
esp_rmaker_param_t *esp_rmaker_temperature_param_create(const char *param_name, float val);
|
||||
|
||||
/**
|
||||
* Create standard OTA Status param
|
||||
*
|
||||
* This will create the standard ota status parameter. Default value
|
||||
* is set internally.
|
||||
*
|
||||
* @param[in] param_name Name of the parameter
|
||||
*
|
||||
* @return Parameter handle on success.
|
||||
* @return NULL in case of failures.
|
||||
*/
|
||||
esp_rmaker_param_t *esp_rmaker_ota_status_param_create(const char *param_name);
|
||||
|
||||
/**
|
||||
* Create standard OTA Info param
|
||||
*
|
||||
* This will create the standard ota info parameter. Default value
|
||||
* is set internally.
|
||||
*
|
||||
* @param[in] param_name Name of the parameter
|
||||
*
|
||||
* @return Parameter handle on success.
|
||||
* @return NULL in case of failures.
|
||||
*/
|
||||
esp_rmaker_param_t *esp_rmaker_ota_info_param_create(const char *param_name);
|
||||
|
||||
/**
|
||||
* Create standard OTA URL param
|
||||
*
|
||||
* This will create the standard ota url parameter. Default value
|
||||
* is set internally.
|
||||
*
|
||||
* @param[in] param_name Name of the parameter
|
||||
*
|
||||
* @return Parameter handle on success.
|
||||
* @return NULL in case of failures.
|
||||
*/
|
||||
esp_rmaker_param_t *esp_rmaker_ota_url_param_create(const char *param_name);
|
||||
|
||||
/**
|
||||
* Create standard Timezone param
|
||||
*
|
||||
* This will create the standard timezone parameter.
|
||||
*
|
||||
* @param[in] param_name Name of the parameter
|
||||
* @param[in] val Default Value of the parameter (Eg. "Asia/Shanghai"). Can be kept NULL.
|
||||
*
|
||||
* @return Parameter handle on success.
|
||||
* @return NULL in case of failures.
|
||||
*/
|
||||
esp_rmaker_param_t *esp_rmaker_timezone_param_create(const char *param_name, const char *val);
|
||||
|
||||
/**
|
||||
* Create standard POSIX Timezone param
|
||||
*
|
||||
* This will create the standard posix timezone parameter.
|
||||
*
|
||||
* @param[in] param_name Name of the parameter
|
||||
* @param[in] val Default Value of the parameter (Eg. "CST-8"). Can be kept NULL.
|
||||
*
|
||||
* @return Parameter handle on success.
|
||||
* @return NULL in case of failures.
|
||||
*/
|
||||
esp_rmaker_param_t *esp_rmaker_timezone_posix_param_create(const char *param_name, const char *val);
|
||||
|
||||
/**
|
||||
* Create standard schedules param
|
||||
*
|
||||
* This will create the standard schedules parameter. Default value
|
||||
* is set internally.
|
||||
*
|
||||
* @param[in] param_name Name of the parameter
|
||||
* @param[in] max_schedules Maximum number of schedules allowed
|
||||
*
|
||||
* @return Parameter handle on success.
|
||||
* @return NULL in case of failures.
|
||||
*/
|
||||
esp_rmaker_param_t *esp_rmaker_schedules_param_create(const char *param_name, int max_schedules);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,76 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <esp_err.h>
|
||||
#include <esp_rmaker_core.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/** Create a standard OTA service
|
||||
*
|
||||
* This creates an OTA service with the mandatory parameters. The default parameter names will be used.
|
||||
* Refer \ref esp_rmaker_standard_params.h for default names.
|
||||
*
|
||||
* @param[in] serv_name The unique service name
|
||||
* @param[in] priv_data (Optional) Private data associated with the service. This should stay
|
||||
* allocated throughout the lifetime of the service.
|
||||
*
|
||||
* @return service_handle on success.
|
||||
* @return NULL in case of any error.
|
||||
*/
|
||||
esp_rmaker_device_t *esp_rmaker_ota_service_create(const char *serv_name, void *priv_data);
|
||||
|
||||
/** Create a standard OTA service
|
||||
*
|
||||
* This creates an OTA service with the mandatory parameters. The default parameter names will be used.
|
||||
* Refer \ref esp_rmaker_standard_params.h for default names.
|
||||
*
|
||||
* @param[in] serv_name The unique service name
|
||||
* @param[in] timezone Default value of timezone string (Eg. "Asia/Shanghai"). Can be kept NULL.
|
||||
* @param[in] timezone_posix Default value of posix timezone string (Eg. "CST-8"). Can be kept NULL.
|
||||
* @param[in] priv_data (Optional) Private data associated with the service. This should stay
|
||||
* allocated throughout the lifetime of the service.
|
||||
*
|
||||
* @return service_handle on success.
|
||||
* @return NULL in case of any error.
|
||||
*/
|
||||
esp_rmaker_device_t *esp_rmaker_time_service_create(const char *serv_name, const char *timezone,
|
||||
const char *timezone_posix, void *priv_data);
|
||||
|
||||
/** Create a standard Schedule service
|
||||
*
|
||||
* This creates a Schedule service with the mandatory parameters. The default parameter names will be used.
|
||||
* Refer \ref esp_rmaker_standard_params.h for default names.
|
||||
*
|
||||
* @param[in] serv_name The unique service name
|
||||
* @param[in] write_cb Write callback.
|
||||
* @param[in] read_cb Read callback.
|
||||
* @param[in] max_schedules Maximum number of schedules supported.
|
||||
* @param[in] priv_data (Optional) Private data associated with the service. This should stay
|
||||
* allocated throughout the lifetime of the service.
|
||||
*
|
||||
* @return service_handle on success.
|
||||
* @return NULL in case of any error.
|
||||
*/
|
||||
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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,64 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/********** STANDARD UI TYPES **********/
|
||||
|
||||
#define ESP_RMAKER_UI_TOGGLE "esp.ui.toggle"
|
||||
#define ESP_RMAKER_UI_SLIDER "esp.ui.slider"
|
||||
#define ESP_RMAKER_UI_DROPDOWN "esp.ui.dropdown"
|
||||
#define ESP_RMAKER_UI_TEXT "esp.ui.text"
|
||||
|
||||
|
||||
/********** STANDARD PARAM TYPES **********/
|
||||
|
||||
#define ESP_RMAKER_PARAM_NAME "esp.param.name"
|
||||
#define ESP_RMAKER_PARAM_POWER "esp.param.power"
|
||||
#define ESP_RMAKER_PARAM_BRIGHTNESS "esp.param.brightness"
|
||||
#define ESP_RMAKER_PARAM_HUE "esp.param.hue"
|
||||
#define ESP_RMAKER_PARAM_SATURATION "esp.param.saturation"
|
||||
#define ESP_RMAKER_PARAM_INTENSITY "esp.param.intensity"
|
||||
#define ESP_RMAKER_PARAM_CCT "esp.param.cct"
|
||||
#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_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"
|
||||
#define ESP_RMAKER_PARAM_TIMEZONE "esp.param.tz"
|
||||
#define ESP_RMAKER_PARAM_TIMEZONE_POSIX "esp.param.tz_posix"
|
||||
#define ESP_RMAKER_PARAM_SCHEDULES "esp.param.schedules"
|
||||
|
||||
|
||||
/********** 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"
|
||||
|
||||
|
||||
/********** STANDARD SERVICE TYPES **********/
|
||||
#define ESP_RMAKER_SERVICE_OTA "esp.service.ota"
|
||||
#define ESP_RMAKER_SERVICE_TIME "esp.service.time"
|
||||
#define ESP_RMAKER_SERVICE_SCHEDULE "esp.service.schedule"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,64 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#pragma once
|
||||
#include <esp_err.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Create User Mapping Endpoint
|
||||
*
|
||||
* This will create a custom provisioning endpoint for user-node mapping.
|
||||
* This should be called after wifi_prov_mgr_init() but before
|
||||
* wifi_prov_mgr_start_provisioning()
|
||||
*
|
||||
* @return ESP_OK on success
|
||||
* @return error on failure
|
||||
*/
|
||||
esp_err_t esp_rmaker_user_mapping_endpoint_create(void);
|
||||
|
||||
/**
|
||||
* Register User Mapping Endpoint
|
||||
*
|
||||
* This will register the callback for the custom provisioning endpoint
|
||||
* for user-node mapping which was created with esp_rmaker_user_mapping_endpoint_create().
|
||||
* This should be called immediately after wifi_prov_mgr_start_provisioning().
|
||||
*
|
||||
* @return ESP_OK on success
|
||||
* @return error on failure
|
||||
*/
|
||||
esp_err_t esp_rmaker_user_mapping_endpoint_register(void);
|
||||
|
||||
/** Add User-Node mapping
|
||||
*
|
||||
* This call will start the user-node mapping workflow on the node.
|
||||
* This is automatically called if you have used esp_rmaker_user_mapping_endpoint_register().
|
||||
* Use this API only if you want to trigger the user-node mapping after the Wi-Fi provisioning
|
||||
* has already been done.
|
||||
*
|
||||
* @param[in] user_id The User identifier received from the client (Phone app/CLI)
|
||||
* @param[in] secret_key The Secret key received from the client (Phone app/CLI)
|
||||
*
|
||||
* @return ESP_OK if the workflow was successfully triggered. This does not guarantee success
|
||||
* of the actual mapping. The mapping status needs to be checked separately by the clients.
|
||||
* @return error on failure.
|
||||
*/
|
||||
esp_err_t esp_rmaker_start_user_node_mapping(char *user_id, char *secret_key);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
174
tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_utils.h
Normal file
174
tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_utils.h
Normal file
@ -0,0 +1,174 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <sntp.h>
|
||||
#include <esp_err.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef struct esp_rmaker_time_config {
|
||||
/** If not specified, then 'CONFIG_ESP_RMAKER_SNTP_SERVER_NAME' is used as the SNTP server. */
|
||||
char *sntp_server_name;
|
||||
/** Optional callback to invoke, whenever time is synchronised. This will be called
|
||||
* periodically as per the SNTP polling interval (which is 60min by default).
|
||||
* If kept NULL, the default callback will be invoked, which will just print the
|
||||
* current local time.
|
||||
*/
|
||||
sntp_sync_time_cb_t sync_time_cb;
|
||||
} esp_rmaker_time_config_t;
|
||||
|
||||
/** Reboot the chip after a delay
|
||||
*
|
||||
* This API just starts a reboot timer and returns immediately.
|
||||
* The actual reboot is trigerred asynchronously in the timer callback.
|
||||
* This is useful if you want to reboot after a delay, to allow other tasks to finish
|
||||
* their operations (Eg. MQTT publish to indicate OTA success). The \ref RMAKER_EVENT_REBOOT
|
||||
* event is triggered when the reboot timer is started.
|
||||
*
|
||||
* @param[in] seconds Time in seconds after which the chip should reboot.
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error on failure.
|
||||
*/
|
||||
esp_err_t esp_rmaker_reboot(uint8_t seconds);
|
||||
|
||||
/** Reset Wi-Fi credentials and reboot
|
||||
*
|
||||
* This will reset just the Wi-Fi credentials and trigger a reboot.
|
||||
* This is useful when you want to keep all the entries in NVS memory
|
||||
* intact, but just change the Wi-Fi credentials. The \ref RMAKER_EVENT_WIFI_RESET
|
||||
* event is triggered after the reset.
|
||||
*
|
||||
* @note This function internally calls esp_rmaker_reboot() and returns
|
||||
* immediately. The reboot happens asynchronously.
|
||||
*
|
||||
* @param[in] seconds Time in seconds after which the chip should reboot.
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error on failure.
|
||||
*/
|
||||
esp_err_t esp_rmaker_wifi_reset(uint8_t seconds);
|
||||
|
||||
/** Reset to factory defaults and reboot
|
||||
*
|
||||
* This will clear entire NVS partition and trigger a reboot.
|
||||
* The \ref RMAKER_EVENT_FACTORY_RESET event is triggered after the reset.
|
||||
*
|
||||
* @note This function internally calls esp_rmaker_reboot() and returns.
|
||||
* The reboot happens asynchronously.
|
||||
*
|
||||
* @param[in] seconds Time in seconds after which the chip should reboot.
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
* @return error on failure.
|
||||
*/
|
||||
esp_err_t esp_rmaker_factory_reset(uint8_t seconds);
|
||||
|
||||
/** Initialize time synchronization
|
||||
*
|
||||
* This API initializes SNTP for time synchronization.
|
||||
*
|
||||
* @param[in] config Configuration to be used for SNTP time synchronization. The default configuration is used if NULL is passed.
|
||||
*
|
||||
* @return ESP_OK on success
|
||||
* @return error on failure
|
||||
*/
|
||||
esp_err_t esp_rmaker_time_sync_init(esp_rmaker_time_config_t *config);
|
||||
|
||||
/** Check if current time is updated
|
||||
*
|
||||
* This API checks if the current system time is updated against the reference time of 1-Jan-2019.
|
||||
*
|
||||
* @return true if time is updated
|
||||
* @return false if time is not updated
|
||||
*/
|
||||
bool esp_rmaker_time_check(void);
|
||||
|
||||
/** Wait for time synchronization
|
||||
*
|
||||
* This API waits for the system time to be updated against the reference time of 1-Jan-2019.
|
||||
* This is a blocking call.
|
||||
*
|
||||
* @param[in] ticks_to_wait Number of ticks to wait for time synchronization. Accepted values: 0 to portMAX_DELAY.
|
||||
*
|
||||
* @return ESP_OK on success
|
||||
* @return error on failure
|
||||
*/
|
||||
esp_err_t esp_rmaker_time_wait_for_sync(uint32_t ticks_to_wait);
|
||||
|
||||
/** Set POSIX timezone
|
||||
*
|
||||
* Set the timezone (TZ environment variable) as per the POSIX format
|
||||
* specified in the [GNU libc documentation](https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html).
|
||||
* Eg. For China: "CST-8"
|
||||
* For US Pacific Time (including daylight saving information): "PST8PDT,M3.2.0,M11.1.0"
|
||||
*
|
||||
* @param[in] tz_posix NULL terminated TZ POSIX string
|
||||
*
|
||||
* @return ESP_OK on success
|
||||
* @return error on failure
|
||||
*/
|
||||
esp_err_t esp_rmaker_time_set_timezone_posix(const char *tz_posix);
|
||||
|
||||
/** Set timezone location string
|
||||
*
|
||||
* Set the timezone as a user friendly location string.
|
||||
* Check [here](https://rainmaker.espressif.com/docs/time-service.html) for a list of valid values.
|
||||
*
|
||||
* Eg. For China: "Asia/Shanghai"
|
||||
* For US Pacific Time: "America/Los_Angeles"
|
||||
*
|
||||
* @note Setting timezone using this API internally also sets the POSIX timezone string.
|
||||
*
|
||||
* @param[in] tz NULL terminated Timezone location string
|
||||
*
|
||||
* @return ESP_OK on success
|
||||
* @return error on failure
|
||||
*/
|
||||
esp_err_t esp_rmaker_time_set_timezone(const char *tz);
|
||||
|
||||
/** Enable Timezone Service
|
||||
*
|
||||
* This enables the ESP RainMaker standard timezone service which can be used to set
|
||||
* timezone, either in POSIX or location string format. Please refer the specifications
|
||||
* for additional details.
|
||||
*
|
||||
* @return ESP_OK on success
|
||||
* @return error on failure
|
||||
*/
|
||||
esp_err_t esp_rmaker_timezone_service_enable(void);
|
||||
|
||||
/** Get printable local time string
|
||||
*
|
||||
* Get a printable local time string, with information of timezone and Daylight Saving.
|
||||
* Eg. "Tue Sep 1 09:04:38 2020 -0400[EDT], DST: Yes"
|
||||
* "Tue Sep 1 21:04:04 2020 +0800[CST], DST: No"
|
||||
*
|
||||
*
|
||||
* @param[out] buf Pointer to a pre-allocated buffer into which the time string will
|
||||
* be populated.
|
||||
* @param[in] buf_len Length of the above buffer.
|
||||
*
|
||||
* @return ESP_OK on success
|
||||
* @return error on failure
|
||||
*/
|
||||
esp_err_t esp_rmaker_get_local_time_str(char *buf, size_t buf_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user