ESP RainMaker is an end-to-end solution offered by Espressif to enable remote control and monitoring for ESP32-S2 and ESP32 based products without any configuration required in the Cloud. The primary components of this solution are:
- Claiming Service (to get the Cloud connectivity credentials)
- RainMaker library (i.e. this library, to develop the firmware)
1. ESP RainMaker agent should be initialized before this call.
2. Once ESP RainMaker agent starts, compulsorily call WiFi.beginProvision() API.
.. code-block:: arduino
esp_err_t start();
This function will return `ESP_OK` on success or `Error` in case of failure.
RMaker.stop
***********
It stops the ESP RainMaker agent which was started using `RMaker.start()`.
.. code-block:: arduino
esp_err_t stop()
This function will return
1. `ESP_OK` : On success
2. Error in case of failure.
RMaker.deinitNode
*****************
It deinitializes the ESP RainMaker agent and the node created using `RMaker.initNode()`.
.. code-block:: arduino
esp_err_t deinitNode(Node node)
* ``node`` : Node object created using `RMaker.initNode()`
This function will return
1. `ESP_OK` : On success
2. Error in case of failure
RMaker.enableOTA
****************
It enables OTA as per the ESP RainMaker Specification. For more details refer ESP RainMaker documentation. check `here <https://rainmaker.espressif.com/docs/ota.html>`__.
.. code-block:: arduino
esp_err_t enableOTA(ota_type_t type);
* ``type`` : The OTA workflow type.
- OTA_USING_PARAMS
- OTA_USING_TOPICS
This function will return
1. `ESP_OK` : On success
2. Error in case of failure
RMaker.enableSchedule
*********************
This API enables the scheduling service for the node. For more information, check `here <https://rainmaker.espressif.com/docs/scheduling.html>`__.
.. code-block:: arduino
esp_err_t enableSchedule();
This function will return
1. `ESP_OK` : On success
2. Error in case of failure
RMaker.setTimeZone
******************
This API set's the timezone as a user friendly location string. Check
`here <https://rainmaker.espressif.com/docs/time-service.html>`__ for a list of valid values.
**NOTE** : default value is "Asia/Shanghai".
This API comes into picture only when working with scheduling.
.. code-block:: arduino
esp_err_t setTimeZone(const char *tz);
* ``tz`` : Valid values as specified in documentation.
This function will return
1. `ESP_OK` : On success
2. Error in case of failure
ESP RainMaker Node API
-----------------------
`Node` class expose API's for node.
**NOTE** : my_node is the object of Node class.
my_node.getNodeID
*****************
It returns the unique node_id assigned to the node. This node_id is usually the MAC address of the board.
.. code-block:: arduino
char * getNodeID()
* ``tz`` : Valid values as specified in documentation.
This function will return
1. `char *` : Pointer to a NULL terminated node_id string.
my_node.getNodeInfo
*******************
It returns pointer to the node_info_t as configured during node initialisation.
.. code-block:: arduino
node_info_t * getNodeInfo();
This function will return
1. `node_info_t` : Pointer to the structure node_info_t on success.
2. `NULL` : On failure.
**ESP RainMaker node info**
It has following data member
1. char * name
2. char * type
3. char * fw_version
4. char * model
my_node.addNodeAttr
*******************
It adds a new attribute as the metadata to the node.
* ``dev_name`` : Unique device name by default it is "switch" for switch device.
* ``priv_data`` : Private data associated with the device. This will be passed to the callbacks.
* ``power`` : It is the value that can be set for primary parameter.
Sample example for standard device.
.. code-block:: arduino
Switch switch1;
Switch switch2("switch2", NULL, true);
- `"switch2"` : Name for standard device.
- `NULL` : Private data for the device, which will be used in callback.
- `true` : Default value for the primary param, in case of switch it is power.
**NOTE**: No parameter are compulsory for standard devices. However if you are creating two objects of same standard class then in that case you will have to set the device name, if not then both device will have same name which is set by default, hence device will not get create. *Device name should be unique for each device.*
my_device.getDeviceName
***********************
It returns the name of the Device.
.. code-block:: arduino
const char * getDeviceName();
* ``device`` : Device object
This function will return
- `char *`: Returns Device name.
**NOTE**: Each device on the node should have unique device name.
my_device.addDeviceAttr
***********************
It adds attribute to the device. Device attributes are reported only once after a boot-up as part of the node configuration. Eg. Serial Number
**NOTE** : Care should be taken while accessing name of parameter. Above mentioned are the two ways using which default name of parameters can be accessed. Either LHS or RHS.
my_device.assignPrimaryParam
****************************
It assigns a parameter (already added using addXParam() or addParam()) as a primary parameter, which can be used by clients (phone apps specifically) to give prominence to it.
* ``value`` : Value to be updated. It can be int, bool, char * , float.
This function will return
1. `ESP_OK` : On success
2. Error in case of failure
my_device.addCb
***************
It registers read and write callback for the device which will be invoked as per requests received from the cloud (or other paths as may be added in future).
`Param` class expose API's for creating custom parameters for the devices and report and update values associated with parameter to the ESP RainMaker cloud. Parameterized constructor is defined which creates custom parameter.
**NOTE** : `my_param` is the object of Param class.
* ``param_type`` : Type of the parameter. It is optional can be kept NULL.
* ``val`` : Define the default value for the parameter. It should be defined using `value(int ival)` , `value(bool bval)` , `value(float fval)` , `value(char *sval)`.
* ``properties`` : Properties of the parameter, which will be a logical OR of flags.
**NOTE** : Parameter created using Param class should be added to the device using `my_device.addParam(my_param);`
my_param.addUIType
******************
Add a UI type to the parameter. This will be used by the Phone apps (or other clients) to render appropriate UI for the given parameter. Please refer the RainMaker documentation
`here <https://rainmaker.espressif.com/docs/standard-types.html#ui-elements>`__ for supported UI Types.
.. code-block:: arduino
esp_err_t addUIType(const char *ui_type);
* ``ui_type`` : String describing the UI Type.
* Standard UI Types
* ESP_RMAKER_UI_TOGGLE
* ESP_RMAKER_UI_SLIDER
* ESP_RMAKER_UI_DROPDOWN
* ESP_RMAKER_UI_TEXT
This function will return
1. `ESP_OK` : On success
2. Error in case of failure
my_param.addBounds
******************
Add bounds for an integer/float parameter. This can be used to add bounds (min/max values) for a given integer/float parameter. Eg. brightness will have bounds as 0 and 100 if it is a percentage.
`Sample example : my_param.addBounds(value(0), value(100), value(5));`
my_param.updateAndReport
************************
It updates the parameter and report it to ESP RainMaker cloud. This is called in callback.
.. code-block:: arduino
esp_err_t updateAndReport(param_val_t val);
* ``val`` : New value of the parameter
This function will return
1. `ESP_OK` : On success
2. Error in case of failure
**NOTE**:
- This API should always be called inside device write callback, if you aimed at updating n reporting parameter values, changed via RainMaker Client (Phone App), to the ESP RainMaker cloud.
- If not called then paramter values will not be updated to the ESP RainMaker cloud.
printQR
*******
This API displays QR code, which is used in provisioning.